From bbd1a19ad6edfaae303a0e5fa588fc8d3a810b9d Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Thu, 3 Sep 2026 16:02:31 -0600 Subject: [PATCH] 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. Also create a variable for context so it is created in one place and used in several places in the workflow. Signed-off-by: Rich Megginson --- .github/workflows/ansible-lint.yml | 42 ++++++++++++++---- .../workflows/ansible-managed-var-comment.yml | 44 ++++++++++++++----- .github/workflows/ansible-test.yml | 44 ++++++++++++++----- .github/workflows/codespell.yml | 30 +++++++++++-- .github/workflows/markdownlint.yml | 30 +++++++++++-- .../workflows/qemu-kvm-integration-tests.yml | 33 +++++++++++--- .github/workflows/test_converting_readme.yml | 31 +++++++++++-- .github/workflows/woke.yml | 30 +++++++++++-- 8 files changed, 238 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ansible-lint.yml b/.github/workflows/ansible-lint.yml index 1120b1e..0d8dc9f 100644 --- a/.github/workflows/ansible-lint.yml +++ b/.github/workflows/ansible-lint.yml @@ -24,6 +24,8 @@ env: permissions: contents: read pull-requests: read + # This is required for the ability to create/update the Pull request status + statuses: write jobs: ansible_lint: if: | @@ -71,29 +73,41 @@ jobs: - { ansible_lint: "24.*", ansible: "2.16.*", python: "3.12" } - { ansible_lint: "26.*", ansible: "2.20.*", python: "3.13" } steps: - - name: Update pip, git - run: | - set -euxo pipefail - sudo apt update - sudo apt install -y git - - - name: Get PR head SHA + - name: Get PR head SHA and context if: github.event_name == 'issue_comment' - id: head_sha + id: head_sha_context env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} PR_NUMBER: ${{ github.event.issue.number }} + CONTEXT: "${{ github.workflow }} / ${{ github.job }} (${{ matrix.versions.ansible_lint }}, ${{ matrix.versions.ansible }}, ${{ matrix.versions.python }}) (pull_request)" run: | set -euxo pipefail head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + echo "context=$CONTEXT" >> "$GITHUB_OUTPUT" + + - name: Set commit status as pending + if: github.event_name == 'issue_comment' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: pending + context: ${{ steps.head_sha_context.outputs.context }} + description: Test started + targetUrl: "" + + - name: Update pip, git + run: | + set -euxo pipefail + sudo apt update + sudo apt install -y git - name: Checkout repo uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false - ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} + ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }} - name: Install tox, tox-lsr run: | @@ -115,3 +129,13 @@ jobs: LSR_ANSIBLE_LINT_ANSIBLE_DEP="ansible-core==${{ matrix.versions.ansible }}" \ tox -x testenv:ansible-lint-collection.basepython="python${{ matrix.versions.python }}" \ -e ansible-lint-collection + + - name: Set final commit status + if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != '' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: ${{ job.status }} + context: ${{ steps.head_sha_context.outputs.context }} + description: Test finished + targetUrl: "" diff --git a/.github/workflows/ansible-managed-var-comment.yml b/.github/workflows/ansible-managed-var-comment.yml index d5fefbe..c4e2f04 100644 --- a/.github/workflows/ansible-managed-var-comment.yml +++ b/.github/workflows/ansible-managed-var-comment.yml @@ -21,6 +21,8 @@ on: # yamllint disable-line rule:truthy permissions: contents: read pull-requests: read + # This is required for the ability to create/update the Pull request status + statuses: write jobs: ansible_managed_var_comment: if: | @@ -59,30 +61,42 @@ jobs: ) runs-on: ubuntu-latest steps: - - name: Update pip, git - run: | - set -euxo pipefail - python3 -m pip install --upgrade pip - sudo apt update - sudo apt install -y git - - - name: Get PR head SHA + - name: Get PR head SHA and context if: github.event_name == 'issue_comment' - id: head_sha + id: head_sha_context env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} PR_NUMBER: ${{ github.event.issue.number }} + CONTEXT: "${{ github.workflow }} / ${{ github.job }} (pull_request)" run: | set -euxo pipefail head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + echo "context=$CONTEXT" >> "$GITHUB_OUTPUT" + + - name: Set commit status as pending + if: github.event_name == 'issue_comment' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: pending + context: ${{ steps.head_sha_context.outputs.context }} + description: Test started + targetUrl: "" + + - name: Update pip, git + run: | + set -euxo pipefail + python3 -m pip install --upgrade pip + sudo apt update + sudo apt install -y git - name: Checkout repo uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false - ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} + ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }} - name: Install tox, tox-lsr run: | @@ -93,3 +107,13 @@ jobs: run: | set -euxo pipefail TOXENV=ansible-managed-var-comment lsr_ci_runtox + + - name: Set final commit status + if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != '' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: ${{ job.status }} + context: ${{ steps.head_sha_context.outputs.context }} + description: Test finished + targetUrl: "" diff --git a/.github/workflows/ansible-test.yml b/.github/workflows/ansible-test.yml index 47b4ac6..cefb144 100644 --- a/.github/workflows/ansible-test.yml +++ b/.github/workflows/ansible-test.yml @@ -24,6 +24,8 @@ env: permissions: contents: read pull-requests: read + # This is required for the ability to create/update the Pull request status + statuses: write jobs: ansible_test: if: | @@ -73,30 +75,42 @@ jobs: - { ansible: "2-20", python: "3.13" } - { ansible: "milestone", python: "3.13" } steps: - - name: Update pip, git - run: | - set -euxo pipefail - python3 -m pip install --upgrade pip - sudo apt update - sudo apt install -y git - - - name: Get PR head SHA + - name: Get PR head SHA and context if: github.event_name == 'issue_comment' - id: head_sha + id: head_sha_context env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} PR_NUMBER: ${{ github.event.issue.number }} + CONTEXT: "${{ github.workflow }} / ${{ github.job }} (${{ matrix.versions.ansible }}, ${{ matrix.versions.python }}) (pull_request)" run: | set -euxo pipefail head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + echo "context=$CONTEXT" >> "$GITHUB_OUTPUT" + + - name: Set commit status as pending + if: github.event_name == 'issue_comment' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: pending + context: ${{ steps.head_sha_context.outputs.context }} + description: Test started + targetUrl: "" + + - name: Update pip, git + run: | + set -euxo pipefail + python3 -m pip install --upgrade pip + sudo apt update + sudo apt install -y git - name: Checkout repo uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false - ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} + ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }} - name: Install tox, tox-lsr run: | @@ -116,3 +130,13 @@ jobs: tox \ -x testenv:ansible-test-${{ matrix.versions.ansible }}.basepython="python${{ matrix.versions.python }}" \ -e ansible-test-${{ matrix.versions.ansible }} + + - name: Set final commit status + if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != '' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: ${{ job.status }} + context: ${{ steps.head_sha_context.outputs.context }} + description: Test finished + targetUrl: "" diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index 30c9f42..e5496e5 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -13,6 +13,8 @@ on: # yamllint disable-line rule:truthy permissions: contents: read pull-requests: read + # This is required for the ability to create/update the Pull request status + statuses: write jobs: codespell: if: | @@ -52,23 +54,45 @@ jobs: name: Check for spelling errors runs-on: ubuntu-latest steps: - - name: Get PR head SHA + - name: Get PR head SHA and context if: github.event_name == 'issue_comment' - id: head_sha + id: head_sha_context env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} PR_NUMBER: ${{ github.event.issue.number }} + CONTEXT: "${{ github.workflow }} / Check for spelling errors (pull_request)" run: | set -euxo pipefail head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + echo "context=$CONTEXT" >> "$GITHUB_OUTPUT" - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false - ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} + ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }} + + - name: Set commit status as pending + if: github.event_name == 'issue_comment' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: pending + context: ${{ steps.head_sha_context.outputs.context }} + description: Test started + targetUrl: "" - name: Codespell uses: codespell-project/actions-codespell@8f01853be192eb0f849a5c7d721450e7a467c579 # v2.2 + + - name: Set final commit status + if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != '' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: ${{ job.status }} + context: ${{ steps.head_sha_context.outputs.context }} + description: Test finished + targetUrl: "" diff --git a/.github/workflows/markdownlint.yml b/.github/workflows/markdownlint.yml index 5dbcdc2..b6306f2 100644 --- a/.github/workflows/markdownlint.yml +++ b/.github/workflows/markdownlint.yml @@ -22,6 +22,8 @@ on: # yamllint disable-line rule:truthy permissions: contents: read pull-requests: read + # This is required for the ability to create/update the Pull request status + statuses: write jobs: markdownlint: if: | @@ -66,23 +68,35 @@ jobs: sudo apt update sudo apt install -y git - - name: Get PR head SHA + - name: Get PR head SHA and context if: github.event_name == 'issue_comment' - id: head_sha + id: head_sha_context env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} PR_NUMBER: ${{ github.event.issue.number }} + CONTEXT: "${{ github.workflow }} / ${{ github.job }} (pull_request)" run: | set -euxo pipefail head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + echo "context=$CONTEXT" >> "$GITHUB_OUTPUT" - name: Check out code uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false - ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} + ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }} + + - name: Set commit status as pending + if: github.event_name == 'issue_comment' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: pending + context: ${{ steps.head_sha_context.outputs.context }} + description: Test started + targetUrl: "" # CHANGELOG.md is generated automatically from PR titles and descriptions # It might have issues but they are not critical @@ -93,3 +107,13 @@ jobs: --ignore=CHANGELOG.md **/*.md config: .markdownlint.yaml + + - name: Set final commit status + if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != '' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: ${{ job.status }} + context: ${{ steps.head_sha_context.outputs.context }} + description: Test finished + targetUrl: "" diff --git a/.github/workflows/qemu-kvm-integration-tests.yml b/.github/workflows/qemu-kvm-integration-tests.yml index e724eda..87a1dc1 100644 --- a/.github/workflows/qemu-kvm-integration-tests.yml +++ b/.github/workflows/qemu-kvm-integration-tests.yml @@ -90,23 +90,25 @@ jobs: ANSIBLE_INJECT_FACT_VARS: "false" steps: - - name: Get PR head SHA + - name: Get PR head SHA and context if: github.event_name == 'issue_comment' - id: head_sha + id: head_sha_context env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} PR_NUMBER: ${{ github.event.issue.number }} + CONTEXT: "${{ github.workflow }} / scenario (${{ matrix.scenario.image }}, ${{ matrix.scenario.env }}) (pull_request)" run: | set -euxo pipefail head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + echo "context=$CONTEXT" >> "$GITHUB_OUTPUT" - name: Checkout repo uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false - ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} + ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }} - name: Check if platform is supported id: check_platform @@ -144,6 +146,16 @@ jobs: echo "supported=$supported" >> "$GITHUB_OUTPUT" + - name: Set commit status as pending + if: github.event_name == 'issue_comment' && steps.check_platform.outputs.supported + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: pending + context: ${{ steps.head_sha_context.outputs.context }} + description: Test started + targetUrl: "" + - name: Set up /dev/kvm if: steps.check_platform.outputs.supported run: | @@ -290,11 +302,22 @@ jobs: done "${cmdline[@]}" + - name: Set final commit status + if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != '' && (steps.check_platform.outputs.supported || failure()) + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: ${{ job.status }} + context: ${{ steps.head_sha_context.outputs.context }} + description: Test finished + targetUrl: "" + - name: Set commit status as success with a description that platform is skipped - if: ${{ steps.check_platform.outputs.supported == '' }} + if: ${{ success() && github.event_name == 'issue_comment' && steps.check_platform.outputs.supported == '' }} uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} status: success - context: "${{ github.workflow }} / scenario (${{ matrix.scenario.image }}, ${{ matrix.scenario.env }}) (pull_request)" + context: ${{ steps.head_sha_context.outputs.context }} description: The role does not support this platform. Skipping. targetUrl: "" diff --git a/.github/workflows/test_converting_readme.yml b/.github/workflows/test_converting_readme.yml index 187bd6f..ec4ee62 100644 --- a/.github/workflows/test_converting_readme.yml +++ b/.github/workflows/test_converting_readme.yml @@ -21,6 +21,8 @@ on: # yamllint disable-line rule:truthy permissions: contents: read pull-requests: read + # This is required for the ability to create/update the Pull request status + statuses: write jobs: test_converting_readme: if: | @@ -61,6 +63,7 @@ jobs: permissions: pull-requests: read contents: write + statuses: write steps: - name: Update pip, git run: | @@ -68,23 +71,35 @@ jobs: sudo apt update sudo apt install -y git - - name: Get PR head SHA + - name: Get PR head SHA and context if: github.event_name == 'issue_comment' - id: head_sha + id: head_sha_context env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} PR_NUMBER: ${{ github.event.issue.number }} + CONTEXT: "${{ github.workflow }} / ${{ github.job }} (pull_request)" run: | set -euxo pipefail head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + echo "context=$CONTEXT" >> "$GITHUB_OUTPUT" - name: Check out code uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false - ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} + ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }} + + - name: Set commit status as pending + if: github.event_name == 'issue_comment' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: pending + context: ${{ steps.head_sha_context.outputs.context }} + description: Test started + targetUrl: "" - name: Remove badges from README.md prior to converting to HTML run: sed -i '1,8 {/^\[\!.*actions\/workflows/d}' README.md @@ -102,3 +117,13 @@ jobs: with: name: README.html path: README.html + + - name: Set final commit status + if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != '' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: ${{ job.status }} + context: ${{ steps.head_sha_context.outputs.context }} + description: Test finished + targetUrl: "" diff --git a/.github/workflows/woke.yml b/.github/workflows/woke.yml index 4219efa..3b52dd6 100644 --- a/.github/workflows/woke.yml +++ b/.github/workflows/woke.yml @@ -13,6 +13,8 @@ on: # yamllint disable-line rule:truthy permissions: contents: read pull-requests: read + # This is required for the ability to create/update the Pull request status + statuses: write jobs: woke: if: | @@ -52,23 +54,35 @@ jobs: name: Detect non-inclusive language runs-on: ubuntu-latest steps: - - name: Get PR head SHA + - name: Get PR head SHA and context if: github.event_name == 'issue_comment' - id: head_sha + id: head_sha_context env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} PR_NUMBER: ${{ github.event.issue.number }} + CONTEXT: "${{ github.workflow }} / Detect non-inclusive language (pull_request)" run: | set -euxo pipefail head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + echo "context=$CONTEXT" >> "$GITHUB_OUTPUT" - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false - ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} + ref: ${{ steps.head_sha_context.outputs.head_sha || github.sha }} + + - name: Set commit status as pending + if: github.event_name == 'issue_comment' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: pending + context: ${{ steps.head_sha_context.outputs.context }} + description: Test started + targetUrl: "" - name: Run lsr-woke-action # Originally, uses: get-woke/woke-action@v0 @@ -77,3 +91,13 @@ jobs: woke-args: "-c https://raw.githubusercontent.com/linux-system-roles/tox-lsr/main/src/tox_lsr/config_files/woke.yml --count-only-error-for-failure" # Cause the check to fail on any broke rules fail-on-error: true + + - name: Set final commit status + if: always() && github.event_name == 'issue_comment' && steps.head_sha_context.outputs.head_sha != '' + uses: myrotvorets/set-commit-status-action@c0f880c99d91381c6fdb97726f03feb8004409b4 # master + with: + sha: ${{ steps.head_sha_context.outputs.head_sha }} + status: ${{ job.status }} + context: ${{ steps.head_sha_context.outputs.context }} + description: Test finished + targetUrl: ""