Skip to content

Commit d1bf927

Browse files
ci: workflow release helm chart
Signed-off-by: Thomas Poignant <thomas.poignant@gofeatureflag.org>
1 parent 0c8e53f commit d1bf927

File tree

7 files changed

+193
-23
lines changed

7 files changed

+193
-23
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/bin/bash
2+
3+
# Script to bump Helm chart version and appVersion in Chart.yaml
4+
# Usage: ./bump-helm-chart.sh <version>
5+
# Examples: ./bump-helm-chart.sh v1.2.3 or ./bump-helm-chart.sh 1.2.3
6+
7+
set -euo pipefail
8+
9+
# Colors for output
10+
RED='\033[0;31m'
11+
GREEN='\033[0;32m'
12+
YELLOW='\033[1;33m'
13+
NC='\033[0m' # No Color
14+
15+
# Function to print colored output
16+
print_error() {
17+
echo -e "${RED}Error: $1${NC}" >&2
18+
}
19+
20+
print_success() {
21+
echo -e "${GREEN}$1${NC}"
22+
}
23+
24+
print_warning() {
25+
echo -e "${YELLOW}$1${NC}"
26+
}
27+
28+
# Function to show usage
29+
show_usage() {
30+
echo "Usage: $0 <version>"
31+
echo ""
32+
echo "Examples:"
33+
echo " $0 v1.2.3"
34+
echo " $0 1.2.3"
35+
echo ""
36+
echo "The script will update both 'version' and 'appVersion' in Chart.yaml"
37+
echo " - version: semver without 'v' prefix (e.g., 1.2.3)"
38+
echo " - appVersion: string with 'v' prefix (e.g., \"v1.2.3\")"
39+
}
40+
41+
# Function to validate semver format
42+
validate_semver() {
43+
local version="$1"
44+
# Check if version matches semver pattern (major.minor.patch with optional pre-release and build)
45+
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$ ]]; then
46+
return 1
47+
fi
48+
return 0
49+
}
50+
51+
# Function to parse version input
52+
parse_version() {
53+
local input_version="$1"
54+
local version
55+
56+
# Remove 'v' prefix if present
57+
if [[ "$input_version" =~ ^v(.+)$ ]]; then
58+
version="${BASH_REMATCH[1]}"
59+
else
60+
version="$input_version"
61+
fi
62+
63+
# Validate the version format
64+
if ! validate_semver "$version"; then
65+
print_error "Invalid version format: '$input_version'. Expected format: v1.2.3 or 1.2.3"
66+
return 1
67+
fi
68+
69+
echo "$version"
70+
}
71+
72+
# Function to update Chart.yaml
73+
update_chart_yaml() {
74+
local chart_file="$1"
75+
local version="$2"
76+
local app_version="v$version"
77+
78+
# Check if Chart.yaml exists
79+
if [[ ! -f "$chart_file" ]]; then
80+
print_error "Chart.yaml not found at: $chart_file"
81+
return 1
82+
fi
83+
84+
# Update version and appVersion using sed
85+
# Update version (semver without v)
86+
sed -i.tmp "s/^version: .*$/version: $version/" "$chart_file"
87+
88+
# Update appVersion (string with v)
89+
sed -i.tmp "s/^appVersion: .*$/appVersion: \"$app_version\"/" "$chart_file"
90+
91+
# Remove temporary file created by sed
92+
rm -f "${chart_file}.tmp"
93+
94+
print_success "Updated Chart.yaml:"
95+
print_success " version: $version"
96+
print_success " appVersion: \"$app_version\""
97+
}
98+
99+
# Main script logic
100+
main() {
101+
# Check if version argument is provided
102+
if [[ $# -eq 0 ]]; then
103+
print_error "No version provided"
104+
show_usage
105+
exit 1
106+
fi
107+
108+
# Check for help flag
109+
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
110+
show_usage
111+
exit 0
112+
fi
113+
114+
local input_version="$1"
115+
local chart_file="cmd/relayproxy/helm-charts/relay-proxy/Chart.yaml"
116+
117+
# Parse and validate version
118+
local parsed_version
119+
if ! parsed_version=$(parse_version "$input_version"); then
120+
exit 1
121+
fi
122+
123+
print_success "Parsed version: $parsed_version"
124+
125+
# Update Chart.yaml
126+
if ! update_chart_yaml "$chart_file" "$parsed_version"; then
127+
exit 1
128+
fi
129+
130+
print_success "Helm chart version bump completed successfully! 🦁"
131+
}
132+
133+
# Run main function with all arguments
134+
main "$@"

.github/release-please/release-please-config.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
"openfeature/providers/kotlin-provider",
3838
"openfeature/providers/python-provider",
3939
".github/release-please"
40-
],
41-
"extra-files": [
42-
{
43-
"type": "generic",
44-
"path": "cmd/relayproxy/helm-charts/relay-proxy/Chart.yaml"
45-
}
4640
]
4741
},
4842
"modules/evaluation": {

.github/workflows/release-helm.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
name: Release Charts
22
on:
3-
workflow_call:
4-
inputs:
5-
version: { type: string, required: true }
3+
push:
4+
branches:
5+
- main
66

7-
permissions:
8-
actions: read
9-
contents: read
7+
permissions: read-all
108

119
jobs:
1210
helm-release:
@@ -20,7 +18,14 @@ jobs:
2018
with:
2119
fetch-depth: 0
2220

21+
- name: Get changed files in the docs folder
22+
id: changed-files-specific
23+
uses: marceloprado/has-changed-path@df1b7a3161b8fb9fd8c90403c66a9e66dfde50cb # v1.0.1
24+
with:
25+
paths: ./cmd/relayproxy/helm-charts/
26+
2327
- name: Publish Helm chart
28+
if: steps.changed-files-specific.outputs.changed == 'true'
2429
uses: stefanprodan/helm-gh-pages@0ad2bb377311d61ac04ad9eb6f252fb68e207260 # v1.7.0
2530
with:
2631
token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
@@ -39,6 +44,7 @@ jobs:
3944
check-latest: true
4045

4146
- name: Update chart README
47+
if: steps.changed-files-specific.outputs.changed == 'true'
4248
run: make generate-helm-docs
4349

4450
- name: Checkout main branch
@@ -56,6 +62,7 @@ jobs:
5662

5763
- name: Create Pull Request
5864
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
65+
if: steps.changed-files-specific.outputs.changed == 'true'
5966
with:
6067
branch: update-relay-proxy-chart-readme
6168
title: "docs(helm): Update relay proxy helm README"

.github/workflows/release-please.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,3 @@ jobs:
6868
needs: release-please
6969
with:
7070
version: ${{ needs.release-please.outputs.root_version }}
71-
72-
helm-release:
73-
if: ${{ needs.release-please.outputs.root_released == 'true' }}
74-
uses: ./.github/workflows/release-helm.yml
75-
needs:
76-
- release-please
77-
- root-release
78-
with:
79-
version: ${{ needs.release-please.outputs.root_version }}

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,38 @@ jobs:
366366
delete-branch: true
367367
path: ${{ env.MAIN_BRANCH_NAME }}
368368
token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
369+
370+
bump-relay-proxy-helm-chart:
371+
# bump-relay-proxy-helm-chart is opening a pull request to bump the appVersion field
372+
# in the Chart.yaml file of the helm-chart.
373+
runs-on: ubuntu-latest
374+
name: Bump Relay Proxy Helm Chart appVersion
375+
needs:
376+
- goreleaser
377+
- wasm-release
378+
env:
379+
CHART_YAML_FILE_LOCATION: cmd/relayproxy/helm-charts/relay-proxy/Chart.yaml
380+
MAIN_BRANCH_NAME: main
381+
VERSION: ${{ inputs.version }}
382+
steps:
383+
- name: Checkout
384+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
385+
386+
- name: Bump chart appVersion
387+
run: make bump-helm-chart-version VERSION=${VERSION}
388+
389+
- run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
390+
391+
- name: Create Pull Request
392+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
393+
with:
394+
branch: bump-relay-proxy-helm-chart-${VERSION}
395+
title: "chore(helm): Bump relay-proxy helm chart version ${VERSION}"
396+
body: Automated pull request to bump relay-proxy helm chart version ${VERSION}
397+
commit-message: Bump relay-proxy helm chart version ${VERSION}
398+
labels: automerge
399+
assignees: thomaspoignant
400+
draft: false
401+
signoff: true
402+
delete-branch: true
403+
token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ generate-helm-docs: ## Generates helm documentation for the project
7676
$(GOCMD) install github.com/norwoodj/helm-docs/cmd/helm-docs@latest
7777
helm-docs
7878

79+
bump-helm-chart-version: ## Bump Helm chart version (usage: make bump-helm-chart-version VERSION=v1.2.3)
80+
@if [ -z "$(VERSION)" ]; then \
81+
echo "$(RED)Error: VERSION is required$(RESET)"; \
82+
echo "Usage: make bump-helm-chart-version VERSION=v1.2.3"; \
83+
echo " make bump-helm-chart-version VERSION=1.2.3"; \
84+
exit 1; \
85+
fi
86+
.github/ci-scripts/bump-helm-chart.sh $(VERSION)
87+
7988
## Test:
8089
test: ## Run the tests of the project
8190
$(GOTEST) -v -race ./... -tags=docker

cmd/relayproxy/helm-charts/relay-proxy/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ sources:
55
- "https://github.com/thomaspoignant/go-feature-flag"
66
description: A Helm chart to deploy go-feature-flag-relay proxy into Kubernetes
77
type: application
8-
version: 1.46.1 # x-release-please-version
9-
appVersion: "v1.46.1" # x-release-please-version
8+
version: 1.46.1
9+
appVersion: "v1.46.1"
1010

1111
icon: https://raw.githubusercontent.com/thomaspoignant/go-feature-flag/main/logo.png
1212
maintainers:

0 commit comments

Comments
 (0)