Skip to content

Commit 32a0423

Browse files
committed
ci: update status when action triggered by issue comment
issue comment triggers do not automatically update check status in the PR, so use separate steps to update them, similar to how the tft.yml workflow works. For issue comment workflows, ensure that the head_sha is set early in the workflow and the status is only updated if there is a head_sha. Create a variable for context so it is created in one place and used in several places in the workflow. Ensure that the first steps in the workflow are to get the head_sha and set the status to In Progress. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
1 parent c2bd017 commit 32a0423

10 files changed

Lines changed: 311 additions & 83 deletions

.github/workflows/ansible-lint.yml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ env:
2424
permissions:
2525
contents: read
2626
pull-requests: read
27+
# This is required for the ability to create/update the Pull request status
28+
statuses: write
2729
jobs:
2830
ansible_lint:
2931
if: |
@@ -71,29 +73,41 @@ jobs:
7173
- { ansible_lint: "24.*", ansible: "2.16.*", python: "3.12" }
7274
- { ansible_lint: "26.*", ansible: "2.20.*", python: "3.13" }
7375
steps:
74-
- name: Update pip, git
75-
run: |
76-
set -euxo pipefail
77-
sudo apt update
78-
sudo apt install -y git
79-
80-
- name: Get PR head SHA
76+
- name: Get PR head SHA and context
8177
if: github.event_name == 'issue_comment'
82-
id: head_sha
78+
id: head_sha_context
8379
env:
8480
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8581
REPO: ${{ github.repository }}
8682
PR_NUMBER: ${{ github.event.issue.number }}
83+
CONTEXT: "${{ github.workflow }} / ${{ github.job }} (${{ matrix.versions.ansible_lint }}, ${{ matrix.versions.ansible }}, ${{ matrix.versions.python }}) (pull_request)"
8784
run: |
8885
set -euxo pipefail
8986
head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha')
9087
echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT"
88+
echo "context=$CONTEXT" >> "$GITHUB_OUTPUT"
89+
90+
- name: Set commit status as pending
91+
if: github.event_name == 'issue_comment'
92+
uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master
93+
with:
94+
sha: ${{ steps.head_sha_context.outputs.head_sha }}
95+
status: pending
96+
context: ${{ steps.head_sha_context.outputs.context }}
97+
description: Test started
98+
targetUrl: ""
99+
100+
- name: Update pip, git
101+
run: |
102+
set -euxo pipefail
103+
sudo apt update
104+
sudo apt install -y git
91105
92106
- name: Checkout repo
93107
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
94108
with:
95109
persist-credentials: false
96-
ref: ${{ steps.head_sha.outputs.head_sha || github.sha }}
110+
ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }}
97111

98112
- name: Install tox, tox-lsr
99113
run: |
@@ -115,3 +129,13 @@ jobs:
115129
LSR_ANSIBLE_LINT_ANSIBLE_DEP="ansible-core==${{ matrix.versions.ansible }}" \
116130
tox -x testenv:ansible-lint-collection.basepython="python${{ matrix.versions.python }}" \
117131
-e ansible-lint-collection
132+
133+
- name: Set final commit status
134+
if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != ''
135+
uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master
136+
with:
137+
sha: ${{ steps.head_sha_context.outputs.head_sha }}
138+
status: ${{ job.status }}
139+
context: ${{ steps.head_sha_context.outputs.context }}
140+
description: Test finished
141+
targetUrl: ""

.github/workflows/ansible-managed-var-comment.yml

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ on: # yamllint disable-line rule:truthy
2121
permissions:
2222
contents: read
2323
pull-requests: read
24+
# This is required for the ability to create/update the Pull request status
25+
statuses: write
2426
jobs:
2527
ansible_managed_var_comment:
2628
if: |
@@ -59,30 +61,42 @@ jobs:
5961
)
6062
runs-on: ubuntu-latest
6163
steps:
62-
- name: Update pip, git
63-
run: |
64-
set -euxo pipefail
65-
python3 -m pip install --upgrade pip
66-
sudo apt update
67-
sudo apt install -y git
68-
69-
- name: Get PR head SHA
64+
- name: Get PR head SHA and context
7065
if: github.event_name == 'issue_comment'
71-
id: head_sha
66+
id: head_sha_context
7267
env:
7368
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7469
REPO: ${{ github.repository }}
7570
PR_NUMBER: ${{ github.event.issue.number }}
71+
CONTEXT: "${{ github.workflow }} / ${{ github.job }} (pull_request)"
7672
run: |
7773
set -euxo pipefail
7874
head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha')
7975
echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT"
76+
echo "context=$CONTEXT" >> "$GITHUB_OUTPUT"
77+
78+
- name: Set commit status as pending
79+
if: github.event_name == 'issue_comment'
80+
uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master
81+
with:
82+
sha: ${{ steps.head_sha_context.outputs.head_sha }}
83+
status: pending
84+
context: ${{ steps.head_sha_context.outputs.context }}
85+
description: Test started
86+
targetUrl: ""
87+
88+
- name: Update pip, git
89+
run: |
90+
set -euxo pipefail
91+
python3 -m pip install --upgrade pip
92+
sudo apt update
93+
sudo apt install -y git
8094
8195
- name: Checkout repo
8296
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
8397
with:
8498
persist-credentials: false
85-
ref: ${{ steps.head_sha.outputs.head_sha || github.sha }}
99+
ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }}
86100

87101
- name: Install tox, tox-lsr
88102
run: |
@@ -93,3 +107,13 @@ jobs:
93107
run: |
94108
set -euxo pipefail
95109
TOXENV=ansible-managed-var-comment lsr_ci_runtox
110+
111+
- name: Set final commit status
112+
if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != ''
113+
uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master
114+
with:
115+
sha: ${{ steps.head_sha_context.outputs.head_sha }}
116+
status: ${{ job.status }}
117+
context: ${{ steps.head_sha_context.outputs.context }}
118+
description: Test finished
119+
targetUrl: ""

.github/workflows/ansible-test.yml

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ env:
2424
permissions:
2525
contents: read
2626
pull-requests: read
27+
# This is required for the ability to create/update the Pull request status
28+
statuses: write
2729
jobs:
2830
ansible_test:
2931
if: |
@@ -73,30 +75,42 @@ jobs:
7375
- { ansible: "2-20", python: "3.13" }
7476
- { ansible: "milestone", python: "3.13" }
7577
steps:
76-
- name: Update pip, git
77-
run: |
78-
set -euxo pipefail
79-
python3 -m pip install --upgrade pip
80-
sudo apt update
81-
sudo apt install -y git
82-
83-
- name: Get PR head SHA
78+
- name: Get PR head SHA and context
8479
if: github.event_name == 'issue_comment'
85-
id: head_sha
80+
id: head_sha_context
8681
env:
8782
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8883
REPO: ${{ github.repository }}
8984
PR_NUMBER: ${{ github.event.issue.number }}
85+
CONTEXT: "${{ github.workflow }} / ${{ github.job }} (${{ matrix.versions.ansible }}, ${{ matrix.versions.python }}) (pull_request)"
9086
run: |
9187
set -euxo pipefail
9288
head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha')
9389
echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT"
90+
echo "context=$CONTEXT" >> "$GITHUB_OUTPUT"
91+
92+
- name: Set commit status as pending
93+
if: github.event_name == 'issue_comment'
94+
uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master
95+
with:
96+
sha: ${{ steps.head_sha_context.outputs.head_sha }}
97+
status: pending
98+
context: ${{ steps.head_sha_context.outputs.context }}
99+
description: Test started
100+
targetUrl: ""
101+
102+
- name: Update pip, git
103+
run: |
104+
set -euxo pipefail
105+
python3 -m pip install --upgrade pip
106+
sudo apt update
107+
sudo apt install -y git
94108
95109
- name: Checkout repo
96110
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
97111
with:
98112
persist-credentials: false
99-
ref: ${{ steps.head_sha.outputs.head_sha || github.sha }}
113+
ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }}
100114

101115
- name: Install tox, tox-lsr
102116
run: |
@@ -116,3 +130,13 @@ jobs:
116130
tox \
117131
-x testenv:ansible-test-${{ matrix.versions.ansible }}.basepython="python${{ matrix.versions.python }}" \
118132
-e ansible-test-${{ matrix.versions.ansible }}
133+
134+
- name: Set final commit status
135+
if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != ''
136+
uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master
137+
with:
138+
sha: ${{ steps.head_sha_context.outputs.head_sha }}
139+
status: ${{ job.status }}
140+
context: ${{ steps.head_sha_context.outputs.context }}
141+
description: Test finished
142+
targetUrl: ""

.github/workflows/codespell.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ on: # yamllint disable-line rule:truthy
1313
permissions:
1414
contents: read
1515
pull-requests: read
16+
# This is required for the ability to create/update the Pull request status
17+
statuses: write
1618
jobs:
1719
codespell:
1820
if: |
@@ -52,23 +54,45 @@ jobs:
5254
name: Check for spelling errors
5355
runs-on: ubuntu-latest
5456
steps:
55-
- name: Get PR head SHA
57+
- name: Get PR head SHA and context
5658
if: github.event_name == 'issue_comment'
57-
id: head_sha
59+
id: head_sha_context
5860
env:
5961
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6062
REPO: ${{ github.repository }}
6163
PR_NUMBER: ${{ github.event.issue.number }}
64+
CONTEXT: "${{ github.workflow }} / Check for spelling errors (pull_request)"
6265
run: |
6366
set -euxo pipefail
6467
head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha')
6568
echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT"
69+
echo "context=$CONTEXT" >> "$GITHUB_OUTPUT"
70+
71+
- name: Set commit status as pending
72+
if: github.event_name == 'issue_comment'
73+
uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master
74+
with:
75+
sha: ${{ steps.head_sha_context.outputs.head_sha }}
76+
status: pending
77+
context: ${{ steps.head_sha_context.outputs.context }}
78+
description: Test started
79+
targetUrl: ""
6680

6781
- name: Checkout
6882
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
6983
with:
7084
persist-credentials: false
71-
ref: ${{ steps.head_sha.outputs.head_sha || github.sha }}
85+
ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }}
7286

7387
- name: Codespell
7488
uses: codespell-project/actions-codespell@8f01853be192eb0f849a5c7d721450e7a467c579 # v2.2
89+
90+
- name: Set final commit status
91+
if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != ''
92+
uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master
93+
with:
94+
sha: ${{ steps.head_sha_context.outputs.head_sha }}
95+
status: ${{ job.status }}
96+
context: ${{ steps.head_sha_context.outputs.context }}
97+
description: Test finished
98+
targetUrl: ""

.github/workflows/markdownlint.yml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ on: # yamllint disable-line rule:truthy
2222
permissions:
2323
contents: read
2424
pull-requests: read
25+
# This is required for the ability to create/update the Pull request status
26+
statuses: write
2527
jobs:
2628
markdownlint:
2729
if: |
@@ -60,29 +62,41 @@ jobs:
6062
)
6163
runs-on: ubuntu-latest
6264
steps:
63-
- name: Update pip, git
64-
run: |
65-
set -euxo pipefail
66-
sudo apt update
67-
sudo apt install -y git
68-
69-
- name: Get PR head SHA
65+
- name: Get PR head SHA and context
7066
if: github.event_name == 'issue_comment'
71-
id: head_sha
67+
id: head_sha_context
7268
env:
7369
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7470
REPO: ${{ github.repository }}
7571
PR_NUMBER: ${{ github.event.issue.number }}
72+
CONTEXT: "${{ github.workflow }} / ${{ github.job }} (pull_request)"
7673
run: |
7774
set -euxo pipefail
7875
head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha')
7976
echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT"
77+
echo "context=$CONTEXT" >> "$GITHUB_OUTPUT"
78+
79+
- name: Set commit status as pending
80+
if: github.event_name == 'issue_comment'
81+
uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master
82+
with:
83+
sha: ${{ steps.head_sha_context.outputs.head_sha }}
84+
status: pending
85+
context: ${{ steps.head_sha_context.outputs.context }}
86+
description: Test started
87+
targetUrl: ""
88+
89+
- name: Update pip, git
90+
run: |
91+
set -euxo pipefail
92+
sudo apt update
93+
sudo apt install -y git
8094
8195
- name: Check out code
8296
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
8397
with:
8498
persist-credentials: false
85-
ref: ${{ steps.head_sha.outputs.head_sha || github.sha }}
99+
ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }}
86100

87101
# CHANGELOG.md is generated automatically from PR titles and descriptions
88102
# It might have issues but they are not critical
@@ -93,3 +107,13 @@ jobs:
93107
--ignore=CHANGELOG.md
94108
**/*.md
95109
config: .markdownlint.yaml
110+
111+
- name: Set final commit status
112+
if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != ''
113+
uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master
114+
with:
115+
sha: ${{ steps.head_sha_context.outputs.head_sha }}
116+
status: ${{ job.status }}
117+
context: ${{ steps.head_sha_context.outputs.context }}
118+
description: Test finished
119+
targetUrl: ""

0 commit comments

Comments
 (0)