Comment on pull request #1
This file contains 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: Comment on pull request | |
on: | |
workflow_run: | |
workflows: [Prettier code formatter] | |
types: | |
- completed | |
jobs: | |
comment: | |
# available images: https://github.com/actions/runner-images#available-images | |
runs-on: ubuntu-latest | |
if: > | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'failure' | |
steps: | |
- name: Download artifact | |
uses: actions/github-script@v7 | |
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 == "HTML Diff" | |
})[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}}/HTML Diff.zip', Buffer.from(download.data)); | |
- name: Unzip artifact | |
run: unzip HTML\ Diff.zip | |
- name: PR comment with html diff | |
# https://docs.github.com/en/actions/learn-github-actions/expressions#failure-with-conditions | |
uses: thollander/actions-comment-pull-request@v2 | |
with: | |
filePath: diff.html |