Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/scripts/apply-code-quality-ruleset.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"}
]
Comment thread
don-petry marked this conversation as resolved.
Resolved
}
}
Expand Down
46 changes: 46 additions & 0 deletions .github/scripts/tests/apply-code-quality-ruleset.bats
Original file line number Diff line number Diff line change
@@ -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"
}
Comment thread
don-petry marked this conversation as resolved.
Resolved
Comment thread
don-petry marked this conversation as resolved.
Resolved
4 changes: 2 additions & 2 deletions .github/scripts/tests/pr-review-mention-workflow.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/pr-review-mention.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading