PR summary comment #53
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: PR summary comment | |
| on: | |
| workflow_run: | |
| workflows: ['Pull request validation'] | |
| types: [completed] | |
| permissions: | |
| actions: read | |
| pull-requests: write | |
| jobs: | |
| comment: | |
| if: >- | |
| github.event.workflow_run.conclusion == 'success' | |
| && github.event.workflow_run.event == 'pull_request' | |
| name: Post PR summary comment | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Get PR number | |
| id: pr-info | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| GH_REPO: ${{ github.repository }} | |
| RUN_ID: ${{ github.event.workflow_run.id }} | |
| run: | | |
| # Get PR number from the workflow run metadata. | |
| # For same-repo PRs, GitHub populates .pull_requests[] in the run object. | |
| # jq's `// empty` outputs nothing (instead of "null") when the array is empty (fork PRs). | |
| PR_NUMBER=$(gh api "repos/${GH_REPO}/actions/runs/${RUN_ID}" --jq '.pull_requests[0].number // empty') | |
| # For fork PRs, .pull_requests[] is empty (GitHub security restriction). | |
| # Fall back to finding the open PR whose head SHA matches the workflow run's commit. | |
| if [ -z "$PR_NUMBER" ]; then | |
| HEAD_SHA="${{ github.event.workflow_run.head_sha }}" | |
| PR_NUMBER=$(gh api "repos/${GH_REPO}/pulls?state=open&sort=updated&direction=desc&per_page=30" --jq ".[] | select(.head.sha == \"${HEAD_SHA}\") | .number" | head -1) | |
| fi | |
| if [ -z "$PR_NUMBER" ]; then | |
| echo "Could not determine PR number, skipping" | |
| echo "pr_number=" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT | |
| echo "Found PR number: $PR_NUMBER" | |
| - name: Check for docsite artifact | |
| if: steps.pr-info.outputs.pr_number != '' | |
| id: check-docsite | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: docsite-storybook-build | |
| path: docsite-build | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ github.token }} | |
| continue-on-error: true | |
| - name: Post summary comment | |
| if: steps.pr-info.outputs.pr_number != '' | |
| env: | |
| PR_NUMBER: ${{ steps.pr-info.outputs.pr_number }} | |
| RUN_ID: ${{ github.event.workflow_run.id }} | |
| HAS_DOCSITE: ${{ steps.check-docsite.outcome }} | |
| GH_TOKEN: ${{ github.token }} | |
| GH_REPO: ${{ github.repository }} | |
| run: | | |
| RUN_URL="https://github.com/${GH_REPO}/actions/runs/${RUN_ID}" | |
| MARKER="<!-- pr-summary-comment -->" | |
| BODY="${MARKER} | |
| ## 📋 PR Validation Summary | |
| Check the **[Build react library](${RUN_URL})** job summary for detailed reports: | |
| - 📦 **Bundle Size** — size comparison against the base branch" | |
| if [ "$HAS_DOCSITE" == "success" ]; then | |
| BODY="${BODY} | |
| - 📖 **Docsite Preview** — build artifact with local preview instructions" | |
| fi | |
| BODY="${BODY} | |
| > _To view: click the link above → select the **Build react library** job → open the **Summary** tab._" | |
| # Find existing comment | |
| EXISTING_COMMENT_ID=$(gh api "repos/${GH_REPO}/issues/${PR_NUMBER}/comments" --paginate --jq ".[] | select(.body | contains(\"${MARKER}\")) | .id" | head -1) | |
| if [ -n "$EXISTING_COMMENT_ID" ]; then | |
| gh api "repos/${GH_REPO}/issues/comments/${EXISTING_COMMENT_ID}" -X PATCH -f body="$BODY" | |
| echo "Updated existing summary comment (ID: $EXISTING_COMMENT_ID)" | |
| else | |
| gh pr comment "$PR_NUMBER" --body "$BODY" | |
| echo "Created new summary comment" | |
| fi |