From 68116414d09f5448f77e863b2c252508705cd606 Mon Sep 17 00:00:00 2001 From: Eric Fennis Date: Fri, 7 Mar 2025 10:48:06 +0100 Subject: [PATCH] ci(pr-comment): Fix icon preview comment on PRs (#2854) * fix: PR icon Comment * formatting --- .github/workflows/comment-icon-preview.yml | 57 +++++++++++++++++++ .../workflows/pull-request-icon-preview.yml | 26 ++++----- 2 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/comment-icon-preview.yml diff --git a/.github/workflows/comment-icon-preview.yml b/.github/workflows/comment-icon-preview.yml new file mode 100644 index 000000000..d38e627d6 --- /dev/null +++ b/.github/workflows/comment-icon-preview.yml @@ -0,0 +1,57 @@ +name: Icon preview comment + +on: + workflow_run: + workflows: ['Pull request icon preview'] + types: + - completed + +jobs: + upload: + runs-on: ubuntu-latest + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + steps: + - name: 'Download artifact' + uses: actions/github-script@v3.1.0 + with: + script: | + var artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "pr" + })[0]; + var download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); + + - run: unzip pr.zip + + - name: 'Get PR number' + run: cat pr/NR + id: pr-number + + - name: Find Comment + uses: peter-evans/find-comment@v2 + id: pr-comment + with: + issue-number: ${{ steps.pr-number.outputs.stdout }} + comment-author: 'github-actions[bot]' + body-includes: Added or changed icons + + - name: Create or update comment + uses: peter-evans/create-or-update-comment@v3 + with: + comment-id: ${{ steps.pr-comment.outputs.comment-id }} + issue-number: ${{ steps.pr-number.outputs.stdout }} + body-path: ./pr/comment-markup.md + edit-mode: replace diff --git a/.github/workflows/pull-request-icon-preview.yml b/.github/workflows/pull-request-icon-preview.yml index 0f4317b94..8370dcb79 100644 --- a/.github/workflows/pull-request-icon-preview.yml +++ b/.github/workflows/pull-request-icon-preview.yml @@ -1,4 +1,4 @@ -name: Pull request icon previews +name: Pull request icon preview on: pull_request: @@ -22,28 +22,22 @@ jobs: with: files: icons/*.svg - - name: Find Comment - uses: peter-evans/find-comment@v2 - id: pr-comment - with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: 'github-actions[bot]' - body-includes: Added or changed icons - - uses: actions/setup-node@v4 - name: Install svgson for code preview (safer and faster than installing all deps) run: npm install svgson + - name: Save PR number + run: | + mkdir -p ./pr + echo ${{ github.event.number }} > ./pr/NR + - name: Generate comment markup - run: node ./scripts/generateChangedIconsCommentMarkup.mjs >> comment-markup.md + run: node ./scripts/generateChangedIconsCommentMarkup.mjs >> ./pr/comment-markup.md id: comment-markup env: CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} - - name: Create or update comment - uses: peter-evans/create-or-update-comment@v3 + - uses: actions/upload-artifact@v4 with: - comment-id: ${{ steps.pr-comment.outputs.comment-id }} - issue-number: ${{ github.event.pull_request.number }} - body-path: ./comment-markup.md - edit-mode: replace + name: pr + path: pr/