diff --git a/.github/scripts/apply-code-quality-ruleset.sh b/.github/scripts/apply-code-quality-ruleset.sh old mode 100644 new mode 100755 index 1342265a..1e1dd419 --- a/.github/scripts/apply-code-quality-ruleset.sh +++ b/.github/scripts/apply-code-quality-ruleset.sh @@ -4,10 +4,12 @@ # This script creates (or updates) the `code-quality` repository ruleset that # enforces required status checks on the default branch of petry-projects/markets. # -# Required status checks configured (derived from actual CI check run names): -# - SonarCloud sonarcloud.yml, job: sonarcloud (name: SonarCloud) -# - Analyze (actions) codeql.yml, job: analyze (name: Analyze), language: actions -# - dev-lead / dispatch dev-lead.yml, caller job: dev-lead, reusable job: dispatch +# Required status checks configured (codified standard, source of truth: +# petry-projects/.github/standards/rulesets/code-quality.json — see #326): +# - CodeQL CodeQL default setup analysis +# - SonarCloud sonarcloud.yml, job: sonarcloud (name: SonarCloud) +# - agent-shield / AgentShield agent-shield.yml, caller job: agent-shield, reusable job: AgentShield +# - dependency-audit / Detect ecosystems dependency-audit.yml, caller job: dependency-audit, reusable job: Detect ecosystems # # Standard reference: # https://github.com/petry-projects/.github/blob/main/standards/github-settings.md#code-quality--required-checks-ruleset-all-repositories @@ -51,9 +53,10 @@ PAYLOAD=$(jq -n '{ parameters: { strict_required_status_checks_policy: true, required_status_checks: [ + {context: "CodeQL"}, {context: "SonarCloud"}, - {context: "Analyze (actions)"}, - {context: "dev-lead / dispatch"} + {context: "agent-shield / AgentShield"}, + {context: "dependency-audit / Detect ecosystems"} ] } } diff --git a/.github/scripts/tests/apply-code-quality-ruleset.bats b/.github/scripts/tests/apply-code-quality-ruleset.bats new file mode 100644 index 00000000..b6836b93 --- /dev/null +++ b/.github/scripts/tests/apply-code-quality-ruleset.bats @@ -0,0 +1,46 @@ +#!/usr/bin/env bats +# Tests for apply-code-quality-ruleset.sh — static content assertions, no live API calls. +# +# The required status check contexts asserted below are the codified standard +# (petry-projects/.github/standards/rulesets/code-quality.json), the source of +# truth referenced by issue #326. + +SCRIPT="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)/apply-code-quality-ruleset.sh" + +assert_required_check() { + local context="$1" + grep -qE "context:\s*\"$context\"" "$SCRIPT" +} + +@test "script exists and is executable" { + [ -f "$SCRIPT" ] + [ -x "$SCRIPT" ] +} + +@test "script uses set -euo pipefail" { + grep -q 'set -euo pipefail' "$SCRIPT" +} + +@test "script targets petry-projects/markets repo" { + grep -q 'petry-projects/markets' "$SCRIPT" +} + +@test "script declares the code-quality ruleset" { + grep -q 'name: "code-quality"' "$SCRIPT" +} + +@test "script requires the CodeQL status check" { + assert_required_check "CodeQL" +} + +@test "script requires the SonarCloud status check" { + assert_required_check "SonarCloud" +} + +@test "script requires the agent-shield / AgentShield status check" { + assert_required_check "agent-shield / AgentShield" +} + +@test "script requires the dependency-audit / Detect ecosystems status check" { + assert_required_check "dependency-audit / Detect ecosystems" +} diff --git a/.github/scripts/tests/pr-review-mention-workflow.bats b/.github/scripts/tests/pr-review-mention-workflow.bats index 767dc005..6af9315d 100755 --- a/.github/scripts/tests/pr-review-mention-workflow.bats +++ b/.github/scripts/tests/pr-review-mention-workflow.bats @@ -28,10 +28,10 @@ WORKFLOW="$(cd "$(dirname "$BATS_TEST_FILENAME")/../../.." && pwd)/.github/workf [[ "$output" == *"Bot"* ]] } -@test "uses: ref stays pinned to the pr-review-mention/stable channel" { +@test "uses: ref stays pinned to the pr-review-mention/v2-stable channel" { run yq '.jobs.pr-review-mention.uses' "$WORKFLOW" [ "$status" -eq 0 ] - [[ "$output" == *"@pr-review-mention/stable" ]] + [[ "$output" == *"@pr-review-mention/v2-stable" ]] } @test "trigger events are unchanged" { diff --git a/.github/workflows/pr-review-mention.yml b/.github/workflows/pr-review-mention.yml index bc5f9747..52b6da49 100644 --- a/.github/workflows/pr-review-mention.yml +++ b/.github/workflows/pr-review-mention.yml @@ -7,7 +7,7 @@ # • This file is a THIN CALLER STUB. All review-dispatch logic lives in the # reusable workflow above. # • You MUST NOT change: the `uses:` ref — it is pinned to the -# `pr-review-mention/stable` channel, a moving tag advanced centrally. +# `pr-review-mention/v2-stable` channel, a moving tag advanced centrally. # Never repoint it to `@main`, a SHA, or a frozen `@vX` (see # ci-standards.md → Reusable workflow versioning). Also do not change the # trigger events or the job-level `permissions:` block — reusable workflows @@ -35,6 +35,18 @@ permissions: {} jobs: pr-review-mention: + # Skip events whose sender is a Bot (e.g. the Copilot coding agent), marking + # the job skipped (= success) and preventing an unnecessary reusable workflow + # invocation. The mention / review-request flow is human-driven, so a bot + # sender never carries a legitimate review request. + # Limitation: this job-level guard cannot prevent a workflow-level + # `action_required` state — GitHub enforces that approval gate before any + # `if:` condition is evaluated (see issue #307 for context). For bots that + # trigger the repo's first-time-contributor approval requirement the proper + # mitigation is to allowlist the bot account in Settings → Actions → + # "Fork pull request workflows from outside collaborators". + # `github.event.sender` is populated on all three trigger events. + if: github.event.sender.type != 'Bot' permissions: pull-requests: write uses: petry-projects/.github/.github/workflows/pr-review-mention-reusable.yml@pr-review-mention/v2-stable # NOSONAR(githubactions:S7637) first-party channel ref