|
| 1 | +name: Build and Deploy pages to GitHub Pages |
| 2 | +on: [push, workflow_dispatch] |
| 3 | + |
| 4 | +permissions: |
| 5 | + contents: read |
| 6 | + pages: write |
| 7 | + id-token: write |
| 8 | + |
| 9 | +jobs: |
| 10 | + list-branches: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + branches: ${{ steps.set-branches.outputs.branches }} |
| 14 | + steps: |
| 15 | + - name: Checkout repo |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + - name: Get branch list and set output |
| 20 | + id: set-branches |
| 21 | + run: | |
| 22 | + BRANCHES=$( |
| 23 | + git branch -r | |
| 24 | + grep -Ev 'HEAD|v1|v2' | |
| 25 | + sed 's/^[ *]*//' | |
| 26 | + sed 's/^origin\///' | |
| 27 | + jq -R . | |
| 28 | + jq -cs |
| 29 | + ) |
| 30 | + echo "branches=$BRANCHES" >> "$GITHUB_OUTPUT" |
| 31 | +
|
| 32 | + build-compat-pages: |
| 33 | + needs: list-branches |
| 34 | + runs-on: ubuntu-latest |
| 35 | + strategy: |
| 36 | + matrix: |
| 37 | + branch: ${{ fromJson(needs.list-branches.outputs.branches) }} |
| 38 | + name: Build for ${{ matrix.branch }} |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + ref: ${{ matrix.branch }} |
| 43 | + - name: Build cache key |
| 44 | + id: cache-key |
| 45 | + run: | |
| 46 | + HASH=$(git rev-parse --short HEAD) |
| 47 | + echo "CACHE_KEY=${{ matrix.branch }}-$HASH" >> "$GITHUB_ENV" |
| 48 | + - name: Restore cached artifacts |
| 49 | + id: artifacts-restore |
| 50 | + uses: actions/cache/restore@v4 |
| 51 | + with: |
| 52 | + path: ${{ matrix.branch }} |
| 53 | + key: ${{ env.CACHE_KEY }} |
| 54 | + - uses: actions/setup-node@v4 |
| 55 | + if: steps.artifacts-restore.outputs.cache-hit != 'true' |
| 56 | + with: |
| 57 | + node-version: 23 |
| 58 | + cache: npm |
| 59 | + - name: Build |
| 60 | + if: steps.artifacts-restore.outputs.cache-hit != 'true' |
| 61 | + run: | |
| 62 | + npm ci |
| 63 | + npm run build-compat |
| 64 | + npm run bundle |
| 65 | + - name: Prepare build artifacts |
| 66 | + if: steps.artifacts-restore.outputs.cache-hit != 'true' |
| 67 | + run: | |
| 68 | + mkdir -p ${{ matrix.branch }}/compat |
| 69 | + cp tests/compat/index.html tests/compat/compat-data.js tests/compat/tests.js tests/compat/browsers-runner.js ${{ matrix.branch }}/compat |
| 70 | + mkdir -p ${{ matrix.branch }}/bundles |
| 71 | + cp tests/bundles/* ${{ matrix.branch }}/bundles |
| 72 | + mkdir -p ${{ matrix.branch }}/unit-browser |
| 73 | + cp tests/unit-browser/* ${{ matrix.branch }}/unit-browser |
| 74 | + - name: Save cached artifacts |
| 75 | + if: steps.artifacts-restore.outputs.cache-hit != 'true' |
| 76 | + uses: actions/cache/save@v4 |
| 77 | + with: |
| 78 | + path: ${{ matrix.branch }} |
| 79 | + key: ${{ env.CACHE_KEY }} |
| 80 | + - name: Upload artifacts for branch ${{ matrix.branch }} |
| 81 | + uses: actions/upload-artifact@v4 |
| 82 | + with: |
| 83 | + name: ${{ matrix.branch }} |
| 84 | + path: ${{ matrix.branch }} |
| 85 | + |
| 86 | + combine-pages-and-deploy: |
| 87 | + needs: build-compat-pages |
| 88 | + runs-on: ubuntu-latest |
| 89 | + environment: |
| 90 | + name: github-pages |
| 91 | + url: ${{ steps.deployment.outputs.page_url }} |
| 92 | + steps: |
| 93 | + - uses: actions/checkout@v4 |
| 94 | + - name: Download artifacts |
| 95 | + uses: actions/download-artifact@v4 |
| 96 | + with: |
| 97 | + path: pages |
| 98 | + - name: Add docs |
| 99 | + run: cp -r docs/ pages/ |
| 100 | + - name: Setup Pages |
| 101 | + uses: actions/configure-pages@v5 |
| 102 | + - name: Upload GitHub Pages artifact |
| 103 | + uses: actions/upload-pages-artifact@v3 |
| 104 | + with: |
| 105 | + path: pages |
| 106 | + - name: Deploy to GitHub Pages |
| 107 | + id: deployment |
| 108 | + uses: actions/deploy-pages@v4 |
0 commit comments