Skip to content

Commit 50bdd7e

Browse files
authored
Merge pull request #108 from cognifloyd/default-branch-not-master
[BUGFIX] Fix support for non-master default branch in packs
2 parents c938ff4 + cc7882a commit 50bdd7e

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

.circle/deployment

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ 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+
28+
DEFAULT_BRANCH=$(_gh_default_branch)
29+
# Give a good error message after the first use of github API in this script.
30+
if [[ $? != 0 ]]; then
31+
echo "Error retrieving data with github graphql API."
32+
echo "The GitHub PAT might need to be regenerated:"
33+
echo "https://github.com/settings/tokens/new?scopes=public_repo&description=CircleCI%3A%20stackstorm-${PACK_NAME}"
34+
else
35+
echo "GitHub PAT is active."
36+
fi
37+
2438
# TODO: figure out how to make deploy.py rebuild the index.
2539
# python ~/packs/.circle/deploy.py pack.yaml "${CIRCLE_PROJECT_REPONAME}"
2640

@@ -56,8 +70,8 @@ done
5670

5771
# Afer pushing the version, make sure we check out the latest commit
5872
# This is important so index reflects latest changes
59-
git checkout master
60-
git reset --hard master
73+
git checkout ${DEFAULT_BRANCH}
74+
git reset --hard ${DEFAULT_BRANCH}
6175

6276
# Verify there are no unstaged changes
6377
git status
@@ -96,8 +110,15 @@ if ! git -C ~/index diff --quiet --exit-code --cached
96110
then
97111
echo "Updating the index repo..."
98112
git -C ~/index commit -m "Update the ${PACK_NAME} pack."
99-
git -C ~/index push -q origin
100-
echo "Index updated."
113+
if [[ ${DO_NOT_ADD_TO_EXCHANGE_INDEX:-false} == "true" ]]; then
114+
echo "Normal packs update the Exchange index at this point."
115+
echo "This pack will not be added to the Exchange index because of this env var:"
116+
echo "DO_NOT_ADD_TO_EXCHANGE_INDEX=${DO_NOT_ADD_TO_EXCHANGE_INDEX}"
117+
echo "(This var should only be set per-repo in the CI system's UI.)"
118+
else
119+
git -C ~/index push -q origin
120+
echo "Index updated."
121+
fi
101122

102123
# echo "Updating the repo description..."
103124
# PACK_DESCRIPTION=$(cat ~/index/v1/index.json | jq ".packs.${PACK_NAME}.description")

.circle/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def get_available_versions():
155155
if proc.returncode != 0:
156156
sys.exit(
157157
"Error retrieving data with github graphql API.\n"
158-
"The Github PAT might need to be regenerated:\n"
158+
"The GitHub PAT might need to be regenerated:\n"
159159
"https://github.com/settings/tokens/new?scopes=public_repo"
160160
"&description=CircleCI%3A%20stackstorm-" + ACTIVE_PACK_NAME
161161
)

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)