|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '*' |
| 7 | + |
| 8 | +env: |
| 9 | + # update with the name of the main binary |
| 10 | + binary: bevy_github_ci_template |
| 11 | + add_binaries_to_github_release: true |
| 12 | + #itch_target: <itch.io-username>/<game-name> |
| 13 | + |
| 14 | + |
| 15 | +jobs: |
| 16 | + |
| 17 | + # Build for wasm |
| 18 | + release-wasm: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - uses: olegtarasov/[email protected] |
| 23 | + id: get_version |
| 24 | + - uses: actions/checkout@v3 |
| 25 | + - uses: dtolnay/rust-toolchain@stable |
| 26 | + with: |
| 27 | + targets: wasm32-unknown-unknown |
| 28 | + - name: install wasm-bindgen-cli |
| 29 | + run: | |
| 30 | + cargo install wasm-bindgen-cli |
| 31 | +
|
| 32 | + - name: Build |
| 33 | + run: | |
| 34 | + cargo build --release --target wasm32-unknown-unknown |
| 35 | +
|
| 36 | + - name: Prepare package |
| 37 | + run: | |
| 38 | + wasm-bindgen --no-typescript --out-name bevy_game --out-dir wasm --target web target/wasm32-unknown-unknown/release/${{ env.binary }}.wasm |
| 39 | + cp -r assets wasm/ |
| 40 | +
|
| 41 | + - name: Package as a zip |
| 42 | + working-directory: ./wasm |
| 43 | + run: | |
| 44 | + zip --recurse-paths ../${{ env.binary }}.zip . |
| 45 | +
|
| 46 | + - name: Upload binaries to artifacts |
| 47 | + uses: actions/upload-artifact@v3 |
| 48 | + with: |
| 49 | + path: ${{ env.binary }}.zip |
| 50 | + name: wasm |
| 51 | + |
| 52 | + - name: Upload binaries to release |
| 53 | + if: ${{ env.add_binaries_to_github_release == 'true' }} |
| 54 | + uses: svenstaro/upload-release-action@v2 |
| 55 | + with: |
| 56 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + file: ${{ env.binary }}.zip |
| 58 | + asset_name: ${{ env.binary }}-wasm-${{ steps.get_version.outputs.tag }}.zip |
| 59 | + tag: ${{ github.ref }} |
| 60 | + overwrite: true |
| 61 | + |
| 62 | + # Build for Linux |
| 63 | + release-linux: |
| 64 | + runs-on: ubuntu-latest |
| 65 | + |
| 66 | + steps: |
| 67 | + - uses: olegtarasov/[email protected] |
| 68 | + id: get_version |
| 69 | + - uses: actions/checkout@v3 |
| 70 | + - uses: dtolnay/rust-toolchain@stable |
| 71 | + with: |
| 72 | + targets: x86_64-unknown-linux-gnu |
| 73 | + - name: install dependencies |
| 74 | + run: | |
| 75 | + sudo apt-get update; sudo apt-get install pkg-config libx11-dev libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev |
| 76 | +
|
| 77 | + - name: Build |
| 78 | + run: | |
| 79 | + cargo build --release --target x86_64-unknown-linux-gnu |
| 80 | +
|
| 81 | + - name: Prepare package |
| 82 | + run: | |
| 83 | + mkdir linux |
| 84 | + cp target/x86_64-unknown-linux-gnu/release/${{ env.binary }} linux/ |
| 85 | + cp -r assets linux/ |
| 86 | +
|
| 87 | + - name: Package as a zip |
| 88 | + working-directory: ./linux |
| 89 | + run: | |
| 90 | + zip --recurse-paths ../${{ env.binary }}.zip . |
| 91 | +
|
| 92 | + - name: Upload binaries to artifacts |
| 93 | + uses: actions/upload-artifact@v3 |
| 94 | + with: |
| 95 | + path: ${{ env.binary }}.zip |
| 96 | + name: linux |
| 97 | + |
| 98 | + - name: Upload binaries to release |
| 99 | + if: ${{ env.add_binaries_to_github_release == 'true' }} |
| 100 | + uses: svenstaro/upload-release-action@v2 |
| 101 | + with: |
| 102 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 103 | + file: ${{ env.binary }}.zip |
| 104 | + asset_name: ${{ env.binary }}-linux-${{ steps.get_version.outputs.tag }}.zip |
| 105 | + tag: ${{ github.ref }} |
| 106 | + overwrite: true |
| 107 | + |
| 108 | + # Build for Windows |
| 109 | + release-windows: |
| 110 | + runs-on: windows-latest |
| 111 | + |
| 112 | + steps: |
| 113 | + - uses: olegtarasov/[email protected] |
| 114 | + id: get_version |
| 115 | + - uses: actions/checkout@v3 |
| 116 | + - uses: dtolnay/rust-toolchain@stable |
| 117 | + with: |
| 118 | + targets: x86_64-pc-windows-msvc |
| 119 | + |
| 120 | + - name: Build |
| 121 | + run: | |
| 122 | + cargo build --release --target x86_64-pc-windows-msvc |
| 123 | +
|
| 124 | + - name: Prepare package |
| 125 | + run: | |
| 126 | + mkdir windows |
| 127 | + cp target/x86_64-pc-windows-msvc/release/${{ env.binary }}.exe windows/ |
| 128 | + cp -r assets windows/ |
| 129 | +
|
| 130 | + - name: Package as a zip |
| 131 | + run: | |
| 132 | + Compress-Archive -Path windows/* -DestinationPath ${{ env.binary }}.zip |
| 133 | +
|
| 134 | + - name: Upload binaries to artifacts |
| 135 | + uses: actions/upload-artifact@v3 |
| 136 | + with: |
| 137 | + path: ${{ env.binary }}.zip |
| 138 | + name: windows |
| 139 | + |
| 140 | + - name: Upload binaries to release |
| 141 | + if: ${{ env.add_binaries_to_github_release == 'true' }} |
| 142 | + uses: svenstaro/upload-release-action@v2 |
| 143 | + with: |
| 144 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 145 | + file: ${{ env.binary }}.zip |
| 146 | + asset_name: ${{ env.binary }}-windows-${{ steps.get_version.outputs.tag }}.zip |
| 147 | + tag: ${{ github.ref }} |
| 148 | + overwrite: true |
| 149 | + |
| 150 | + # Build for macOS |
| 151 | + release-macos: |
| 152 | + runs-on: macOS-latest |
| 153 | + |
| 154 | + steps: |
| 155 | + - uses: olegtarasov/[email protected] |
| 156 | + id: get_version |
| 157 | + - uses: actions/checkout@v3 |
| 158 | + - uses: dtolnay/rust-toolchain@stable |
| 159 | + with: |
| 160 | + targets: x86_64-apple-darwin |
| 161 | + - name: Environment Setup |
| 162 | + run: | |
| 163 | + export CFLAGS="-fno-stack-check" |
| 164 | + export MACOSX_DEPLOYMENT_TARGET="10.9" |
| 165 | +
|
| 166 | + - name: Build |
| 167 | + run: | |
| 168 | + cargo build --release --target x86_64-apple-darwin |
| 169 | +
|
| 170 | + - name: Prepare Package |
| 171 | + run: | |
| 172 | + mkdir -p ${{ env.binary }}.app/Contents/MacOS |
| 173 | + cp target/x86_64-apple-darwin/release/${{ env.binary }} ${{ env.binary }}.app/Contents/MacOS/ |
| 174 | + cp -r assets ${{ env.binary }}.app/Contents/MacOS/ |
| 175 | + hdiutil create -fs HFS+ -volname "${{ env.binary }}" -srcfolder ${{ env.binary }}.app ${{ env.binary }}.dmg |
| 176 | +
|
| 177 | + - name: Upload binaries to artifacts |
| 178 | + uses: actions/upload-artifact@v3 |
| 179 | + with: |
| 180 | + path: ${{ env.binary }}.dmg |
| 181 | + name: mac |
| 182 | + |
| 183 | + - name: Upload binaries to release |
| 184 | + if: ${{ env.add_binaries_to_github_release == 'true' }} |
| 185 | + uses: svenstaro/upload-release-action@v2 |
| 186 | + with: |
| 187 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 188 | + file: ${{ env.binary }}.dmg |
| 189 | + asset_name: ${{ env.binary }}-macos-${{ steps.get_version.outputs.tag }}.dmg |
| 190 | + tag: ${{ github.ref }} |
| 191 | + overwrite: true |
| 192 | + |
| 193 | + check-if-upload-to-itch-is-configured: |
| 194 | + runs-on: ubuntu-latest |
| 195 | + outputs: |
| 196 | + should-upload: ${{ steps.check-env.outputs.has-itch-target }} |
| 197 | + steps: |
| 198 | + - id: check-env |
| 199 | + run: | |
| 200 | + if [[ -z "$itch_target" ]]; then |
| 201 | + echo "has-itch-target=no" >> $GITHUB_OUTPUT |
| 202 | + else |
| 203 | + echo "has-itch-target=yes" >> $GITHUB_OUTPUT |
| 204 | + fi |
| 205 | +
|
| 206 | + upload-to-itch: |
| 207 | + runs-on: ubuntu-latest |
| 208 | + needs: |
| 209 | + - check-if-upload-to-itch-is-configured |
| 210 | + - release-wasm |
| 211 | + - release-linux |
| 212 | + - release-windows |
| 213 | + - release-macos |
| 214 | + if: ${{ needs.check-if-upload-to-itch-is-configured.outputs.should-upload == 'yes' }} |
| 215 | + |
| 216 | + steps: |
| 217 | + - name: Download artifacts |
| 218 | + uses: actions/download-artifact@v3 |
| 219 | + with: |
| 220 | + path: ./builds |
| 221 | + |
| 222 | + - name: Install butler |
| 223 | + run: | |
| 224 | + curl -L -o butler.zip https://broth.itch.ovh/butler/linux-amd64/LATEST/archive/default |
| 225 | + unzip butler.zip |
| 226 | + chmod +x butler |
| 227 | + ./butler -V |
| 228 | + - uses: olegtarasov/[email protected] |
| 229 | + id: get_version |
| 230 | + - name: Upload to itch.io |
| 231 | + env: |
| 232 | + BUTLER_API_KEY: ${{ secrets.BUTLER_CREDENTIALS }} |
| 233 | + run: | |
| 234 | + for channel in $(ls builds); do |
| 235 | + ./butler push \ |
| 236 | + --fix-permissions \ |
| 237 | + --userversion="${{ steps.get_version.outputs.tag }}" \ |
| 238 | + builds/$channel/* \ |
| 239 | + ${{ env.itch_target }}:$channel |
| 240 | + done |
0 commit comments