Skip to content

CI: fail incomplete action pin validation - #1953

Open
mattjohnsonpint wants to merge 1 commit into
stretchr:masterfrom
mattjohnsonpint:mjp/ci-ghactions-validation
Open

mattjohnsonpint wants to merge 1 commit into
stretchr:masterfrom
mattjohnsonpint:mjp/ci-ghactions-validation

Conversation

@mattjohnsonpint

Copy link
Copy Markdown
Contributor

Summary

Ensure the GitHub Actions pin validation check fails when validation cannot be completed successfully.

Changes

Update .ci.ghactions.sh:

  • Keep the validation loop in the current shell with Bash lastpipe.
  • Require successful GitHub API requests with curl --fail.
  • Use jq -e to validate the returned commit SHA without eval.

Motivation

The validation loop previously ran in a pipeline subshell, so setting its failure status did not affect the script’s exit status. Empty or invalid GitHub API responses could also produce an empty eval command that succeeded. Together, these issues allowed action pin validation to report success without validating every pin.

The validation loop runs in a pipeline subshell, so pin mismatches do not affect the final status. Enable lastpipe so status updates remain in the current shell.

Empty or invalid GitHub API responses also produce an empty eval command that succeeds. Require successful curl and jq validation instead.
Comment thread .ci.ghactions.sh
Comment on lines +47 to +48
if curl --fail --silent --show-error -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$action/commits/$tag" | jq -e --arg hash "$hash" '.sha == $hash' >/dev/null

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative would be to avoid the GitHub API and jq by checking the remote tag with Git directly.

Suggested change
if curl --fail --silent --show-error -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$action/commits/$tag" | jq -e --arg hash "$hash" '.sha == $hash' >/dev/null
if git ls-remote --exit-code "https://github.com/$action.git" \
"refs/tags/$tag" "refs/tags/$tag^{}" |
grep -q "^$hash[[:space:]]"

Let me know which approach you prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants