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
5 changes: 3 additions & 2 deletions .github/scripts/tests/apply-code-quality-ruleset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ assert_required_check() {
# bypass while de-duplicating the pre-existing OrganizationAdmin (the removal
# branch of the merge), so the result is exactly the two required actors.
@test "update adds the dependabot bypass when an existing ruleset has OrganizationAdmin but is missing it" {
export GH_TOKEN="mock-token"
gh() {
if [ "$1" = "api" ]; then
if [ "$2" = "repos/petry-projects/markets/rulesets" ]; then
Expand All @@ -110,7 +111,7 @@ assert_required_check() {
echo '[{"actor_type":"OrganizationAdmin","bypass_mode":"always"}]'
return 0
elif [ "$2" = "-X" ] && [ "$3" = "PUT" ]; then
cat > "$TEST_TMPDIR/payload.json"
cat > "$BATS_TEST_TMPDIR/payload.json"
echo '{}'
return 0
fi
Expand All @@ -122,5 +123,5 @@ assert_required_check() {
run bash "$SCRIPT"
[ "$status" -eq 0 ]

jq -e '.bypass_actors == [{"actor_type":"OrganizationAdmin","bypass_mode":"always"},{"actor_id":3167543,"actor_type":"Integration","bypass_mode":"always"}]' "$TEST_TMPDIR/payload.json"
jq -e '.bypass_actors == [{"actor_type":"OrganizationAdmin","bypass_mode":"always"},{"actor_id":3167543,"actor_type":"Integration","bypass_mode":"always"}]' "$BATS_TEST_TMPDIR/payload.json"
}
50 changes: 50 additions & 0 deletions .github/scripts/tests/shell-tests-workflow.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bats
# Tests for .github/workflows/shell-tests.yml — static YAML assertions,
# no live API calls.
#
# Regression guard for issue #447 (unpinned-actions-shell-tests.yml): the
# action-pinning standard requires every third-party action `uses:` ref to be
# pinned to a full commit SHA, not a moving `@vN` tag. shell-tests.yml checked
# out with `actions/checkout@v7`. These tests pin that the checkout step stays
# on a 40-char commit SHA so a future edit reverting to a floating tag is caught.

WORKFLOW="$(cd "$(dirname "$BATS_TEST_FILENAME")/../../.." && pwd)/.github/workflows/shell-tests.yml"

@test "workflow file exists" {
[ -f "$WORKFLOW" ]
}

@test "workflow is valid YAML" {
yq '.' "$WORKFLOW" >/dev/null
}

@test "every action uses: ref is pinned to a full commit SHA (issue #447)" {
# Every third-party `uses` — step-level and job-level reusable-workflow refs —
# must be owner/repo@<40-hex-sha>; a floating @vN tag fails this. Local actions
# (starting with `./`) need no SHA pin and are skipped. Failures are accumulated
# so a later valid ref can't mask an earlier invalid one.
run yq -r '.jobs[] | ( (.steps[]? | select(has("uses")) | .uses) , (select(has("uses")) | .uses) )' "$WORKFLOW"
[ "$status" -eq 0 ]
[ -n "$output" ]
local failed=0
while IFS= read -r ref; do
[ -n "$ref" ] || continue
[[ "$ref" =~ ^\./ ]] && continue
[[ "$ref" =~ @[0-9a-f]{40}$ ]] || failed=1
done <<< "$output"
[ "$failed" -eq 0 ]
}
Comment thread
don-petry marked this conversation as resolved.
Resolved

@test "checkout step is pinned to a SHA, not a moving tag (issue #447)" {
# Validate every matching checkout step so multiple checkouts can't let one
# unpinned ref slip through; accumulate failures across all output lines.
run yq -r '.jobs.bats.steps[] | select((.uses // "") | test("^actions/checkout@")) | .uses' "$WORKFLOW"
[ "$status" -eq 0 ]
[ -n "$output" ]
local failed=0
while IFS= read -r ref; do
[ -n "$ref" ] || continue
[[ "$ref" =~ ^actions/checkout@[0-9a-f]{40}$ ]] || failed=1
done <<< "$output"
[ "$failed" -eq 0 ]
}
Comment thread
don-petry marked this conversation as resolved.
Resolved
4 changes: 3 additions & 1 deletion .github/workflows/shell-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ jobs:
permissions:
contents: read
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
with:
persist-credentials: false

- name: Install bats
run: sudo npm install -g bats@1.11.1 --ignore-scripts
Expand Down
Loading