Created
May 30, 2025 18:25
-
-
Save rtyley/f59bf2df4907a925727c5015cad9cc87 to your computer and use it in GitHub Desktop.
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 | |
| update_repo() { | |
| GU_REPO=$1 | |
| API_PATH="/repos/guardian/$GU_REPO/contents/.github/workflows/release.yml" | |
| release_yml_api_data=$( gh api "$API_PATH" ) | |
| release_yml_old_sha=$( echo "$release_yml_api_data" | jq -r .sha ) | |
| release_yml_old_content=$( echo "$release_yml_api_data" | jq -r .content | base64 --decode ) | |
| release_yml_new_content=${release_yml_old_content//reusable-release.yml@main/reusable-release.yml@v1} | |
| if [ "$release_yml_old_content" = "$release_yml_new_content" ]; then | |
| echo "No change: $GU_REPO" | |
| else | |
| message="Explicitly use version v1 of gha-scala-library-release-workflow" | |
| release_yml_new_content_base64=$(echo "$release_yml_new_content" | base64) | |
| echo "Updating $GU_REPO ..." | |
| if gh api --silent --method PUT "$API_PATH" --field message="$message" --field sha="$release_yml_old_sha" \ | |
| --field content="$release_yml_new_content_base64"; then | |
| echo "...updated $GU_REPO" | |
| else | |
| echo "Failed to update $GU_REPO directly, will have to use PR..." | |
| default_branch=$( gh api /repos/guardian/etag-caching --jq .default_branch ) | |
| PR_BRANCH="switch-release-yml-to-v1" | |
| head_commit=$( gh api "/repos/guardian/$GU_REPO/commits/$default_branch" --jq .sha ) | |
| gh api --silent --method POST "/repos/guardian/$GU_REPO/git/refs" --field ref="refs/heads/$PR_BRANCH" --field sha="$head_commit" | |
| sleep 2 | |
| gh api --method PUT "$API_PATH" --field message="$message" --field sha="$release_yml_old_sha" \ | |
| --field content="$release_yml_new_content_base64" --field branch="$PR_BRANCH" | |
| sleep 2 | |
| gh api --silent --method POST "/repos/guardian/$GU_REPO/pulls" -f "head=$PR_BRANCH" -f "base=$default_branch" -f "title=$message" -f "body=See https://github.com/guardian/gha-scala-library-release-workflow/pull/61" | |
| fi | |
| fi | |
| } | |
| while read -r GU_REPO; do | |
| update_repo "$GU_REPO" | |
| done < "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment