Skip to content

Commit 4a44820

Browse files
committed
ci(comment): make workflow reusable
Signed-off-by: Randolph Sapp <rs@ti.com>
1 parent aaa6548 commit 4a44820

2 files changed

Lines changed: 35 additions & 31 deletions

File tree

.github/workflows/check-files.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
git switch master
4141
4242
- name: Run check_files.py
43+
id: check
4344
env:
4445
EVENT_NUMBER: ${{ github.event.number }}
4546
run: |
@@ -60,19 +61,20 @@ jobs:
6061
echo "No new unreachable files found with check_files.py"
6162
fi >> "$GITHUB_STEP_SUMMARY"
6263
63-
# Prepare the artifacts
64-
mkdir -p ./results
65-
echo "$EVENT_NUMBER" > ./results/id
66-
cp "$GITHUB_STEP_SUMMARY" ./results/summary
67-
echo "$(wc -l < _new-warn.log)" > ./results/problem-count
64+
# Prepare the output
65+
SUMMARY=$(< "$GITHUB_STEP_SUMMARY")
66+
echo "issue_number=$EVENT_NUMBER" >> "$GITHUB_OUTPUT"
67+
echo "problem_count=$WARNING_COUNT" >> "$GITHUB_OUTPUT"
68+
echo "summary=$SUMMARY" >> "$GITHUB_OUTPUT"
6869
6970
# Exit with error if there are new warnings
7071
[ "$WARNING_COUNT" -eq "0" ]
7172
72-
- name: Save results
73-
uses: actions/upload-artifact@v4
73+
- name: Comment
74+
uses: ./.github/workflows/comment.yml
7475
if: always()
7576
with:
76-
name: results
77-
path: results/
78-
retention-days: 1
77+
issue_number: ${{ steps.check.outputs.issue_number }}
78+
problem_count: ${{ steps.check.outputs.problem_count }}
79+
summary: ${{ steps.check.outputs.summary }}
80+
secrets: inherit

.github/workflows/comment.yml

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
name: "comment"
33

44
on: # yamllint disable-line rule:truthy
5-
workflow_run:
6-
workflows:
7-
- rstcheck
8-
- check_toc_txt
9-
- check-files
10-
types:
11-
- completed
5+
workflow_call:
6+
inputs:
7+
issue_number:
8+
description: "PR / Issue number to comment on"
9+
required: true
10+
type: number
11+
problem_count:
12+
description: "Number of problems detected"
13+
required: true
14+
type: number
15+
summary:
16+
description: "Text summary that will be posted"
17+
required: true
18+
type: string
1219

1320
permissions:
1421
pull-requests: write # Required to leave a comment on a review
@@ -20,25 +27,20 @@ jobs:
2027
if: ${{ github.event.workflow_run.event == 'pull_request' }}
2128

2229
steps:
23-
- name: Download artifact
24-
uses: actions/download-artifact@v4
25-
with:
26-
name: results
27-
run-id: ${{ github.event.workflow_run.id }}
28-
github-token: ${{ secrets.GITHUB_TOKEN }}
29-
path: results
30-
3130
- name: Update pr with info from other runners
3231
uses: actions/github-script@v7
32+
env:
33+
ISSUE_NUMBER: ${{ inputs.issue_number }}
34+
PROBLEM_COUNT: ${{ inputs.problem_count }}
35+
SUMMARY: ${{ inputs.summary }}
3336
with:
3437
github-token: ${{ secrets.GITHUB_TOKEN }}
3538
script: |
36-
var fs = require('fs');
37-
var issue_number = Number(fs.readFileSync('./results/id'));
38-
var problem_count = Number(fs.readFileSync(
39-
'./results/problem-count'
40-
));
41-
var summary = String(fs.readFileSync('./results/summary'));
39+
const { env } = require('node:process');
40+
41+
var issue_number = Number(env.ISSUE_NUMBER);
42+
var problem_count = Number(env.PROBLEM_COUNT);
43+
var summary = String(env.SUMMARY);
4244
4345
if (problem_count > 0) {
4446
github.rest.issues.createComment({

0 commit comments

Comments
 (0)