Skip to content

Commit 5eac71b

Browse files
Add version check for charts when there are changes (#108)
* Enable validation on the Postgres chart * Add version check for charts when there are changes
1 parent d4114d4 commit 5eac71b

File tree

2 files changed

+58
-14
lines changed

2 files changed

+58
-14
lines changed

.circleci/config.yml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,25 @@ executors:
1717
password: $DOCKER_HUB_PASSWORD
1818

1919
commands:
20-
notify_failing_main:
20+
notify_failing_branch:
2121
steps:
2222
- slack/notify:
2323
channel: server-alerts
24-
branch_pattern: main
24+
branch_pattern: main, server-[0-9]\.[0-9]+
2525
event: fail
2626
template: basic_fail_1
2727
set_up_container:
2828
description: "Set up a container build environment"
2929
steps:
3030
- setup_remote_docker
3131
- checkout
32+
install_packagecloud_cli:
33+
steps:
34+
- run:
35+
name: Install package_cloud
36+
command: |
37+
sudo apt-get update && sudo apt-get install ruby-rubygems -y
38+
sudo gem install --no-document package_cloud
3239
3340
jobs:
3441
# Images
@@ -116,7 +123,7 @@ jobs:
116123
- run:
117124
command: ./do kubeconform
118125
when: always
119-
- notify_failing_main
126+
- notify_failing_branch
120127
package-charts:
121128
executor: deploy
122129
steps:
@@ -144,7 +151,14 @@ jobs:
144151
- persist_to_workspace:
145152
root: .
146153
paths: [./target]
147-
- notify_failing_main
154+
- notify_failing_branch
155+
check-version-bump:
156+
executor: deploy
157+
steps:
158+
- checkout
159+
- run:
160+
name: Check if charts changed and version is bumped accordingly
161+
command: ./do check-version-bump
148162
publish-chart:
149163
executor: deploy
150164
parameters:
@@ -156,17 +170,14 @@ jobs:
156170
- checkout
157171
- attach_workspace:
158172
at: .
159-
- run:
160-
name: Install package_cloud
161-
command: |
162-
sudo apt-get update && sudo apt-get install ruby-rubygems -y
163-
sudo gem install --no-document package_cloud
173+
- install_packagecloud_cli
164174
- run:
165175
name: Publish Helm chart
166176
command: |
167177
package_cloud push circleci/<< parameters.repo >>/helm/v1 \
168178
./target/<< parameters.chart_name >>*.tgz
169-
- notify_failing_main
179+
- notify_failing_branch
180+
170181

171182
workflows:
172183
my-workflow:
@@ -231,9 +242,10 @@ workflows:
231242

232243
# Chart jobs
233244
- validate-charts
245+
- check-version-bump
234246
- package-charts:
235247
context: releng-signing
236-
requires: [validate-charts]
248+
requires: [validate-charts, check-version-bump]
237249
# Mongo chart
238250
- approve-publish-mongo-chart:
239251
type: approval

do

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ kubeconform() {
1111

1212
for chart_dir in ./helm/*/; do
1313
if [[ -f "$chart_dir/Chart.yaml" ]]; then
14-
# TODO: Skip postgresql chart - failing validation
15-
if [[ "$chart_dir" == *"postgresql"* || "$chart_dir" == *"common"* ]]; then
16-
echo "Skipping chart: $chart_dir (TODO: fix validation issues)"
14+
if [[ "$chart_dir" == *"common"* ]]; then
1715
continue
1816
fi
1917

@@ -87,6 +85,40 @@ package-all-charts() {
8785
done
8886
}
8987

88+
# This variable is used, but shellcheck can't tell.
89+
# shellcheck disable=SC2034
90+
help_check_version_bump="Check if charts changed and version is bumped accordingly"
91+
check-version-bump() {
92+
for chart_yaml in ./helm/*/Chart.yaml; do
93+
if [[ -f "${chart_yaml}" ]]; then
94+
chart_dir=$(dirname "${chart_yaml}" | sed 's|^\./||')
95+
96+
if git diff --name-only HEAD~1 HEAD | grep -q "^${chart_dir}/"; then
97+
version=$(grep '^version:' "${chart_yaml}" | awk '{print $2}' | tr -d '"')
98+
name=$(grep '^name:' "${chart_yaml}" | awk '{print $2}' | tr -d '"')
99+
100+
case "${name}" in
101+
mongodb) repo="server-mongo" ;;
102+
postgresql) repo="server-postgres" ;;
103+
rabbitmq) repo="server-rabbitmq" ;;
104+
redis) repo="server-redis" ;;
105+
*) echo "Unknown chart: ${name}"; exit 1 ;;
106+
esac
107+
108+
echo "Chart ${name} changed, checking version ${version} in Packagecloud"
109+
110+
if curl -sf "https://${PACKAGECLOUD_TOKEN}:@packagecloud.io/api/v1/repos/circleci/${repo}/search.json?q=${version}" | grep -q "\"filename\":\"${name}-${version}.tgz\""; then
111+
echo "Error: ${name}-${version} already exists. Please bump version in ${chart_yaml}"
112+
exit 1
113+
elif [[ "${CIRCLE_BRANCH:-}" =~ ^server-[0-9]+\.[0-9]+$ && ! "${version}" =~ -${CIRCLE_BRANCH}$ ]]; then
114+
echo "Error: Version ${version} should be suffixed with -${CIRCLE_BRANCH} for branch ${CIRCLE_BRANCH}"
115+
exit 1
116+
fi
117+
fi
118+
fi
119+
done
120+
}
121+
90122
check-helm() {
91123
if ! [ -x "$(command -v helm)" ]; then
92124
echo 'Helm is required. See: https://helm.sh/docs/intro/install/'

0 commit comments

Comments
 (0)