|
| 1 | +name: Compare Build Outputs |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ['Generate Docs'] |
| 6 | + types: [completed] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + actions: read |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + get-comparators: |
| 15 | + name: Get Comparators |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: github.event.workflow_run.event == 'pull_request' |
| 18 | + outputs: |
| 19 | + comparators: ${{ steps.get-comparators.outputs.comparators }} |
| 20 | + steps: |
| 21 | + - name: Harden Runner |
| 22 | + uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 |
| 23 | + with: |
| 24 | + egress-policy: audit |
| 25 | + |
| 26 | + - name: Checkout Code |
| 27 | + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
| 28 | + |
| 29 | + - name: List comparators |
| 30 | + id: get-comparators |
| 31 | + run: | |
| 32 | + # List all .mjs files in scripts/compare-builds/ and remove the .mjs extension |
| 33 | + COMPARATORS=$(ls scripts/compare-builds/*.mjs | xargs -n1 basename | sed 's/\.mjs$//' | jq -R -s -c 'split("\n")[:-1]') |
| 34 | + echo "comparators=$COMPARATORS" >> $GITHUB_OUTPUT |
| 35 | +
|
| 36 | + web: |
| 37 | + name: Compare ${{ matrix.comparator }} Bundle Size |
| 38 | + runs-on: ubuntu-latest |
| 39 | + needs: [get-comparators] |
| 40 | + strategy: |
| 41 | + matrix: |
| 42 | + comparator: ${{ fromJSON(needs.get-comparators.outputs.comparators) }} |
| 43 | + |
| 44 | + steps: |
| 45 | + - name: Harden Runner |
| 46 | + uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 |
| 47 | + with: |
| 48 | + egress-policy: audit |
| 49 | + |
| 50 | + - name: Checkout Code |
| 51 | + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
| 52 | + |
| 53 | + - name: Download Output (HEAD) |
| 54 | + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 |
| 55 | + with: |
| 56 | + name: ${{ matrix.comparator }} |
| 57 | + path: head |
| 58 | + run-id: ${{ github.event.workflow_run.id }} |
| 59 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + |
| 61 | + - name: Get Run ID from BASE |
| 62 | + id: base-run |
| 63 | + env: |
| 64 | + WORKFLOW_ID: ${{ github.event.workflow_run.workflow_id }} |
| 65 | + GH_TOKEN: ${{ github.token }} |
| 66 | + run: | |
| 67 | + ID=$(gh run list -c $GITHUB_SHA -w $WORKFLOW_ID -L 1 --json databaseId --jq ".[].databaseId") |
| 68 | + echo "run_id=$ID" >> $GITHUB_OUTPUT |
| 69 | +
|
| 70 | + - name: Download Output (BASE) |
| 71 | + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 |
| 72 | + with: |
| 73 | + name: web |
| 74 | + path: base |
| 75 | + run-id: ${{ steps.base-run.outputs.run_id }} |
| 76 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + |
| 78 | + - name: Compare Bundle Size |
| 79 | + id: compare |
| 80 | + run: | |
| 81 | + node scripts/compare-builds/${{ matrix.comparator }}.mjs > result.txt |
| 82 | +
|
| 83 | + - name: Upload comparison artifact |
| 84 | + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 |
| 85 | + with: |
| 86 | + name: ${{ matrix.comparator }} |
| 87 | + path: result.txt |
| 88 | + |
| 89 | + aggregate: |
| 90 | + name: Aggregate Comparison Results |
| 91 | + runs-on: ubuntu-latest |
| 92 | + needs: [web] |
| 93 | + |
| 94 | + steps: |
| 95 | + - name: Download all comparison artifacts |
| 96 | + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 |
| 97 | + with: |
| 98 | + path: results |
| 99 | + |
| 100 | + - name: Combine results |
| 101 | + id: combine |
| 102 | + run: | |
| 103 | + cat results/*/result.txt > combined.txt |
| 104 | + echo "combined<<EOF" >> $GITHUB_OUTPUT |
| 105 | + cat combined.txt >> $GITHUB_OUTPUT |
| 106 | + echo "EOF" >> $GITHUB_OUTPUT |
| 107 | +
|
| 108 | + - name: Add Comment to PR |
| 109 | + uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1 |
| 110 | + with: |
| 111 | + comment-tag: 'compared' |
| 112 | + message: ${{ steps.combine.outputs.combined }} |
| 113 | + pr-number: ${{ github.event.workflow_run.pull_requests[0].number }} |
0 commit comments