Skip to content

Commit 374f25d

Browse files
authored
fix(release): Git config value aquisition and dry run base branch (#100)
* fix(release): Obtain global git config values with includes * chore(release): Reduce noise by disabling debug output * chore(release): Improve output * fix(release): Use local base branch for dry-run and rename variables for correctness * chore(release): Push and set upstream for consistency across scripts * fix(nix-shell): Add python pip dependency
1 parent 7c2f13c commit 374f25d

File tree

6 files changed

+51
-34
lines changed

6 files changed

+51
-34
lines changed

release/create-release-branch.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# See README.adoc
44
#
55
set -euo pipefail
6-
set -x
6+
# set -x
77

88
BASE_BRANCH="main"
9-
REPOSITORY="origin"
9+
REMOTE="origin"
1010
#----------------------------------------------------------------------------------------------------
1111
# tags should be semver-compatible e.g. 23.1 and not 23.01
1212
# this is needed for cargo commands to work properly: although it is not strictly needed
@@ -21,10 +21,13 @@ update_products() {
2121
else
2222
git clone --branch main --depth 1 "git@github.com:stackabletech/${DOCKER_IMAGES_REPO}.git" "$BASE_DIR/$DOCKER_IMAGES_REPO"
2323
cd "$BASE_DIR/$DOCKER_IMAGES_REPO"
24-
git switch "${RELEASE_BRANCH}" || git switch -c "${RELEASE_BRANCH}" "${REPOSITORY}/${BASE_BRANCH}"
24+
git switch "${RELEASE_BRANCH}" || git switch -c "${RELEASE_BRANCH}" "${REMOTE}/${BASE_BRANCH}"
2525
fi
2626

2727
push_branch "$DOCKER_IMAGES_REPO"
28+
29+
echo
30+
echo "Check $BASE_DIR/$DOCKER_IMAGES_REPO"
2831
}
2932

3033
update_operators() {
@@ -36,7 +39,7 @@ update_operators() {
3639
else
3740
git clone --branch main --depth 1 "git@github.com:stackabletech/${operator}.git" "$BASE_DIR/${operator}"
3841
cd "$BASE_DIR/${operator}"
39-
git switch "${RELEASE_BRANCH}" || git switch -c "${RELEASE_BRANCH}" "${REPOSITORY}/${BASE_BRANCH}"
42+
git switch "${RELEASE_BRANCH}" || git switch -c "${RELEASE_BRANCH}" "${REMOTE}/${BASE_BRANCH}"
4043
fi
4144
push_branch "$operator"
4245
done < <(yq '... comments="" | .operators[] ' "$INITIAL_DIR"/release/config.yaml)
@@ -49,7 +52,7 @@ update_demos() {
4952
else
5053
git clone --branch main --depth 1 "git@github.com:stackabletech/${DEMOS_REPO}.git" "$BASE_DIR/$DEMOS_REPO"
5154
cd "$BASE_DIR/$DEMOS_REPO"
52-
git switch "${RELEASE_BRANCH}" || git switch -c "${RELEASE_BRANCH}" "${REPOSITORY}/${BASE_BRANCH}"
55+
git switch "${RELEASE_BRANCH}" || git switch -c "${RELEASE_BRANCH}" "${REMOTE}/${BASE_BRANCH}"
5356
fi
5457

5558
# Search and replace known references to stackableRelease, container images, branch references.
@@ -74,13 +77,13 @@ update_repos() {
7477
}
7578

7679
push_branch() {
77-
local REMOTE="$1";
80+
local REPOSITORY="$1";
7881
if $PUSH; then
79-
echo "Pushing to $REMOTE"
80-
git push -u "${REPOSITORY}" "${RELEASE_BRANCH}"
82+
echo "Pushing changes to $REPOSITORY"
83+
git push -u "$REMOTE" "$RELEASE_BRANCH"
8184
else
82-
echo "Dry run pushing to $REMOTE"
83-
git push --dry-run -u "${REPOSITORY}" "${RELEASE_BRANCH}"
85+
echo "Dry-run: not pushing changes to $REPOSITORY"
86+
git push --dry-run -u "$REMOTE" "$RELEASE_BRANCH"
8487
fi
8588
}
8689

release/create-release-candidate-branch.sh

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# See README.adoc
44
#
55
set -euo pipefail
6-
set -x
6+
# set -x
77

88
# tags should be semver-compatible e.g. 23.1.1 not 23.01.1
99
# this is needed for cargo commands to work properly
1010
# optional release-candidate suffixes are in the form:
1111
# - rc-1, e.g. 23.1.1-rc1, 23.12.1-rc12 etc.
1212
TAG_REGEX="^[0-9][0-9]\.([1-9]|[1][0-2])\.[0-9]+(-rc[0-9]+)?$"
13-
REPOSITORY="origin"
13+
REMOTE="origin"
1414
PR_MSG="> [!CAUTION]
1515
> ## DO NOT MERGE MANUALLY!
1616
> This branch will be merged (and the commit tagged) by stackable-utils once any necessary commits have been cherry-picked to here from the main branch."
@@ -89,6 +89,8 @@ check_tag_is_valid() {
8989
}
9090

9191
check_products() {
92+
echo "Checking products"
93+
9294
if [ ! -d "$TEMP_RELEASE_FOLDER/$DOCKER_IMAGES_REPO" ]; then
9395
echo "Cloning folder: $TEMP_RELEASE_FOLDER/$DOCKER_IMAGES_REPO"
9496
# $TEMP_RELEASE_FOLDER has already been created in main()
@@ -109,17 +111,23 @@ check_products() {
109111
# will be prepared
110112
BRANCH_EXISTS=$(git branch -a | grep -E "$PR_BRANCH$")
111113
if [ -n "${BRANCH_EXISTS}" ]; then
112-
>&2 echo "PR branch already exists: ${REPOSITORY}/$PR_BRANCH"
114+
>&2 echo "PR branch already exists: ${REMOTE}/$PR_BRANCH"
113115
exit 1
114116
fi
115117

116118
# create a new branch for the PR off of this
117-
git switch -c "${PR_BRANCH}" "${REPOSITORY}/${RELEASE_BRANCH}"
119+
local BASE_BRANCH="$RELEASE_BRANCH"
120+
if $PUSH; then
121+
BASE_BRANCH="${REMOTE}/${RELEASE_BRANCH}"
122+
fi
123+
git switch -c "$PR_BRANCH" "$BASE_BRANCH"
118124

119125
check_tag_is_valid
120126
}
121127

122128
check_operators() {
129+
echo "Checking operators"
130+
123131
while IFS="" read -r operator || [ -n "$operator" ]; do
124132
echo "Operator: $operator"
125133
if [ ! -d "$TEMP_RELEASE_FOLDER/${operator}" ]; then
@@ -144,7 +152,11 @@ check_operators() {
144152
fi
145153

146154
# create a new branch for the PR off of this
147-
git switch -c "${PR_BRANCH}" "${REPOSITORY}/${RELEASE_BRANCH}"
155+
local BASE_BRANCH="$RELEASE_BRANCH"
156+
if $PUSH; then
157+
BASE_BRANCH="${REMOTE}/${RELEASE_BRANCH}"
158+
fi
159+
git switch -c "$PR_BRANCH" "$BASE_BRANCH"
148160

149161
check_tag_is_valid
150162
done < <(yq '... comments="" | .operators[] ' "$INITIAL_DIR"/release/config.yaml)
@@ -209,11 +221,11 @@ push_branch() {
209221
if $PUSH; then
210222
echo "Pushing changes..."
211223
# the branch must be updated before the PR can be created
212-
git push "${REPOSITORY}" "${PR_BRANCH}"
224+
git push -u "$REMOTE" "$PR_BRANCH"
213225
gh pr create --reviewer stackabletech/developers --base "${RELEASE_BRANCH}" --head "${PR_BRANCH}" --title "chore: Release ${RELEASE_TAG}" --body "${PR_MSG}"
214226
else
215-
echo "(Dry-run: not pushing...)"
216-
git push --dry-run "${REPOSITORY}" "${PR_BRANCH}"
227+
echo "Dry-run: not pushing changes..."
228+
git push --dry-run -u "$REMOTE" "$PR_BRANCH"
217229
gh pr create --reviewer stackabletech/developers --dry-run --base "${RELEASE_BRANCH}" --head "${PR_BRANCH}" --title "chore: Release ${RELEASE_TAG}" --body "${PR_MSG}"
218230
fi
219231
}
@@ -280,8 +292,8 @@ parse_inputs() {
280292

281293
check_dependencies() {
282294
# check for a globally configured git user
283-
git_user=$(git config --global --get user.name)
284-
git_email=$(git config --global --get user.email)
295+
git_user=$(git config --global --includes --get user.name)
296+
git_email=$(git config --global --includes --get user.email)
285297
echo "global git user: $git_user <$git_email>"
286298

287299
if [ -z "$git_user" ] || [ -z "$git_email" ]; then
@@ -325,7 +337,7 @@ main() {
325337
fi
326338

327339
if [ ! -d "$TEMP_RELEASE_FOLDER" ]; then
328-
echo "Creating folder for cloning docker images and operators: [$TEMP_RELEASE_FOLDER]"
340+
echo "Creating folder for cloning docker images and/or operators: [$TEMP_RELEASE_FOLDER]"
329341
mkdir -p "$TEMP_RELEASE_FOLDER"
330342
fi
331343

@@ -337,7 +349,7 @@ main() {
337349
checks
338350
set -e
339351

340-
echo "Cloning docker images and operators to [$TEMP_RELEASE_FOLDER]"
352+
echo "Cloning docker-images and/or operators to [$TEMP_RELEASE_FOLDER]"
341353
rc_branch_repos
342354
cleanup
343355
}

release/merge-release-candidate.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# See README.md
44
#
55
set -euo pipefail
6-
set -x
6+
# set -x
77

88
parse_inputs() {
99
RELEASE_TAG=""
@@ -53,7 +53,7 @@ merge_operators() {
5353
gh pr review "${PR_BRANCH}" --approve -R stackabletech/"${operator}"
5454
gh pr merge "${PR_BRANCH}" --delete-branch --squash -R stackabletech/"${operator}"
5555
else
56-
echo "(Dry-run: not reviewing/merging...)"
56+
echo "Dry-run: not reviewing/merging..."
5757
fi
5858
else
5959
echo "Skipping ${operator}, PR already closed"
@@ -71,7 +71,7 @@ merge_products() {
7171
gh pr review "${PR_BRANCH}" --approve -R stackabletech/"${DOCKER_IMAGES_REPO}"
7272
gh pr merge "${PR_BRANCH}" --delete-branch --squash -R stackabletech/"${DOCKER_IMAGES_REPO}"
7373
else
74-
echo "(Dry-run: not reviewing/merging...)"
74+
echo "Dry-run: not reviewing/merging..."
7575
fi
7676
else
7777
echo "Skipping ${DOCKER_IMAGES_REPO}, PR already closed"
@@ -89,8 +89,8 @@ merge() {
8989

9090
check_dependencies() {
9191
# check for a globally configured git user
92-
git_user=$(git config --global --get user.name)
93-
git_email=$(git config --global --get user.email)
92+
git_user=$(git config --global --includes --get user.name)
93+
git_email=$(git config --global --includes --get user.email)
9494
echo "global git user: $git_user <$git_email>"
9595

9696
if [ -z "$git_user" ] || [ -z "$git_email" ]; then

release/post-release.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# See README.adoc
44
#
55
set -euo pipefail
6-
set -x
6+
# set -x
7+
78
#-----------------------------------------------------------
89
# tags should be semver-compatible e.g. 23.1.1 not 23.01.1
910
# this is needed for cargo commands to work properly
@@ -104,7 +105,7 @@ update_operators() {
104105
git push -u "${REMOTE}" "${CHANGELOG_BRANCH}"
105106
gh pr create --reviewer stackabletech/developers --base main --head "${CHANGELOG_BRANCH}" --title "chore: Update changelog from release ${RELEASE_TAG}" --body "${PR_MSG}"
106107
else
107-
echo "(Dry-run: not pushing...)"
108+
echo "Dry-run: not pushing..."
108109
git push --dry-run "${REMOTE}" "${CHANGELOG_BRANCH}"
109110
gh pr create --reviewer stackabletech/developers --dry-run --base main --head "${CHANGELOG_BRANCH}" --title "chore: Update changelog from release ${RELEASE_TAG}" --body "${PR_MSG}"
110111
fi
@@ -165,7 +166,7 @@ update_products() {
165166
git push -u "${REMOTE}" "${CHANGELOG_BRANCH}"
166167
gh pr create --reviewer stackabletech/developers --base main --head "${CHANGELOG_BRANCH}" --title "chore: Update changelog from release ${RELEASE_TAG}" --body "${PR_MSG}"
167168
else
168-
echo "(Dry-run: not pushing...)"
169+
echo "Dry-run: not pushing..."
169170
git push --dry-run "${REMOTE}" "${CHANGELOG_BRANCH}"
170171
gh pr create --reviewer stackabletech/developers --dry-run --base main --head "${CHANGELOG_BRANCH}" --title "chore: Update changelog from release ${RELEASE_TAG}" --body "${PR_MSG}"
171172
fi

release/tag-release-candidate.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# See README.adoc
44
#
55
set -euo pipefail
6-
set -x
6+
# set -x
77

88
# tags should be semver-compatible e.g. 23.1.1 not 23.01.1
99
# this is needed for cargo commands to work properly
@@ -104,7 +104,7 @@ push_branch() {
104104
echo "Pushing changes..."
105105
git push "${REPOSITORY}" "${RELEASE_TAG}"
106106
else
107-
echo "(Dry-run: not pushing...)"
107+
echo "Dry-run: not pushing..."
108108
git push --dry-run "${REPOSITORY}" "${RELEASE_TAG}"
109109
fi
110110
}
@@ -158,8 +158,8 @@ parse_inputs() {
158158

159159
check_dependencies() {
160160
# check for a globally configured git user
161-
git_user=$(git config --global --get user.name)
162-
git_email=$(git config --global --get user.email)
161+
git_user=$(git config --global --includes --get user.name)
162+
git_email=$(git config --global --includes --get user.email)
163163
echo "global git user: $git_user <$git_email>"
164164

165165
if [ -z "$git_user" ] || [ -z "$git_email" ]; then

shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ pkgs.mkShell {
66
gh
77
jinja2-cli
88
yq-go
9+
python311Packages.pip
910
];
1011
}

0 commit comments

Comments
 (0)