Skip to content

Commit 7b7b28e

Browse files
committed
Fix support for non-master default pack branches
If any packs end up using `main` instead of `master` as their default branch, then deploying the index will fail without this change. Currently only the `test` and `test2` packs use an non-master default branch (`aaa`). So, the impact of this change is minimal.
1 parent c938ff4 commit 7b7b28e

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

.circle/deployment

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ fi
2121
# TODO: remove the install_gh call once circleci config is updated in all packs
2222
type gh &>/dev/null || ~/ci/.circle/install_gh
2323

24+
# GH_TOKEN is used by gh which is used in functions.sh
25+
export GH_TOKEN=${MACHINE_PASSWORD}
26+
source ~/ci/tools/functions.sh
27+
2428
# TODO: figure out how to make deploy.py rebuild the index.
2529
# python ~/packs/.circle/deploy.py pack.yaml "${CIRCLE_PROJECT_REPONAME}"
2630

@@ -54,10 +58,11 @@ do
5458
fi
5559
done
5660

61+
DEFAULT_BRANCH=$(_gh_default_branch)
5762
# Afer pushing the version, make sure we check out the latest commit
5863
# This is important so index reflects latest changes
59-
git checkout master
60-
git reset --hard master
64+
git checkout ${DEFAULT_BRANCH}
65+
git reset --hard ${DEFAULT_BRANCH}
6166

6267
# Verify there are no unstaged changes
6368
git status

tools/functions.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#### gh helpers
2+
3+
_gh_default_branch() {
4+
# get the default branch for the current repo (might not be master)
5+
6+
gh api graphql -F owner=':owner' -F name=':repo' -f query='
7+
query($name: String!, $owner: String!) {
8+
repository(owner: $owner, name: $name) {
9+
defaultBranchRef { name }
10+
}
11+
}
12+
' | jq -r '.data.repository.defaultBranchRef.name'
13+
}

0 commit comments

Comments
 (0)