Skip to content

Instantly share code, notes, and snippets.

@michelesr
Last active April 9, 2026 22:41
Show Gist options
  • Select an option

  • Save michelesr/6b239deac5edcbf7c870e9354509ac49 to your computer and use it in GitHub Desktop.

Select an option

Save michelesr/6b239deac5edcbf7c870e9354509ac49 to your computer and use it in GitHub Desktop.
Pins github actions references to hardcoded hashes
#!/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