From 201b40ab39c4a2d9ff99b1ad49be1b3e73ee38e8 Mon Sep 17 00:00:00 2001 From: sophlanz Date: Thu, 17 Oct 2024 12:07:57 -0400 Subject: [PATCH 1/2] replace master references with default branch name fetched from github api --- circleci/breakdown-sync | 8 +++++++- circleci/catalog-sync | 7 ++++++- circleci/output-force-deploy | 6 ++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/circleci/breakdown-sync b/circleci/breakdown-sync index 5dd97d8..f8caf5e 100755 --- a/circleci/breakdown-sync +++ b/circleci/breakdown-sync @@ -11,7 +11,13 @@ set -e : ${CIRCLE_BRANCH?"Missing required env var"} BRANCH=$CIRCLE_BRANCH -if [[ $BRANCH != "master" ]]; then +: ${CIRCLE_PROJECT_REPONAME?"Missing required env var"} +REPO=$CIRCLE_PROJECT_REPONAME + +DEFAULT_BRANCH=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/Clever/$REPO" | jq -r '.default_branch') + +if [[ $BRANCH != $DEFAULT_BRANCH ]]; then echo "Skipping sync for non-master branch" exit 0 fi diff --git a/circleci/catalog-sync b/circleci/catalog-sync index 0f5aa56..f7a86f9 100755 --- a/circleci/catalog-sync +++ b/circleci/catalog-sync @@ -12,7 +12,12 @@ set -e : ${CIRCLE_BRANCH?"Missing required env var"} BRANCH=$CIRCLE_BRANCH -if [[ $BRANCH != "master" ]]; then +: ${CIRCLE_PROJECT_REPONAME?"Missing required env var"} +REPO=$CIRCLE_PROJECT_REPONAME + +DEFAULT_BRANCH=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/Clever/$REPO" | jq -r '.default_branch') +if [[ $BRANCH != $DEFAULT_BRANCH ]]; then echo "Skipping sync for non-master branch" exit 0 fi diff --git a/circleci/output-force-deploy b/circleci/output-force-deploy index a90778d..7de05f5 100755 --- a/circleci/output-force-deploy +++ b/circleci/output-force-deploy @@ -5,7 +5,9 @@ REPO=$CIRCLE_PROJECT_REPONAME : ${CIRCLE_PROJECT_USERNAME?"Missing required env var"} USER=$CIRCLE_PROJECT_USERNAME - +: ${GITHUB_TOKEN?"Missing required env var"} +DEFAULT_BRANCH=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/Clever/$REPO" | jq -r '.default_branch') echo "frontend-test failed! As a result, your deploy will not start automatically." echo "If you think this is a transient issue, try re-running this job with the \"Rerun from failed\" option." echo "To force deploy, do the following:" @@ -14,7 +16,7 @@ echo "2) Run the following command, replacing CIRCLE_API_TOKEN with the token fr echo "curl -u CIRCLE_API_TOKEN: \\ -X POST \\ --header \"Content-Type: application/json\" -d '{ - \"branch\": \"master\", + \"branch\": \"${DEFAULT_BRANCH}\", \"parameters\": { \"force_deploy\": true } From 28288f0f9a53d97ff18e558ff50fb5cf031155ea Mon Sep 17 00:00:00 2001 From: sophlanz Date: Thu, 17 Oct 2024 13:47:22 -0400 Subject: [PATCH 2/2] add checks for github token --- circleci/breakdown-sync | 2 +- circleci/catalog-sync | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/circleci/breakdown-sync b/circleci/breakdown-sync index f8caf5e..b7f916a 100755 --- a/circleci/breakdown-sync +++ b/circleci/breakdown-sync @@ -13,7 +13,7 @@ set -e BRANCH=$CIRCLE_BRANCH : ${CIRCLE_PROJECT_REPONAME?"Missing required env var"} REPO=$CIRCLE_PROJECT_REPONAME - +: ${GITHUB_TOKEN?"Missing required env var"} DEFAULT_BRANCH=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ "https://api.github.com/repos/Clever/$REPO" | jq -r '.default_branch') diff --git a/circleci/catalog-sync b/circleci/catalog-sync index f7a86f9..826e3c4 100755 --- a/circleci/catalog-sync +++ b/circleci/catalog-sync @@ -14,7 +14,7 @@ set -e BRANCH=$CIRCLE_BRANCH : ${CIRCLE_PROJECT_REPONAME?"Missing required env var"} REPO=$CIRCLE_PROJECT_REPONAME - +: ${GITHUB_TOKEN?"Missing required env var"} DEFAULT_BRANCH=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ "https://api.github.com/repos/Clever/$REPO" | jq -r '.default_branch') if [[ $BRANCH != $DEFAULT_BRANCH ]]; then