Last active
April 9, 2026 22:41
-
-
Save michelesr/6b239deac5edcbf7c870e9354509ac49 to your computer and use it in GitHub Desktop.
Pins github actions references to hardcoded hashes
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
| #!/usr/bin/env bash | |
| # a cache to keep already discovered refs | |
| declare -A refs | |
| for action in $(rg --no-filename 'uses: ' .github/workflows action.y*ml | sed -e '/^$/d' -e '/\.\//d' -e 's/.*uses: //'); do | |
| repo=$(awk <<<"${action}" -F@ '{print $1}') | |
| ref=$(awk <<<"${action}" -F@ '{print $2}') | |
| if [[ ${refs["${action}"]} != "" ]]; then | |
| continue | |
| fi | |
| # get the new ref from github | |
| dst_ref=$(gh api repos/${repo}/commits/${ref} --template '{{.sha}}') | |
| refs["${action}"]="$dst_ref" | |
| done | |
| for action in ${!refs[@]}; do | |
| repo=$(awk <<<"${action}" -F@ '{print $1}') | |
| src_ref=$(awk <<<"${action}" -F@ '{print $2}') | |
| dst_ref="${refs["${action}"]}" | |
| find .github/workflows -iname '*.yml' -o -iname '*.yaml' | xargs sed -i "s!${action}!${repo}@${dst_ref}!" action.y*ml | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment