Skip to content

Commit ce7654c

Browse files
feat(ci): add build_release, publish_charts and manage_release workflow
1 parent bda3698 commit ce7654c

3 files changed

Lines changed: 195 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: manage_release
2+
3+
# Triggered on every push to master that touches charts/,
4+
# or manually via workflow_dispatch with an optional chart name.
5+
on:
6+
push:
7+
branches: [master]
8+
paths:
9+
- 'charts/**'
10+
workflow_dispatch:
11+
inputs:
12+
chart:
13+
description: "Chart to release (leave empty for automatic detection)"
14+
required: false
15+
default: ""
16+
17+
jobs:
18+
19+
# Detect which charts need to be released
20+
detect:
21+
name: Detect charts
22+
runs-on: ubuntu-22.04
23+
outputs:
24+
charts: ${{ steps.compute.outputs.charts }}
25+
has_charts: ${{ steps.compute.outputs.has_charts }}
26+
steps:
27+
- name: Checkout repo
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
submodules: true
32+
33+
- name: Init runner
34+
run: bash ./scripts/init_runner.sh ${{ github.job }}
35+
36+
- name: Detect charts
37+
id: compute
38+
env:
39+
GITHUB_EVENT_NAME: ${{ github.event_name }}
40+
GITHUB_EVENT_BEFORE: ${{ github.event.before }}
41+
GITHUB_EVENT_AFTER: ${{ github.event.after }}
42+
INPUT_CHART: ${{ github.event.inputs.chart }}
43+
run: bash ./scripts/detect_charts.sh
44+
45+
# Release the detected charts
46+
name: Release charts
47+
runs-on: ubuntu-22.04
48+
needs: detect
49+
if: needs.detect.outputs.has_charts == 'true'
50+
permissions:
51+
contents: write # required to create and push git tags
52+
steps:
53+
- name: Checkout repo
54+
uses: actions/checkout@v4
55+
with:
56+
fetch-depth: 0
57+
submodules: true
58+
59+
- name: Init runner
60+
run: bash ./scripts/init_runner.sh ${{ github.job }}
61+
62+
- name: Setup workspace
63+
env:
64+
KALISIO_GITHUB_URL: ${{ secrets.KALISIO_GITHUB_URL }}
65+
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
66+
run: bash ./scripts/setup_workspace.sh
67+
68+
- name: Release charts
69+
env:
70+
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
71+
run: bash ./scripts/build_release.sh -p ${{ needs.detect.outputs.charts }}

scripts/build_release.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
# set -x
4+
5+
# Build and release Helm charts to Harbor OCI registry and S3 backup.
6+
# Decrypts Harbor and rclone credentials from the development repository,
7+
# logs into the registry, then delegates to publish_charts.sh.
8+
#
9+
# Usage (CI mode):
10+
# bash ./scripts/build_release.sh -p chart1 chart2
11+
#
12+
# Usage (dev mode, no push):
13+
# bash ./scripts/build_release.sh chart1
14+
15+
THIS_FILE=$(readlink -f "${BASH_SOURCE[0]}")
16+
THIS_DIR=$(dirname "$THIS_FILE")
17+
ROOT_DIR=$(dirname "$THIS_DIR")
18+
WORKSPACE_DIR="$(dirname "$ROOT_DIR")"
19+
20+
. "$THIS_DIR/kash/kash.sh"
21+
22+
## Parse options
23+
##
24+
PUBLISH=false
25+
while getopts "p" option; do
26+
case $option in
27+
p) # publish charts to Harbor and S3
28+
PUBLISH=true
29+
;;
30+
*)
31+
;;
32+
esac
33+
done
34+
shift $((OPTIND-1))
35+
36+
## Decrypt credentials
37+
##
38+
begin_group "Setup Harbor credentials"
39+
40+
load_env_files \
41+
"$WORKSPACE_DIR/development/common/kalisio_harbor.enc.env"
42+
43+
load_value_files \
44+
"$WORKSPACE_DIR/development/common/KALISIO_HARBOR_PASSWORD.enc.value"
45+
46+
end_group "Setup Harbor credentials"
47+
48+
## Login to Harbor OCI registry
49+
##
50+
begin_group "Helm registry login"
51+
52+
helm registry login "$KALISIO_HARBOR_URL" \
53+
--username "$KALISIO_HARBOR_USERNAME" \
54+
--password-stdin < "$KALISIO_HARBOR_PASSWORD"
55+
56+
end_group "Helm registry login"
57+
58+
## Decrypt rclone configuration for S3 backup access
59+
##
60+
begin_group "Setup rclone config"
61+
62+
RCLONE_ENC_CONF="$WORKSPACE_DIR/development/rclone.enc.conf"
63+
RCLONE_DEC_CONF=$(enc2dec "$RCLONE_ENC_CONF")
64+
sops --decrypt --output "$RCLONE_DEC_CONF" "$RCLONE_ENC_CONF"
65+
66+
end_group "Setup rclone config"
67+
68+
## Release charts
69+
##
70+
begin_group "Release charts"
71+
72+
if [ "$PUBLISH" = true ]; then
73+
bash "$THIS_DIR/publish_charts.sh" "$@"
74+
else
75+
echo "-> Dry run mode: skipping publish (use -p to publish)"
76+
fi
77+
78+
end_group "Release charts"
79+
80+
## Logout from Harbor OCI registry
81+
##
82+
helm registry logout "$KALISIO_HARBOR_URL"

scripts/publish_charts.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
# set -x
4+
5+
# Orchestrate the release of all charts passed as arguments.
6+
# For each chart, decides between a production release or a dev release
7+
# based on whether the corresponding git tag already exists:
8+
# - tag absent -> new version -> production release (release-chart.sh)
9+
# - tag present -> same version, content changed -> dev release (release-dev-chart.sh)
10+
#
11+
# Usage (CI mode):
12+
# SOPS_AGE_KEY=... bash ./scripts/publish_charts.sh chart1 chart2
13+
#
14+
# Usage (dev mode, no push):
15+
# bash ./scripts/publish_charts.sh chart1
16+
17+
THIS_FILE=$(readlink -f "${BASH_SOURCE[0]}")
18+
THIS_DIR=$(dirname "$THIS_FILE")
19+
20+
. "$THIS_DIR/kash/kash.sh"
21+
22+
# Git identity required to create and push tags
23+
git config user.name "github-actions[bot]"
24+
git config user.email "github-actions[bot]@users.noreply.github.com"
25+
26+
# Release each chart
27+
for CHART in "$@"; do
28+
VERSION=$(sed -En 's/^version: (.*)$/\1/p' "charts/${CHART}/Chart.yaml")
29+
TAG_NAME="${CHART}-${VERSION}"
30+
31+
begin_group "Publish ${CHART} (${VERSION})"
32+
33+
if git show-ref --tags "${TAG_NAME}" --quiet; then
34+
echo "-> Tag ${TAG_NAME} already exists, releasing dev version (0.0.0-dev)"
35+
bash "$THIS_DIR/release-dev-chart.sh" "${CHART}"
36+
else
37+
echo "-> Tag ${TAG_NAME} not found, releasing production version (${VERSION})"
38+
bash "$THIS_DIR/release-chart.sh" "${CHART}"
39+
fi
40+
41+
end_group "Publish ${CHART} (${VERSION})"
42+
done

0 commit comments

Comments
 (0)