Skip to content

Dependency Update Comment #117

Dependency Update Comment

Dependency Update Comment #117

name: Dependency Update Comment
on:
workflow_run:
workflows: ["Dependency Update Test"]
types:
- completed
permissions:
pull-requests: write
jobs:
comment:
name: Post PR Comment
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request'
steps:
- name: Download test results
uses: actions/download-artifact@v4
with:
name: dependency-test-results
path: ./test-results/
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
continue-on-error: true
- name: Check if artifact exists
id: check-artifact
run: |
if [ -f "./test-results/pr_number.txt" ]; then
echo "artifact_exists=true" >> $GITHUB_OUTPUT
else
echo "artifact_exists=false" >> $GITHUB_OUTPUT
fi
- name: Comment on PR
if: steps.check-artifact.outputs.artifact_exists == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const prNumber = parseInt(fs.readFileSync('./test-results/pr_number.txt', 'utf8').trim());
const hasMajorUpdates = fs.readFileSync('./test-results/has_major_updates.txt', 'utf8').trim() === 'true';
const workflowConclusion = '${{ github.event.workflow_run.conclusion }}';
let body = '## Dependency Update Test Results\n\n';
body += '| Check | Status |\n';
body += '|-------|--------|\n';
if (workflowConclusion === 'success') {
body += '| Build | :white_check_mark: Passed |\n';
body += '| Tests | :white_check_mark: Passed |\n';
body += '| Matrix Test | :white_check_mark: Passed |\n';
} else {
body += '| Tests | :x: Failed |\n';
body += '\n> **Error**: Some tests failed. Please check the [workflow run](${{ github.event.workflow_run.html_url }}) for details.\n';
}
if (hasMajorUpdates) {
body += '\n> **Note**: This PR contains major version updates. Please review carefully.\n';
}
body += '\n---\n';
body += '_This comment was automatically generated by the Dependency Update Test workflow._\n';
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Dependency Update Test Results')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body
});
}