Skip to content

Commit 74c6d88

Browse files
committed
fix(ci): comment triggered action should set status on PR
1 parent 3956cbc commit 74c6d88

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

.github/actions/gradle-task/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ runs:
2222
with:
2323
cache-read-only: false
2424
cache-encryption-key: ${{ inputs.gradle-cache-encryption-key }}
25-
- name: Ktfmt
25+
- name: Gradle task
2626
shell: bash
2727
run: ./project/gradlew -p project ${{ inputs.task }} --scan
2828
env:

.github/workflows/build-test-lint.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ jobs:
1212
name: ktfmt
1313
runs-on: ubuntu-latest
1414
steps:
15+
- name: "Validate input ref"
16+
if: ${{ inputs.ref == '' }}
17+
run: |
18+
echo "Input ref is empty. Please provide a valid ref."
19+
exit 1
1520
- name: "Checkout"
1621
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
1722
with:
@@ -24,6 +29,11 @@ jobs:
2429
name: Build
2530
runs-on: ubuntu-latest
2631
steps:
32+
- name: "Validate input ref"
33+
if: ${{ inputs.ref == '' }}
34+
run: |
35+
echo "Input ref is empty. Please provide a valid ref."
36+
exit 1
2737
- name: "Checkout"
2838
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
2939
with:

.github/workflows/pull-request-comment.yaml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@ name: PR comment trigger
66
types: [created]
77

88
jobs:
9-
debug:
10-
name: Debug
11-
runs-on: ubuntu-latest
12-
steps:
13-
- uses: hmarr/debug-action@v3
149
check-comment:
1510
name: PR Comment
1611
runs-on: ubuntu-latest
1712
permissions:
1813
contents: read
19-
checks: write
2014
outputs:
21-
sha: ${{ steps.get-pr-info.outputs.sha }}
15+
sha: ${{ fromJson(steps.get-pr-info.outputs.result).sha }}
2216
if: |
2317
github.event.issue.pull_request &&
2418
github.event.comment.body == '/run-tests' &&
@@ -39,6 +33,7 @@ jobs:
3933
if (!pr) {
4034
throw new Error('Pull request not found');
4135
}
36+
console.log(`Pull request head SHA: ${pr.head.sha}`);
4237
return {
4338
sha: pr.head.sha
4439
};
@@ -55,23 +50,38 @@ jobs:
5550
pr-checkpoint-status:
5651
name: "PR Checkpoint Status"
5752
runs-on: ubuntu-latest
53+
permissions:
54+
actions: read
55+
statuses: write
56+
checks: write
5857
needs: [check-comment, build-test-lint]
5958
steps:
6059
- name: Set status check
6160
uses: actions/github-script@v7
61+
env:
62+
SHA: ${{ needs.check-comment.outputs.sha }}
6263
with:
6364
github-token: ${{ secrets.GITHUB_TOKEN }}
6465
script: |
6566
const { owner, repo } = context.repo;
66-
const sha = ${{ needs.check-comment.outputs.sha }}
67-
68-
// Set the status check
69-
await github.rest.repos.createCommitStatus({
67+
const sha = process.env.SHA;
68+
console.log(`Setting status check for SHA: ${sha}`);
69+
await github.rest.checks.create({
70+
owner,
71+
repo,
72+
name: 'PR Checkpoint Status',
73+
head_sha: sha,
74+
status: 'completed',
75+
conclusion: 'success',
76+
output: {
77+
title: 'Build & Test Completed',
78+
summary: 'All checks passed successfully.',
79+
text: 'All checks passed successfully.'
80+
}
81+
});
82+
const { data: checkRuns } = await github.rest.checks.listForRef({
7083
owner,
7184
repo,
72-
sha,
73-
state: 'success', // 'error', 'failure', 'pending'
74-
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}',
75-
description: 'Build and test completed successfully',
76-
context: 'PR Checkpoint Status' // This must match the name in branch protection
85+
ref: sha
7786
});
87+
console.log(`Check runs: ${JSON.stringify(checkRuns)}`);

0 commit comments

Comments
 (0)