Skip to content

Knip-reporter

Knip-reporter #177

Workflow file for this run

name: Knip-reporter
on:
workflow_run:
workflows: ["Knip"]
types:
- completed
jobs:
knip-reporter:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion != 'success' }}
steps:
- name: Verify Runner's Identity
id: verify-runner
run: |
echo "Runner name: $RUNNER_NAME"
if [[ "$RUNNER_NAME" != *"GitHub Actions"* ]]; then
echo "This workflow must run on a GitHub Actions runner. (github-actions[bot])"
exit 1
fi
- uses: actions/download-artifact@v4
with:
name: knip-results
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Read pr number
id: pr-number
uses: juliangruber/read-file-action@v1
with:
path: ./pr-number.txt
trim: true
- name: Get or create comment ID for Knip Report
id: get-comment
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issue_number = ${{ steps.pr-number.outputs.content }};
// Fetch all comments on the PR
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});
// Look for an existing Knip report comment
let knipComment = comments.data.find(comment =>
comment.body.startsWith("| Knip Report |")
);
if (knipComment) {
console.log('Found existing Knip report comment:', knipComment.id);
core.setOutput('comment_id', knipComment.id); // Set the comment ID output
} else {
console.log('No existing Knip report comment found.');
core.setOutput('comment_id', ''); // No existing comment
}
- name: Report Knip results to pull request
uses: gitcoindev/knip-reporter@main
with:
verbose: true
comment_id: ${{ steps.get-comment.outputs.comment_id || github.workflow }}-knip-report
command_script_name: knip-ci
annotations: true
ignore_results: false
json_input: true
json_input_file_name: knip-results.json
pull_request_number: ${{ steps.pr-number.outputs.content }}
token: ${{ secrets.GITHUB_TOKEN }}