Repository navigation
feat: implement issue #447 — Compliance: unpinned-actions-shell-tests.yml #455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ] | ||
| } | ||
|
|
||
| @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 ] | ||
| } | ||
|
don-petry marked this conversation as resolved.
Resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.