Skip to content

Commit 821afc5

Browse files
authored
Merge pull request #1712 from vprashar2929/acpi-wk-status
fix(ci): ensure proper status reporting for mock-acpi workflow
2 parents 1f14180 + dd34274 commit 821afc5

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

.github/workflows/mock_acpi.yml

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@ on: # yamllint disable-line rule:truthy
66
types: [created]
77

88
jobs:
9+
# Since `issue_comment` event runs on the default branch,
10+
# we need to get the branch of the pull request
11+
fetch-branch-name:
12+
if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
13+
name: Fetch branch name
14+
runs-on: ubuntu-latest
15+
outputs:
16+
head_ref: ${{ steps.pr_branch.outputs.head_ref }}
17+
head_sha: ${{ steps.pr_branch.outputs.head_sha }}
18+
steps:
19+
- name: Get PR branch
20+
id: pr_branch
21+
uses: xt0rted/pull-request-comment-branch@v2
22+
# Since `issue_comment` event workflow will not appear on the
23+
# pull request page, we need to set the status of the job
24+
# in order to attach it to the pull request itself
25+
set-status-pending:
26+
if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
27+
name: Set job status as pending
28+
runs-on: ubuntu-latest
29+
needs: [fetch-branch-name]
30+
steps:
31+
- name: Set job status as pending
32+
uses: myrotvorets/set-commit-status-action@master
33+
with:
34+
sha: ${{ needs.fetch-branch-name.outputs.head_sha }}
35+
token: ${{ secrets.GITHUB_TOKEN }}
36+
status: pending
37+
938
create-runner:
1039
if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
1140
name: Create Runner
@@ -25,7 +54,7 @@ jobs:
2554
setup-runner:
2655
if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
2756
name: Setup Runner
28-
needs: create-runner
57+
needs: [fetch-branch-name, create-runner]
2958
runs-on: self-hosted
3059
continue-on-error: true # This is done to release equinix runners irrespective of failure
3160
outputs:
@@ -50,6 +79,8 @@ jobs:
5079
5180
- name: Checkout code
5281
uses: actions/checkout@v3
82+
with:
83+
ref: ${{ needs.fetch-branch-name.outputs.head_ref }}
5384

5485
- name: Run playbook
5586
id: run-playbook
@@ -68,7 +99,7 @@ jobs:
6899
if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
69100
name: Cleanup
70101
runs-on: ubuntu-latest
71-
needs: [setup-runner]
102+
needs: create-runner
72103
steps:
73104
- name: delete runner
74105
uses: rootfs/metal-delete-action@main
@@ -82,10 +113,24 @@ jobs:
82113
if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
83114
name: Mark workflow as failed
84115
runs-on: ubuntu-latest
85-
needs: [setup-runner]
116+
needs: setup-runner
86117
steps:
87118
- name: Mark workflow as failed if playbook failed
88119
if: needs.setup-runner.outputs.playbook-status == 'failure'
89120
run: |
90121
echo "Playbook failed, marking workflow as failed"
91122
exit 1
123+
124+
set-final-status:
125+
if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
126+
name: Set final status
127+
runs-on: ubuntu-latest
128+
needs: fetch-branch-name
129+
steps:
130+
- name: Set job status as ${{ job.status }}
131+
uses: myrotvorets/set-commit-status-action@master
132+
if: always()
133+
with:
134+
sha: ${{ needs.fetch-branch-name.outputs.head_sha }}
135+
token: ${{ secrets.GITHUB_TOKEN }}
136+
status: ${{ job.status }}

0 commit comments

Comments
 (0)