Skip to content

Comment screenshots on PR #2823

Comment screenshots on PR

Comment screenshots on PR #2823

name: Comment screenshots on PR
on:
workflow_run:
workflows: ["On pull request"]
types:
- completed
jobs:
upload_and_comment:
name: "Upload and Comment on PR"
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Download artifact
uses: actions/github-script@v7
with:
script: |
var artifacts = await github.rest.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 == "ci_screenshots"
})[0];
var download = await github.rest.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 }}/ci_screenshots.zip', Buffer.from(download.data));
- name: Unzip artifact
run: unzip ci_screenshots.zip
- name: Upload screenshots and generate message
id: upload_screenshots
run: |
./ops/pr_screenshots/generate_screenshots_message.py ${{ secrets.GITHUB_TOKEN }}
MESSAGE=$(cat ci_screenshots_message.md)
MESSAGE="${MESSAGE//'%'/'%25'}"
MESSAGE="${MESSAGE//$'\n'/'%0A'}"
MESSAGE="${MESSAGE//$'\r'/'%0D'}"
echo "::set-output name=message::$MESSAGE"
- name: Comment screenshots message on PR
uses: phulsechinmay/rewritable-pr-comment@v0.3.0
with:
message: ${{ steps.upload_screenshots.outputs.message }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT_IDENTIFIER: "screenshots-comment-rewritable-action"
ISSUE_ID: ${{ steps.upload_screenshots.outputs.pr }}