Skip to content

Commit 516c2d6

Browse files
committed
Fix release cloudbuild config
Cloudbuild creates a very minimal git repo -- the checkout doesn't have tags, branches, or other commits. Previously, we were grabbing other tags and branches, but weren't correcting which branch we were on, which was confusing the new release notes tooling. Now, we load all branches & tags, create local branches for all remote release branches, point the current release branch at the given tag just to be safe, then delete the current tag. We re-add the current tag once the release notes tooling has done its thing.
1 parent 503ba3b commit 516c2d6

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

build/build_kubebuilder.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,21 @@ if [ -z "$SNAPSHOT" ]; then
8181
tmp_notes="$(mktemp)"
8282
trap "rm -f ${tmp_notes}" EXIT
8383
install_notes
84+
if [[ -n "${CLOUD_BUILD}" ]]; then
85+
# we refresh just before this, no point (plus, we fiddle with the current branch a bit)
86+
NOTES_FLAGS+=" --use-upstream=false"
87+
# we can look for tag alpha/beta here too
88+
# (TODO(directxman12): this should be in the tool)
89+
[[ "${TAG_NAME}" == "v"*"-alpha."* ]] && NOTES_FLAGS+=" -r alpha"
90+
[[ "${TAG_NAME}" == "v"*"-beta."* ]] && NOTES_FLAGS+=" -r beta"
91+
[[ "${TAG_NAME}" == "v"*"-rc."* ]] && NOTES_FLAGS+=" -r rc"
92+
fi
8493
notes $NOTES_FLAGS | tee "$tmp_notes"
94+
# we need to delete the tag for the release notes script, so restore it when done so that
95+
# go releaser can find the right tag
96+
if [[ -n "${TAG_NAME}" ]]; then
97+
git tag ${TAG_NAME}
98+
fi
8599
GORELEASER_FLAGS="${GORELEASER_FLAGS} --release-notes=${tmp_notes}"
86100
else
87101
# TODO(estroz): figure out how to generate snapshot release notes with the kubebuilder generator.

build/cloudbuild.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,31 @@
2020

2121
steps:
2222
- name: "gcr.io/cloud-builders/git"
23-
args: ["fetch", "--tags", "--unshallow"]
23+
entrypoint: 'bash'
24+
args:
25+
- '-c'
26+
- |
27+
git fetch --tags --unshallow
28+
git for-each-ref --contains HEAD
29+
# TAG_NAME is defined by GCB, so uses 1 dollar sign, BRANCH_NAME is bash, so we need to escape it
30+
# with two dollar signs
31+
export BRANCH_NAME=$(git for-each-ref --format="%(refname:strip=-1)" --contains HEAD 'refs/remotes/origin/release-*')
32+
export ALL_BRANCHES=$(git for-each-ref --format="%(refname:strip=-1)" 'refs/remotes/origin/release-*')
33+
echo "branch: $${BRANCH_NAME}, tag: ${TAG_NAME}, all release branches: $${ALL_BRANCHES}"
34+
for branch in $${ALL_BRANCHES}; do
35+
git branch $${branch} origin/$${branch}
36+
done
37+
git branch -f $${BRANCH_NAME} HEAD
38+
git checkout $${BRANCH_NAME}
39+
git branch --set-upstream-to=origin/$${BRANCH_NAME}
40+
git tag -d ${TAG_NAME}
2441
- name: "goreleaser/goreleaser:v0.147"
2542
entrypoint: "bash"
2643
args: ["build/build_kubebuilder.sh"]
2744
secretEnv: ["GITHUB_TOKEN"]
45+
env:
46+
- 'TAG_NAME=$TAG_NAME'
47+
- 'CLOUD_BUILD=true'
2848
secrets:
2949
- kmsKeyName: projects/kubebuilder/locations/global/keyRings/kubebuilder-gh-tokens/cryptoKeys/gh-release-token
3050
secretEnv:

0 commit comments

Comments
 (0)