|
| 1 | +name: Deploy Preview |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - "browser-echo/**" |
| 9 | + pull_request: |
| 10 | + paths: |
| 11 | + - "browser-echo/**" |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + pr_number: |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + |
| 18 | +# ensure job runs sequentially so pushing to the preview branch doesn't conflict |
| 19 | +concurrency: |
| 20 | + group: ci-deploy-preview |
| 21 | + |
| 22 | +jobs: |
| 23 | + preview_deploy: |
| 24 | + permissions: write-all |
| 25 | + timeout-minutes: 30 |
| 26 | + name: Deploy Docs preview |
| 27 | + if: ${{ github.event_name == 'push' || ((github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' ) && !github.event.pull_request.head.repo.fork ) }} |
| 28 | + runs-on: ubuntu-latest |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Set preview path (PR) |
| 32 | + if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }} |
| 33 | + env: |
| 34 | + PREVIEW_PATH: pr/${{ github.event.pull_request.number || inputs.pr_number }} |
| 35 | + run: | |
| 36 | + echo "PREVIEW_PATH=$PREVIEW_PATH" >> "$GITHUB_ENV" |
| 37 | +
|
| 38 | + - name: Set preview path (push) |
| 39 | + if: ${{ github.event_name == 'push' }} |
| 40 | + env: |
| 41 | + PREVIEW_PATH: main |
| 42 | + run: | |
| 43 | + echo "PREVIEW_PATH=$PREVIEW_PATH" >> "$GITHUB_ENV" |
| 44 | +
|
| 45 | + - uses: actions/checkout@v4 |
| 46 | + |
| 47 | + - name: Install Node.js |
| 48 | + uses: actions/setup-node@v4 |
| 49 | + with: |
| 50 | + node-version: 20 |
| 51 | + |
| 52 | + - name: Install rust stable toolchain |
| 53 | + uses: dtolnay/rust-toolchain@stable |
| 54 | + |
| 55 | + - name: Add wasm target |
| 56 | + run: rustup target add wasm32-unknown-unknown |
| 57 | + |
| 58 | + - name: Install tools |
| 59 | + uses: taiki-e/install-action@v2 |
| 60 | + with: |
| 61 | + tool: wasm-bindgen,wasm-opt,wasm-pack,cargo-make |
| 62 | + |
| 63 | + - name: Build examples |
| 64 | + run: cargo make deploy |
| 65 | + |
| 66 | + - name: Deploy Docs to Preview Branch |
| 67 | + uses: peaceiris/actions-gh-pages@v4 |
| 68 | + with: |
| 69 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + publish_dir: ./deploy-out |
| 71 | + destination_dir: ${{ env.PREVIEW_PATH }} |
| 72 | + publish_branch: generated-deploy-preview |
| 73 | + |
| 74 | + - name: Find Docs Comment |
| 75 | + if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }} |
| 76 | + uses: peter-evans/find-comment@v3 |
| 77 | + id: fc |
| 78 | + with: |
| 79 | + issue-number: ${{ github.event.pull_request.number || inputs.pr_number }} |
| 80 | + comment-author: "github-actions[bot]" |
| 81 | + body-includes: Deployment for this PR has been generated |
| 82 | + |
| 83 | + - name: Get current timestamp |
| 84 | + if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }} |
| 85 | + id: get_timestamp |
| 86 | + run: echo "TIMESTAMP=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV |
| 87 | + |
| 88 | + - name: Create or Update Docs Comment |
| 89 | + if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }} |
| 90 | + uses: peter-evans/create-or-update-comment@v4 |
| 91 | + with: |
| 92 | + issue-number: ${{ github.event.pull_request.number || inputs.pr_number }} |
| 93 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 94 | + body: | |
| 95 | + Deployment for this PR has been generated and is available at: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ env.PREVIEW_PATH }}/browser-echo/ |
| 96 | +
|
| 97 | + Last updated: ${{ env.TIMESTAMP }} |
| 98 | + edit-mode: replace |
0 commit comments