|
| 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-2048 |
| 11 | + add_binaries_to_github_release: true |
| 12 | + itch_target: mistycow/bevy-2048 |
| 13 | + |
| 14 | + # Before enabling LFS, please take a look at GitHub's documentation for costs and quota limits: |
| 15 | + # https://docs.github.com/en/repositories/working-with-files/managing-large-files/about-storage-and-bandwidth-usage |
| 16 | + use_git_lfs: false |
| 17 | + |
| 18 | + |
| 19 | +jobs: |
| 20 | + |
| 21 | + # Build for wasm |
| 22 | + release-wasm: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + steps: |
| 26 | + - uses: olegtarasov/[email protected] |
| 27 | + id: get_version |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + lfs: ${{ env.use_git_lfs }} |
| 31 | + - uses: dtolnay/rust-toolchain@stable |
| 32 | + with: |
| 33 | + targets: wasm32-unknown-unknown |
| 34 | + - name: install wasm-bindgen-cli |
| 35 | + run: | |
| 36 | + cargo install wasm-bindgen-cli |
| 37 | +
|
| 38 | + - name: Build |
| 39 | + run: | |
| 40 | + cargo build --release --target wasm32-unknown-unknown |
| 41 | +
|
| 42 | + - name: Prepare package |
| 43 | + run: | |
| 44 | + wasm-bindgen --no-typescript --out-name bevy_game --out-dir wasm --target web target/wasm32-unknown-unknown/release/${{ env.binary }}.wasm |
| 45 | + cp -r assets wasm/ || true # Try to copy, but ignore if it can't copy if source directory does not exist |
| 46 | +
|
| 47 | + - name: Package as a zip |
| 48 | + working-directory: ./wasm |
| 49 | + run: | |
| 50 | + zip --recurse-paths ../${{ env.binary }}.zip . |
| 51 | +
|
| 52 | + - name: Upload binaries to artifacts |
| 53 | + uses: actions/upload-artifact@v3 |
| 54 | + with: |
| 55 | + path: ${{ env.binary }}.zip |
| 56 | + name: wasm |
| 57 | + retention-days: 1 |
| 58 | + |
| 59 | + - name: Upload binaries to release |
| 60 | + if: ${{ env.add_binaries_to_github_release == 'true' }} |
| 61 | + uses: svenstaro/upload-release-action@v2 |
| 62 | + with: |
| 63 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 64 | + file: ${{ env.binary }}.zip |
| 65 | + asset_name: ${{ env.binary }}-wasm-${{ steps.get_version.outputs.tag }}.zip |
| 66 | + tag: ${{ github.ref }} |
| 67 | + overwrite: true |
| 68 | + |
| 69 | + # Build for Linux |
| 70 | + release-linux: |
| 71 | + runs-on: ubuntu-latest |
| 72 | + |
| 73 | + steps: |
| 74 | + - uses: olegtarasov/[email protected] |
| 75 | + id: get_version |
| 76 | + - uses: actions/checkout@v4 |
| 77 | + with: |
| 78 | + lfs: ${{ env.use_git_lfs }} |
| 79 | + - uses: dtolnay/rust-toolchain@stable |
| 80 | + with: |
| 81 | + targets: x86_64-unknown-linux-gnu |
| 82 | + - name: install dependencies |
| 83 | + run: | |
| 84 | + sudo apt-get update; sudo apt-get install pkg-config libx11-dev libasound2-dev libudev-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev |
| 85 | +
|
| 86 | + - name: Build |
| 87 | + run: | |
| 88 | + cargo build --release --target x86_64-unknown-linux-gnu |
| 89 | +
|
| 90 | + - name: Prepare package |
| 91 | + run: | |
| 92 | + mkdir linux |
| 93 | + cp target/x86_64-unknown-linux-gnu/release/${{ env.binary }} linux/ |
| 94 | + cp -r assets linux/ || true # Try to copy, but ignore if it can't copy if source directory does not exist |
| 95 | +
|
| 96 | + - name: Package as a zip |
| 97 | + working-directory: ./linux |
| 98 | + run: | |
| 99 | + zip --recurse-paths ../${{ env.binary }}.zip . |
| 100 | +
|
| 101 | + - name: Upload binaries to artifacts |
| 102 | + uses: actions/upload-artifact@v3 |
| 103 | + with: |
| 104 | + path: ${{ env.binary }}.zip |
| 105 | + name: linux |
| 106 | + retention-days: 1 |
| 107 | + |
| 108 | + - name: Upload binaries to release |
| 109 | + if: ${{ env.add_binaries_to_github_release == 'true' }} |
| 110 | + uses: svenstaro/upload-release-action@v2 |
| 111 | + with: |
| 112 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 113 | + file: ${{ env.binary }}.zip |
| 114 | + asset_name: ${{ env.binary }}-linux-${{ steps.get_version.outputs.tag }}.zip |
| 115 | + tag: ${{ github.ref }} |
| 116 | + overwrite: true |
| 117 | + |
| 118 | + # Build for Windows |
| 119 | + release-windows: |
| 120 | + runs-on: windows-latest |
| 121 | + |
| 122 | + steps: |
| 123 | + - uses: olegtarasov/[email protected] |
| 124 | + id: get_version |
| 125 | + - uses: actions/checkout@v4 |
| 126 | + with: |
| 127 | + lfs: ${{ env.use_git_lfs }} |
| 128 | + - uses: dtolnay/rust-toolchain@stable |
| 129 | + with: |
| 130 | + targets: x86_64-pc-windows-msvc |
| 131 | + |
| 132 | + - name: Build |
| 133 | + run: | |
| 134 | + cargo build --release --target x86_64-pc-windows-msvc |
| 135 | +
|
| 136 | + - name: Prepare package |
| 137 | + run: | |
| 138 | + mkdir windows |
| 139 | + cp target/x86_64-pc-windows-msvc/release/${{ env.binary }}.exe windows/ |
| 140 | + mkdir assets -ea 0 # create the assets directory if it does not exist, it will get ignored in the zip if empty |
| 141 | + cp -r assets windows/ |
| 142 | +
|
| 143 | + - name: Package as a zip |
| 144 | + run: | |
| 145 | + Compress-Archive -Path windows/* -DestinationPath ${{ env.binary }}.zip |
| 146 | +
|
| 147 | + - name: Upload binaries to artifacts |
| 148 | + uses: actions/upload-artifact@v3 |
| 149 | + with: |
| 150 | + path: ${{ env.binary }}.zip |
| 151 | + name: windows |
| 152 | + retention-days: 1 |
| 153 | + |
| 154 | + - name: Upload binaries to release |
| 155 | + if: ${{ env.add_binaries_to_github_release == 'true' }} |
| 156 | + uses: svenstaro/upload-release-action@v2 |
| 157 | + with: |
| 158 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 159 | + file: ${{ env.binary }}.zip |
| 160 | + asset_name: ${{ env.binary }}-windows-${{ steps.get_version.outputs.tag }}.zip |
| 161 | + tag: ${{ github.ref }} |
| 162 | + overwrite: true |
| 163 | + |
| 164 | + # Build for MacOS x86_64 |
| 165 | + release-macOS-intel: |
| 166 | + runs-on: macOS-latest |
| 167 | + |
| 168 | + steps: |
| 169 | + - uses: olegtarasov/[email protected] |
| 170 | + id: get_version |
| 171 | + - uses: actions/checkout@v4 |
| 172 | + with: |
| 173 | + lfs: ${{ env.use_git_lfs }} |
| 174 | + - uses: dtolnay/rust-toolchain@stable |
| 175 | + with: |
| 176 | + targets: x86_64-apple-darwin |
| 177 | + - name: Environment Setup |
| 178 | + run: | |
| 179 | + export CFLAGS="-fno-stack-check" |
| 180 | + export MACOSX_DEPLOYMENT_TARGET="10.9" |
| 181 | +
|
| 182 | + - name: Build |
| 183 | + run: | |
| 184 | + cargo build --release --target x86_64-apple-darwin |
| 185 | +
|
| 186 | + - name: Prepare Package |
| 187 | + run: | |
| 188 | + mkdir -p ${{ env.binary }}.app/Contents/MacOS |
| 189 | + cp target/x86_64-apple-darwin/release/${{ env.binary }} ${{ env.binary }}.app/Contents/MacOS/ |
| 190 | + cp -r assets ${{ env.binary }}.app/Contents/MacOS/ || true # Try to copy, but ignore if it can't copy if source directory does not exist |
| 191 | + hdiutil create -fs HFS+ -volname "${{ env.binary }}" -srcfolder ${{ env.binary }}.app ${{ env.binary }}-macOS-intel.dmg |
| 192 | +
|
| 193 | + - name: Upload binaries to artifacts |
| 194 | + uses: actions/upload-artifact@v3 |
| 195 | + with: |
| 196 | + path: ${{ env.binary }}-macOS-intel.dmg |
| 197 | + name: macOS-intel |
| 198 | + retention-days: 1 |
| 199 | + |
| 200 | + - name: Upload binaries to release |
| 201 | + if: ${{ env.add_binaries_to_github_release == 'true' }} |
| 202 | + uses: svenstaro/upload-release-action@v2 |
| 203 | + with: |
| 204 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 205 | + file: ${{ env.binary }}-macOS-intel.dmg |
| 206 | + asset_name: ${{ env.binary }}-macOS-intel-${{ steps.get_version.outputs.tag }}.dmg |
| 207 | + tag: ${{ github.ref }} |
| 208 | + overwrite: true |
| 209 | + |
| 210 | + # Build for MacOS Apple Silicon |
| 211 | + release-macOS-apple-silicon: |
| 212 | + runs-on: macOS-latest |
| 213 | + |
| 214 | + steps: |
| 215 | + - uses: olegtarasov/[email protected] |
| 216 | + id: get_version |
| 217 | + - uses: actions/checkout@v4 |
| 218 | + with: |
| 219 | + lfs: ${{ env.use_git_lfs }} |
| 220 | + - uses: dtolnay/rust-toolchain@stable |
| 221 | + with: |
| 222 | + targets: aarch64-apple-darwin |
| 223 | + - name: Environment |
| 224 | + # macOS 11 was the first version to support ARM |
| 225 | + run: | |
| 226 | + export MACOSX_DEPLOYMENT_TARGET="11" |
| 227 | +
|
| 228 | + - name: Build |
| 229 | + run: | |
| 230 | + cargo build --release --target aarch64-apple-darwin |
| 231 | +
|
| 232 | + - name: Prepare Package |
| 233 | + run: | |
| 234 | + mkdir -p ${{ env.binary }}.app/Contents/MacOS |
| 235 | + cp target/aarch64-apple-darwin/release/${{ env.binary }} ${{ env.binary }}.app/Contents/MacOS/ |
| 236 | + cp -r assets ${{ env.binary }}.app/Contents/MacOS/ || true # Try to copy, but ignore if it can't copy if source directory does not exist |
| 237 | + hdiutil create -fs HFS+ -volname "${{ env.binary }}-macOS-apple-silicon" -srcfolder ${{ env.binary }}.app ${{ env.binary }}-macOS-apple-silicon.dmg |
| 238 | +
|
| 239 | + - name: Upload binaries to artifacts |
| 240 | + uses: actions/upload-artifact@v3 |
| 241 | + with: |
| 242 | + path: ${{ env.binary }}-macOS-apple-silicon.dmg |
| 243 | + name: macOS-apple-silicon |
| 244 | + retention-days: 1 |
| 245 | + |
| 246 | + - name: Upload binaries to release |
| 247 | + if: ${{ env.add_binaries_to_github_release == 'true' }} |
| 248 | + uses: svenstaro/upload-release-action@v2 |
| 249 | + with: |
| 250 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 251 | + file: ${{ env.binary }}-macOS-apple-silicon.dmg |
| 252 | + asset_name: ${{ env.binary }}-macOS-apple-silicon-${{ steps.get_version.outputs.tag }}.dmg |
| 253 | + tag: ${{ github.ref }} |
| 254 | + overwrite: true |
| 255 | + |
| 256 | + check-if-upload-to-itch-is-configured: |
| 257 | + runs-on: ubuntu-latest |
| 258 | + outputs: |
| 259 | + should-upload: ${{ steps.check-env.outputs.has-itch-target }} |
| 260 | + steps: |
| 261 | + - id: check-env |
| 262 | + run: | |
| 263 | + if [[ -z "$itch_target" ]]; then |
| 264 | + echo "has-itch-target=no" >> $GITHUB_OUTPUT |
| 265 | + else |
| 266 | + echo "has-itch-target=yes" >> $GITHUB_OUTPUT |
| 267 | + fi |
| 268 | +
|
| 269 | + upload-to-itch: |
| 270 | + runs-on: ubuntu-latest |
| 271 | + needs: |
| 272 | + - check-if-upload-to-itch-is-configured |
| 273 | + - release-wasm |
| 274 | + - release-linux |
| 275 | + - release-windows |
| 276 | + - release-macOS-intel |
| 277 | + - release-macOS-apple-silicon |
| 278 | + if: ${{ needs.check-if-upload-to-itch-is-configured.outputs.should-upload == 'yes' }} |
| 279 | + |
| 280 | + steps: |
| 281 | + - name: Download artifacts |
| 282 | + uses: actions/download-artifact@v3 |
| 283 | + with: |
| 284 | + path: ./builds |
| 285 | + |
| 286 | + - name: Install butler |
| 287 | + run: | |
| 288 | + curl -L -o butler.zip https://broth.itch.ovh/butler/linux-amd64/LATEST/archive/default |
| 289 | + unzip butler.zip |
| 290 | + chmod +x butler |
| 291 | + ./butler -V |
| 292 | + - uses: olegtarasov/[email protected] |
| 293 | + id: get_version |
| 294 | + - name: Upload to itch.io |
| 295 | + env: |
| 296 | + BUTLER_API_KEY: ${{ secrets.BUTLER_CREDENTIALS }} |
| 297 | + run: | |
| 298 | + for channel in $(ls builds); do |
| 299 | + ./butler push \ |
| 300 | + --fix-permissions \ |
| 301 | + --userversion="${{ steps.get_version.outputs.tag }}" \ |
| 302 | + builds/$channel/* \ |
| 303 | + ${{ env.itch_target }}:$channel |
| 304 | + done |
0 commit comments