Skip to content

Commit 41d3ef9

Browse files
chore: Extend post-release script to update docker-images Changelog (#92)
* chore: Extend post-release script to update docker-images Changelog * chore: explicitly sign commits * Apply suggestions from code review Co-authored-by: Sebastian Bernauer <sebastian.bernauer@stackable.de> --------- Co-authored-by: Sebastian Bernauer <sebastian.bernauer@stackable.de>
1 parent 202438c commit 41d3ef9

File tree

2 files changed

+106
-28
lines changed

2 files changed

+106
-28
lines changed

release/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,17 @@ e.g.
166166
Some post release steps are performed with `release/post-release.sh` script, called from the repository root folder. The syntax is given below:
167167

168168
```
169-
./release/post-release.sh -t <release-tag> [-p]
169+
./release/post-release.sh -t <release-tag> [-p] [-w products|operators|all]
170170
```
171171

172172
- `-t <release-tag>`: the release tag (mandatory). This must be a semver-compatible value (i.e. major/minor/path, without leading zeros) such as `23.1.0`, `23.10.3` etc. and will be used to create a tag with the name
173173
- `-p`: push flag (optional, default is "false"). If provided, the created commits and tags made as part of this process will be pushed to the origin.
174+
- `-w`: which repositories to update the changelogs for. It can be "products", "operators", "all" (defaults to "all").
174175

175176
##### What this script does
176177

177-
- checks that the release tag exists and that the all operator repositories have a clean working copy
178+
- checks that the release tag exists and that all operator repositories have a clean working copy
179+
- checks that the release tag exists and that the docker-images repository has a clean working copy
178180
- merges the CHANGELOG.md from the release tag into main
179181
- creates PRs for all operators
180182

release/post-release.sh

Lines changed: 102 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ set -x
99
# this is needed for cargo commands to work properly
1010
#-----------------------------------------------------------
1111
TAG_REGEX="^[0-9][0-9]\.([1-9]|[1][0-2])\.[0-9]+$"
12-
REPOSITORY="origin"
12+
REMOTE="origin"
1313

1414
parse_inputs() {
1515
RELEASE_TAG=""
1616
PUSH=false
17+
WHAT="all"
1718

1819
while [[ "$#" -gt 0 ]]; do
1920
case $1 in
2021
-t|--tag) RELEASE_TAG="$2"; shift ;;
22+
-w|--what) WHAT="$2"; shift ;;
2123
-p|--push) PUSH=true ;;
2224
*) echo "Unknown parameter passed: $1"; exit 1 ;;
2325
esac
@@ -35,45 +37,50 @@ parse_inputs() {
3537
RELEASE_BRANCH="release-$RELEASE"
3638

3739
INITIAL_DIR="$PWD"
40+
DOCKER_IMAGES_REPO=$(yq '... comments="" | .images-repo ' "$INITIAL_DIR"/release/config.yaml)
3841
TEMP_RELEASE_FOLDER="/tmp/stackable-$RELEASE_BRANCH"
3942

40-
echo "Settings: ${RELEASE_BRANCH}: Push: $PUSH"
43+
echo "Settings: $RELEASE_BRANCH: Push: $PUSH"
4144
}
4245

46+
# Check that the operator repos have been cloned locally, and that the release
47+
# branch and tag exists.
4348
check_operators() {
44-
while IFS="" read -r operator || [ -n "$operator" ]
49+
while IFS="" read -r OPERATOR || [ -n "$OPERATOR" ]
4550
do
46-
echo "Operator: $operator"
47-
if [ ! -d "$TEMP_RELEASE_FOLDER/${operator}" ]; then
48-
echo "Expected folder is missing: $TEMP_RELEASE_FOLDER/${operator}"
51+
echo "Operator: $OPERATOR"
52+
if [ ! -d "$TEMP_RELEASE_FOLDER/$OPERATOR" ]; then
53+
echo "Expected folder is missing: $TEMP_RELEASE_FOLDER/$OPERATOR"
4954
exit 1
5055
fi
5156

52-
cd "$TEMP_RELEASE_FOLDER/${operator}"
57+
cd "$TEMP_RELEASE_FOLDER/$OPERATOR"
5358

5459
DIRTY_WORKING_COPY=$(git status --short)
55-
if [ -n "${DIRTY_WORKING_COPY}" ]; then
56-
echo "Dirty working copy found for operator ${operator}"
60+
if [ -n "$DIRTY_WORKING_COPY" ]; then
61+
echo "Dirty working copy found for operator $OPERATOR"
5762
exit 1
5863
fi
5964
BRANCH_EXISTS=$(git branch | grep "$RELEASE_BRANCH")
60-
if [ -z "${BRANCH_EXISTS}" ]; then
61-
echo "Expected release branch is missing: ${operator}/$RELEASE_BRANCH"
65+
if [ -z "$BRANCH_EXISTS" ]; then
66+
echo "Expected release branch is missing: $OPERATOR/$RELEASE_BRANCH"
6267
exit 1
6368
fi
6469
git fetch --tags
6570
TAG_EXISTS=$(git tag | grep "$RELEASE_TAG")
66-
if [ -z "${TAG_EXISTS}" ]; then
67-
echo "Expected tag $RELEASE_TAG missing for operator ${operator}"
71+
if [ -z "$TAG_EXISTS" ]; then
72+
echo "Expected tag $RELEASE_TAG missing for operator $OPERATOR"
6873
exit 1
6974
fi
7075
done < <(yq '... comments="" | .operators[] ' "$INITIAL_DIR"/release/config.yaml)
7176
}
7277

73-
update_main_changelog() {
74-
while IFS="" read -r operator || [ -n "$operator" ]
78+
# Update the operator changelogs on main, and check they do not differ from
79+
# the changelog in the release branch.
80+
update_operators() {
81+
while IFS="" read -r OPERATOR || [ -n "$OPERATOR" ]
7582
do
76-
cd "$TEMP_RELEASE_FOLDER/${operator}"
83+
cd "$TEMP_RELEASE_FOLDER/$OPERATOR"
7784
# New branch that updates the CHANGELOG
7885
CHANGELOG_BRANCH="update-changelog-from-release-$RELEASE_TAG"
7986
# Branch out from main
@@ -84,20 +91,76 @@ update_main_changelog() {
8491
# are no conflicts.
8592
CHANGELOG_MODIFIED=$(git status --short)
8693
if [ "M CHANGELOG.md" != "$CHANGELOG_MODIFIED" ]; then
87-
echo "Failed to update CHANGELOG.md in main for operator ${operator}"
94+
echo "Failed to update CHANGELOG.md in main for operator $OPERATOR"
8895
exit 1
8996
fi
9097
# Commit the updated CHANGELOG.
9198
git add CHANGELOG.md
92-
git commit -m "Update CHANGELOG.md from release $RELEASE_TAG"
99+
git commit -sm "Update CHANGELOG.md from release $RELEASE_TAG"
93100
# Maybe push and create pull request
94101
if "$PUSH"; then
95-
git push -u "$REPOSITORY" "$CHANGELOG_BRANCH"
102+
git push -u "$REMOTE" "$CHANGELOG_BRANCH"
96103
gh pr create --fill --reviewer stackable/developers --head "$CHANGELOG_BRANCH" --base main
97104
fi
98105
done < <(yq '... comments="" | .operators[] ' "$INITIAL_DIR"/release/config.yaml)
99106
}
100107

108+
# Check that the docker-images repo has been cloned locally, and that the release
109+
# branch and tag exists.
110+
check_docker_images() {
111+
echo "docker-images"
112+
if [ ! -d "$TEMP_RELEASE_FOLDER/$DOCKER_IMAGES_REPO" ]; then
113+
echo "Expected folder is missing: $TEMP_RELEASE_FOLDER/$DOCKER_IMAGES_REPO"
114+
exit 1
115+
fi
116+
117+
cd "$TEMP_RELEASE_FOLDER/$DOCKER_IMAGES_REPO"
118+
119+
DIRTY_WORKING_COPY=$(git status --short)
120+
if [ -n "${DIRTY_WORKING_COPY}" ]; then
121+
echo "Dirty working copy found for $DOCKER_IMAGES_REPO"
122+
exit 1
123+
fi
124+
BRANCH_EXISTS=$(git branch | grep "$RELEASE_BRANCH")
125+
if [ -z "${BRANCH_EXISTS}" ]; then
126+
echo "Expected release branch is missing: $DOCKER_IMAGES_REPO/$RELEASE_BRANCH"
127+
exit 1
128+
fi
129+
git fetch --tags
130+
TAG_EXISTS=$(git tag | grep "$RELEASE_TAG")
131+
if [ -z "${TAG_EXISTS}" ]; then
132+
echo "Expected tag $RELEASE_TAG missing for $DOCKER_IMAGES_REPO"
133+
exit 1
134+
fi
135+
}
136+
137+
# Update the docker-images changelogs on main, and check they do not differ from
138+
# the changelog in the release branch.
139+
update_docker_images() {
140+
cd "$TEMP_RELEASE_FOLDER/$DOCKER_IMAGES_REPO"
141+
# New branch that updates the CHANGELOG
142+
CHANGELOG_BRANCH="update-changelog-from-release-$RELEASE_TAG"
143+
# Branch out from main
144+
git switch -c "$CHANGELOG_BRANCH" main
145+
# Checkout CHANGELOG changes from the release tag
146+
git checkout "$RELEASE_TAG" -- CHANGELOG.md
147+
# Ensure only the CHANGELOG has been modified and there
148+
# are no conflicts.
149+
CHANGELOG_MODIFIED=$(git status --short)
150+
if [ "M CHANGELOG.md" != "$CHANGELOG_MODIFIED" ]; then
151+
echo "Failed to update CHANGELOG.md in main for $DOCKER_IMAGES_REPO"
152+
exit 1
153+
fi
154+
# Commit the updated CHANGELOG.
155+
git add CHANGELOG.md
156+
git commit -sm "Update CHANGELOG.md from release $RELEASE_TAG"
157+
# Maybe push and create pull request
158+
if "$PUSH"; then
159+
git push -u "$REMOTE" "$CHANGELOG_BRANCH"
160+
gh pr create --fill --reviewer stackable/developers --head "$CHANGELOG_BRANCH" --base main
161+
fi
162+
}
163+
101164

102165
main() {
103166
parse_inputs "$@"
@@ -118,14 +181,27 @@ main() {
118181
exit 1
119182
fi
120183

121-
# sanity checks before we start: folder, branches etc.
122-
# deactivate -e so that piped commands can be used
123-
set +e
124-
check_operators
125-
set -e
184+
if [ "products" == "$WHAT" ] || [ "all" == "$WHAT" ]; then
185+
# sanity checks before we start: folder, branches etc.
186+
# deactivate -e so that piped commands can be used
187+
set +e
188+
check_docker_images
189+
set -e
190+
191+
echo "Update $DOCKER_IMAGES_REPO main changelog for release $RELEASE_TAG"
192+
update_docker_images
193+
fi
194+
if [ "operators" == "$WHAT" ] || [ "all" == "$WHAT" ]; then
195+
# sanity checks before we start: folder, branches etc.
196+
# deactivate -e so that piped commands can be used
197+
set +e
198+
check_operators
199+
set -e
200+
201+
echo "Update the operator main changelog for release $RELEASE_TAG"
202+
update_operators
203+
fi
126204

127-
echo "Update main changelog from release $RELEASE_TAG"
128-
update_main_changelog
129205
}
130206

131207
main "$@"

0 commit comments

Comments
 (0)