|
| 1 | +name: Deploy WASM build to GitHub Pages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +env: |
| 9 | + CARGO_TERM_COLOR: always |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + timeout-minutes: 20 |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v4 |
| 18 | + - uses: actions/cache@v4 |
| 19 | + with: |
| 20 | + path: | |
| 21 | + ~/.cargo/bin/ |
| 22 | + ~/.cargo/registry/index/ |
| 23 | + ~/.cargo/registry/cache/ |
| 24 | + ~/.cargo/git/db/ |
| 25 | + target/ |
| 26 | + key: ${{ github.ref || github.run_id }} |
| 27 | + - uses: dtolnay/rust-toolchain@stable |
| 28 | + - name: Add WASM |
| 29 | + run: rustup target add wasm32-unknown-unknown |
| 30 | + - name: Install WASM bindgen CLI |
| 31 | + run: cargo install -f wasm-bindgen-cli |
| 32 | + - name: Install alsa and udev |
| 33 | + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev |
| 34 | + - name: Build |
| 35 | + run: cargo build --release --target wasm32-unknown-unknown && wasm-bindgen --out-dir ./out/ --target web ./target/wasm32-unknown-unknown/release/tetris_in_rust.wasm |
| 36 | + - name: Copy |
| 37 | + run: cp -R assets out/ && cp index.html out/index.html && cp style.css out |
| 38 | + - name: Push |
| 39 | + uses: s0/git-publish-subdir-action@develop |
| 40 | + env: |
| 41 | + SQUASH_HISTORY: true |
| 42 | + REPO: self |
| 43 | + BRANCH: gh-pages # The branch name where you want to push the assets |
| 44 | + FOLDER: out # The directory where your assets are generated |
| 45 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub will automatically add this - you don't need to bother getting a token |
| 46 | + MESSAGE: "Build: ({sha}) {msg}" # The commit message |
| 47 | + - name: Upload artifact |
| 48 | + uses: actions/upload-pages-artifact@v3 |
| 49 | + with: |
| 50 | + path: '${{ github.event.repository.name }}/out' |
| 51 | + deploy: |
| 52 | + needs: build |
| 53 | + runs-on: ubuntu-latest |
| 54 | + permissions: |
| 55 | + pages: write |
| 56 | + id-token: write |
| 57 | + environment: |
| 58 | + name: github-pages |
| 59 | + url: 'https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/' |
| 60 | + steps: |
| 61 | + - name: Setup Pages |
| 62 | + uses: actions/configure-pages@v5 |
| 63 | + - name: Deploy |
| 64 | + uses: actions/deploy-pages@v4 |
0 commit comments