Dist Files Size Diff (Comment) #604
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Dist Files Size Diff (Comment) | |
| # workflow_run is required to post PR comments from fork-triggered runs: | |
| # the upstream `Dist Files Size Diff` workflow runs on `pull_request` (read-only | |
| # token from forks) and uploads the diff as an artifact; this workflow runs in | |
| # the base-repo context with `pull-requests: write` to post the comment. | |
| # Safety: we gate on workflow_run.conclusion, validate the PR number with a | |
| # regex, and never execute artifact contents (diff.md is posted as comment body). | |
| on: | |
| workflow_run: # zizmor: ignore[dangerous-triggers] | |
| workflows: ['Dist Files Size Diff'] | |
| types: | |
| - completed | |
| permissions: {} | |
| jobs: | |
| dist-files-size-diff: | |
| if: github.event.workflow_run.conclusion == 'success' | |
| permissions: | |
| contents: read # Required to checkout the repository (default) | |
| actions: read # Required to download artifacts from the triggering workflow run | |
| pull-requests: write # Required to post the size diff comment on the pull request | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: dist-size-diff | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Read pr-number artifact to env var | |
| id: read-pr-number | |
| run: | | |
| PR_NUMBER=$(cat ./pr-number) | |
| if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then | |
| echo "Invalid PR number: $PR_NUMBER" | |
| exit 1 | |
| fi | |
| echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT | |
| - name: Comment on the pull request (if success) | |
| uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5 | |
| with: | |
| number: ${{ steps.read-pr-number.outputs.pr-number }} | |
| path: ./diff.md |