|
| 1 | +# This is a basic workflow to help you get started with Actions |
| 2 | + |
| 3 | +name: Deploy to GitHub Pages |
| 4 | + |
| 5 | +# Controls when the workflow will run |
| 6 | +on: |
| 7 | + # Triggers the workflow on push or pull request events but only for the "master" branch |
| 8 | + push: |
| 9 | + branches: [ "master" ] |
| 10 | + pull_request: |
| 11 | + branches: [ "master" ] |
| 12 | + |
| 13 | + # Allows you to run this workflow manually from the Actions tab |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +# set permissions of GITHUB_TOKEN to allow pages deployment |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + pages: write |
| 20 | + id-token: write |
| 21 | + |
| 22 | +# allow only one concurrent deployment, with "mailbox" queue |
| 23 | +concurrency: |
| 24 | + group: "pages" |
| 25 | + cancel-in-progress: false |
| 26 | + |
| 27 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
| 28 | +jobs: |
| 29 | + # job called "build" |
| 30 | + build: |
| 31 | + # The type of runner that the job will run on |
| 32 | + runs-on: ubuntu-latest |
| 33 | + |
| 34 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 35 | + steps: |
| 36 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 37 | + - name: checkout |
| 38 | + uses: actions/checkout@v4 |
| 39 | + # Cache cargo and target directories |
| 40 | + - name: cache |
| 41 | + uses: actions/cache@v4 |
| 42 | + with: |
| 43 | + path: | |
| 44 | + ~/.cargo/bin |
| 45 | + ~/.cargo/registry/index/ |
| 46 | + ~/.cargo/registry/cache/ |
| 47 | + ~/.cargo/git/db/ |
| 48 | + target/ |
| 49 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 50 | + # install the rust toolchain targeting wasm32-unknown-unknown |
| 51 | + - name: install-rust-toolchain |
| 52 | + uses: actions-rs/[email protected] |
| 53 | + with: |
| 54 | + toolchain: stable |
| 55 | + target: wasm32-unknown-unknown |
| 56 | + # install wasm-pack tool |
| 57 | + - name: install-wasm-pack |
| 58 | + |
| 59 | + # run wasm-pack to generate ./pkg/ with all the js and wasm |
| 60 | + - name: run-wasm-pack-build |
| 61 | + run: wasm-pack build --target web |
| 62 | + # package all the files to one artifact directory |
| 63 | + - name: create-artifact |
| 64 | + run: | |
| 65 | + mkdir out |
| 66 | + cp ./index.html ./out/index.html |
| 67 | + cp -r ./pkg/ ./out/pkg/ |
| 68 | + # upload the artifact |
| 69 | + - name: Upload artifact |
| 70 | + id: deployment |
| 71 | + uses: actions/upload-pages-artifact@v3 |
| 72 | + with: |
| 73 | + path: ./out |
| 74 | + |
| 75 | + # deploy job |
| 76 | + deploy: |
| 77 | + environment: |
| 78 | + name: github-pages |
| 79 | + url: ${{ steps.deployment.outputs.page_url }} |
| 80 | + # needs build to be done first |
| 81 | + needs: build |
| 82 | + runs-on: ubuntu-latest |
| 83 | + steps: |
| 84 | + - name: Deploy to GitHub pages |
| 85 | + id: deployment |
| 86 | + uses: actions/deploy-pages@v4 |
0 commit comments