Skip to content

Commit e7efeb3

Browse files
authored
Automate releases (#507)
<!-- Thank you for contributing! Please make sure that your code changes are covered with tests. In case of new features or big changes remember to adjust the documentation. In case of an existing issue, reference it using one of the following: closes: #ISSUE related: #ISSUE How to write a good git commit message: http://chris.beams.io/posts/git-commit/ --> ## What *Describe what the change is solving* Configure Helm chart releasing for ngrok/helm-charts repo Add release.sh automation ## How *Describe the solution* Update the github workflows Add new script `release.sh` * create new release branch from main * discover PRs since last release * insert/update/edit the changelogs * commit and review changes ## Breaking Changes *Are there any breaking changes in this PR?* No.
2 parents d3feb24 + a22153a commit e7efeb3

File tree

4 files changed

+234
-0
lines changed

4 files changed

+234
-0
lines changed

.github/workflows/helm_release.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,6 @@ jobs:
6767
CR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6868
CR_RELEASE_NAME_TEMPLATE: "helm-chart-{{ .Version }}" # Publishes a new release. Ex: helm-chart-0.1.0
6969
CR_SKIP_EXISTING: "true"
70+
CR_GIT_REPO: "helm-charts" # https://github.com/ngrok/helm-charts
7071
with:
7172
charts_dir: helm

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ VERSION = $(shell cat VERSION)
2525

2626
# Tools
2727

28+
SCRIPT_DIR = ./scripts
29+
2830
HELM_CHART_DIR = ./helm/ngrok-operator
2931
HELM_TEMPLATES_DIR = $(HELM_CHART_DIR)/templates
3032

@@ -130,6 +132,10 @@ KUBE_NAMESPACE ?= ngrok-operator
130132
HELM_RELEASE_NAME ?= ngrok-operator
131133
KUBE_DEPLOYMENT_NAME ?= ngrok-operator-manager
132134

135+
.PHONY: release
136+
release:
137+
$(SCRIPT_DIR)/release.sh
138+
133139
.PHONY: deploy
134140
deploy: _deploy-check-env-vars docker-build manifests kustomize _helm_setup ## Deploy controller to the K8s cluster specified in ~/.kube/config.
135141
helm upgrade $(HELM_RELEASE_NAME) $(HELM_CHART_DIR) --install \

docs/developer-guide/releasing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
# Release Steps
1313

14+
tl;dr Run: `$ make release`
15+
16+
## Manual Steps
17+
1418
Overview:
1519
1. Create a new branch like `release-ngrok-operator-<version>`
1620
1. Update versions and changelogs

scripts/release.sh

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
#!/usr/bin/env bash
2+
3+
set -eou pipefail
4+
5+
# This script releases a new version of the ngrok-operator app and Helm chart
6+
7+
## Guards
8+
9+
# git tree must be clean
10+
if `git status --porcelain | grep -q .`; then
11+
echo "ERROR: Working directory is not clean. Please commit all changes before releasing."
12+
exit 1
13+
fi
14+
15+
## Helpers
16+
17+
color_echo () {
18+
local n_flag=""
19+
if [[ "$1" == "-n" ]]
20+
then
21+
n_flag="-n"
22+
shift
23+
fi
24+
is_stderr=false
25+
case $1 in
26+
(red) color="1;31"
27+
is_stderr=true ;;
28+
(green) color="1;32" ;;
29+
(yellow) color="1;33" ;;
30+
(blue) color="1;34" ;;
31+
(purple) color="1;35" ;;
32+
(cyan) color="1;36" ;;
33+
(white) color="0" ;;
34+
(*) color=$1 ;;
35+
esac
36+
shift
37+
if [[ $is_stderr == true ]]
38+
then
39+
echo -e $n_flag "\033[${color}m$@\033[0m" >&2
40+
else
41+
echo -e $n_flag "\033[${color}m$@\033[0m"
42+
fi
43+
}
44+
45+
## Main
46+
47+
# collect current versions
48+
curr_app_version=$(cat VERSION)
49+
curr_chart_version=$(cat helm/ngrok-operator/Chart.yaml | yq '.version' -r)
50+
51+
# print version info
52+
color_echo green "== Current Release Info:"
53+
color_echo green "== App Version: $curr_app_version"
54+
color_echo green "== Chart Version: $curr_chart_version"
55+
color_echo green "" # formatting
56+
57+
# prompt for next versions
58+
read -p "Supply next ngrok-operator-<version> (current: $curr_app_version): " next_app_version
59+
read -p "Supply next Helm chart <version> (current: $curr_chart_version): " next_chart_version
60+
echo "" # formatting
61+
62+
# use defaults if no new version supplied
63+
next_app_version=${next_app_version:-$curr_app_version}
64+
next_chart_version=${next_chart_version:-$curr_chart_version}
65+
66+
# create git branch
67+
echo "Creating release branch..."
68+
git fetch origin main
69+
git checkout -b release-ngrok-operator-$next_app_version-helm-chart-$next_chart_version origin/main
70+
echo "" # formatting
71+
72+
# update the version files
73+
echo $next_app_version > VERSION
74+
yq -Y -i ".version = \"$next_chart_version\"" helm/ngrok-operator/Chart.yaml
75+
yq -Y -i ".appVersion = \"$next_app_version\"" helm/ngrok-operator/Chart.yaml
76+
77+
# update the Helm snapshots
78+
echo "Updating Helm snapshots..."
79+
make helm-update-snapshots helm-test
80+
echo "" # formatting
81+
82+
# find and echo the PRs between $from..$to
83+
function gather_prs () {
84+
from=$1
85+
to=$2
86+
87+
if ! `git tag -l | grep -q $from` ; then
88+
color_echo red "ERROR: Tag $from not found" >&2
89+
exit 1
90+
fi
91+
92+
# format: <commit-sha> <commit-msg> ()<pr-number>)
93+
git log --pretty=format:"%h %s" --merges --grep="Merge pull request" $1..$2 \
94+
| while read line ; do
95+
commit_sha=$(echo $line | awk '{print $1}') # first field
96+
commit_msg=$(echo $line | awk '{$1=$NF=""; print }' | sed 's/^\ *//') # 2nd through 2nd-to-last fields, trim leading whitespace
97+
pr_number=$(echo $line | awk '{print $NF}' | tr -d '()#') # last field, remove parens and hash
98+
echo "- $commit_msg by @<gh-user> <$(git show -s --format='%an' $commit_sha)> in [#${pr_number}](https://github.com/ngrok/ngrok-operator/pull/${pr_number})"
99+
done
100+
}
101+
102+
curr_version_tag="ngrok-operator-$curr_app_version"
103+
prs_since_last_release=$(gather_prs $curr_version_tag HEAD)
104+
105+
# adds a templated changelog entry to the changelog_path
106+
function add_changelog_entry() {
107+
changelog_path=$1
108+
tag=$2
109+
from_version=$3
110+
to_version=$4
111+
112+
# template for new changelog entry
113+
# Intentionally not indented
114+
changelog_next_version=$(cat <<EOF
115+
## $to_version
116+
**Full Changelog**: https://github.com/ngrok/ngrok-operator/compare/$tag-$from_version...$tag-$to_version
117+
118+
<!-- remove empty sections -->
119+
<!-- PRs since last release: -->
120+
$prs_since_last_release
121+
122+
### Added
123+
124+
- Add some example feature by @<user> in [#PR](https://github.com/ngrok/ngrok-operator/pull/0000)
125+
126+
### Changed
127+
128+
- Bump image version to \`$to_version\`
129+
- Update some feature by @<user> in [#PR](https://github.com/ngrok/ngrok-operator/pull/0000)
130+
131+
### Fixed
132+
133+
- Fixed some feature by @<user> in [#PR](https://github.com/ngrok/ngrok-operator/pull/0000)
134+
135+
### Removed
136+
137+
- Removed some feature by @<user> in [#PR](https://github.com/ngrok/ngrok-operator/pull/0000)
138+
139+
EOF
140+
)
141+
142+
inserted=false
143+
cat $changelog_path | while read ; do
144+
line="$REPLY"
145+
if ! $inserted && grep -q "^## $from_version\$" <<< $line ; then
146+
inserted=true
147+
echo "$changelog_next_version" >> $changelog_path.new
148+
echo "" >> $changelog_path.new # formatting
149+
echo "$line" >> $changelog_path.new
150+
else
151+
echo "$line" >> $changelog_path.new
152+
fi
153+
done
154+
155+
mv -f $changelog_path.new $changelog_path
156+
}
157+
158+
color_echo green "" # formatting
159+
color_echo green "PRs since last release:"
160+
if [ -z "$prs_since_last_release" ]; then
161+
color_echo yellow "No PRs found since last release"
162+
color_echo yellow "Are you sure you want to make a release?"
163+
read -p "Press Enter to continue..."
164+
else
165+
color_echo green "$prs_since_last_release"
166+
fi
167+
color_echo green "" # formatting
168+
169+
# prompt to update the app CHANGELOG
170+
app_changelog_path=CHANGELOG.md
171+
if `grep -q "^## $next_app_version\$" $app_changelog_path` ; then
172+
color_echo yellow "WARN: App $app_changelog_path already contains an entry for version $next_app_version"
173+
echo "Skipping $app_changelog_path update..."
174+
else
175+
echo -n "Please update the App"
176+
color_echo -n yellow " $app_changelog_path "
177+
echo -n "with the changes for next version"
178+
color_echo -n green " $next_app_version "
179+
echo "" # formatting
180+
echo "Save and close the file when complete"
181+
read -p "Press Enter to continue..."
182+
183+
# add new changelog entry and open the file for editing
184+
add_changelog_entry $app_changelog_path ngrok-operator $curr_app_version $next_app_version
185+
$EDITOR $app_changelog_path
186+
fi
187+
echo "" # formatting
188+
echo "" # formatting
189+
190+
# prompt to update the chart CHANGELOG
191+
chart_changelog_path=helm/ngrok-operator/CHANGELOG.md
192+
if `grep -q "^## $next_chart_version\$" $chart_changelog_path` ; then
193+
color_echo yellow "WARN: Helm Chart $chart_changelog_path already contains an entry for version $next_chart_version"
194+
echo "Skipping $chart_changelog_path update..."
195+
else
196+
echo -n "Please update the Helm Chart"
197+
color_echo -n yellow " $chart_changelog_path "
198+
echo -n "with the changes for next version"
199+
color_echo -n green " $next_chart_version "
200+
echo "" # formatting
201+
echo "Save and close the file when complete"
202+
read -p "Press Enter to continue..."
203+
204+
# add new changelog entry and open the file for editing
205+
add_changelog_entry $chart_changelog_path helm-chart $curr_chart_version $next_chart_version
206+
$EDITOR $chart_changelog_path
207+
fi
208+
echo "" # formatting
209+
echo "" # formatting
210+
211+
# files are updated, commit and share diff
212+
echo "Committing changes..."
213+
git add VERSION helm/ngrok-operator/Chart.yaml $app_changelog_path $chart_changelog_path
214+
git commit -m "Release ngrok-operator-$next_app_version helm-chart-$next_chart_version"
215+
echo "" # formatting
216+
echo "Please review the changes, then push the commit"
217+
read -p "Press Enter to continue..."
218+
echo "" # formatting
219+
git show -p HEAD
220+
echo "" # formatting
221+
222+
color_echo green "Done! Please push the changes and open a PR to merge the release."
223+
exit 0

0 commit comments

Comments
 (0)