Fix blocks-ci screenshot diff output and PR comment content

This commit is contained in:
Henning Dieterichs
2026-04-07 17:36:52 +02:00
committed by Henning Dieterichs
parent a199142a6f
commit 706c2ced9e

View File

@@ -62,49 +62,17 @@ jobs:
test/componentFixtures/.screenshots/current/manifest.json \
test/componentFixtures/blocks-ci-screenshots.md \
https://hediet-screenshots.azurewebsites.net \
--json \
> /tmp/blocks-ci-diff.json 2>/tmp/blocks-ci-stderr.txt \
> /tmp/blocks-ci-updated.md 2>/tmp/blocks-ci-stderr.txt \
&& echo "match=true" >> "$GITHUB_OUTPUT" \
|| {
echo "match=false" >> "$GITHUB_OUTPUT"
cat /tmp/blocks-ci-stderr.txt >&2
DIFF=$(cat /tmp/blocks-ci-diff.json)
echo "diff<<BLOCKS_CI_EOF" >> "$GITHUB_OUTPUT"
echo "$DIFF" >> "$GITHUB_OUTPUT"
CONTENT=$(cat /tmp/blocks-ci-updated.md)
echo "content<<BLOCKS_CI_EOF" >> "$GITHUB_OUTPUT"
echo "$CONTENT" >> "$GITHUB_OUTPUT"
echo "BLOCKS_CI_EOF" >> "$GITHUB_OUTPUT"
}
- name: Suggest blocks-ci screenshot update
if: github.event_name == 'pull_request' && steps.blocks-ci.outputs.match == 'false'
uses: actions/github-script@v7
with:
script: |
const diff = JSON.parse(process.env.DIFF_JSON);
const filePath = 'test/componentFixtures/blocks-ci-screenshots.md';
const marker = '<!-- blocks-ci-screenshot-suggestion -->';
try {
await github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
commit_id: context.payload.pull_request.head.sha,
event: 'COMMENT',
body: `${marker}\n### blocks-ci screenshots changed\n\nApply the suggestion below to update the committed screenshots.`,
comments: [{
path: filePath,
start_line: diff.startLine < diff.endLine ? diff.startLine : undefined,
line: diff.endLine,
side: 'RIGHT',
body: `${marker}\nScreenshots for \`blocks-ci\` fixtures have changed. Apply this suggestion to accept:\n\n\`\`\`suggestion\n${diff.replacement}\n\`\`\``,
}],
});
} catch (err) {
core.warning(`Failed to post blocks-ci screenshot suggestion: ${err.message}`);
}
env:
DIFF_JSON: ${{ steps.blocks-ci.outputs.diff }}
- name: Upload screenshots
uses: actions/upload-artifact@v7
with:
@@ -152,12 +120,24 @@ jobs:
SCREENSHOT_SERVICE_TOKEN: ${{ steps.oidc.outputs.token }}
- name: Post PR comment
if: github.event_name == 'pull_request' && steps.diff.outputs.has_changes == 'true'
if: github.event_name == 'pull_request' && (steps.diff.outputs.has_changes == 'true' || steps.blocks-ci.outputs.match == 'false')
uses: actions/github-script@v7
with:
script: |
const marker = '<!-- screenshot-diff-report -->';
const body = process.env.COMMENT_BODY;
let body = process.env.COMMENT_BODY || '';
const blocksCiContent = process.env.BLOCKS_CI_CONTENT;
if (blocksCiContent) {
if (body) { body += '\n\n---\n\n'; }
body += '### blocks-ci screenshots changed\n\n';
body += 'Replace the contents of `test/componentFixtures/blocks-ci-screenshots.md` with:\n\n';
body += '<details>\n<summary>Updated blocks-ci-screenshots.md</summary>\n\n';
body += '```md\n' + blocksCiContent + '\n```\n\n';
body += '</details>';
}
body = marker + '\n' + body;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
@@ -184,11 +164,12 @@ jobs:
}
env:
COMMENT_BODY: ${{ steps.diff.outputs.body }}
BLOCKS_CI_CONTENT: ${{ steps.blocks-ci.outputs.content }}
- name: Fail if blocks-ci hashes changed
if: steps.blocks-ci.outputs.match == 'false'
run: |
echo "::error::blocks-ci screenshot hashes do not match committed file. See PR review suggestion to update."
echo "::error::blocks-ci screenshot hashes do not match committed file. See PR comment for updated content."
exit 1
# - name: Compare screenshots