@@ -3,19 +3,22 @@ name: Release Helm Chart by Branch
33on :
44 push :
55 branches :
6- # - master
76 - master-copy
87 paths :
9- - ' deployments/kubernetes/chart/**'
8+ - ' deployments/kubernetes/chart/reloader/ **'
109 workflow_dispatch : {}
1110
1211permissions :
1312 contents : write
13+ packages : write
1414
1515concurrency :
1616 group : helm-chart-release-branch-${{ github.ref_name }}
1717 cancel-in-progress : false
1818
19+ env :
20+ OCI_REPO : ghcr.io/${{ github.repository_owner }}/charts
21+
1922jobs :
2023 release :
2124 runs-on : ubuntu-latest
@@ -25,95 +28,93 @@ jobs:
2528 with :
2629 fetch-depth : 0
2730
28- - name : Configure Git
31+ - name : Set up Helm
32+ uses : azure/setup-helm@v4
33+ with :
34+ version : v3.14.0
35+
36+ - name : Read new chart version
37+ id : newver
2938 run : |
30- git config user.name "${GITHUB_ACTOR}"
31- git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
39+ ver=$(grep '^version:' deployments/kubernetes/chart/reloader/Chart.yaml | awk '{print $2}')
40+ echo "version=$ver" >> $GITHUB_OUTPUT
3241
33- - name : Ensure gh-pages branch exists
34- shell : bash
42+ - name : Fetch existing branch index (if any)
43+ id : prev
3544 run : |
36- set -euo pipefail
37- SRC_BRANCH="${GITHUB_REF_NAME}"
38- if ! git ls-remote --exit-code --heads origin gh-pages >/dev/null 2>&1; then
39- echo "Initializing gh-pages branch"
40- git checkout --orphan gh-pages
41- git reset --hard
42- rm -rf ./* .github || true
43- touch .nojekyll
44- git add .nojekyll
45- git commit -m "Initialize gh-pages for Helm chart index"
46- git push origin gh-pages
47- # Switch back to the source branch explicitly
48- git fetch origin "$SRC_BRANCH" --depth=1
49- git checkout "$SRC_BRANCH"
45+ set -e
46+ BRANCH_SAFE="${GITHUB_REF_NAME//\//-}"
47+ URL="https://${{ github.repository_owner }}.github.io/${GITHUB_REPOSITORY#*/}/branches/${BRANCH_SAFE}/index.yaml"
48+ echo "url=$URL" >> $GITHUB_OUTPUT
49+ if curl -fsS "$URL" -o existing-index.yaml; then
50+ latest=$(yq '.entries.reloader | sort_by(.version)[-1].version' existing-index.yaml || true)
51+ echo "latest=$latest" >> $GITHUB_OUTPUT
52+ else
53+ echo "latest=" >> $GITHUB_OUTPUT
5054 fi
5155
52- - name : Compute branch-specific paths
53- id : branch
54- shell : bash
56+ - name : Ensure version increment
5557 run : |
56- RAW="${GITHUB_REF_NAME}"
57- SAFE ="${RAW//\//- }"
58- echo "raw=$RAW" >> $GITHUB_OUTPUT
59- echo "safe=$SAFE" >> $GITHUB_OUTPUT
60- OWNER="${{ github.repository_owner }}"
61- REPO="${GITHUB_REPOSITORY#*/}"
62- BASE="https://${OWNER}.github.io/${REPO}"
63- echo "base=$BASE" >> $GITHUB_OUTPUT
64- echo "index_path=branches/$SAFE" >> $GITHUB_OUTPUT
65- echo "repo_url=$BASE/branches/$SAFE" >> $GITHUB_OUTPUT
66- CHART_VERSION=$(grep '^version:' deployments/kubernetes/chart/reloader/Chart.yaml | awk '{print $2}')
67- echo "chart_version=$CHART_VERSION" >> $GITHUB_OUTPUT
58+ set -e
59+ new ="${{ steps.newver.outputs.version } }"
60+ old="${{ steps.prev.outputs.latest }}"
61+ if [ -n "$old" ]; then
62+ # naive semver compare using sort -V
63+ ordered=$(printf "%s\n%s\n" "$old" "$new" | sort -V | tail -n1)
64+ if [ "$ordered" != "$new" ] || [ "$old" = "$new" ]; then
65+ echo "Chart version $new is not greater than previous $old" >&2
66+ exit 1
67+ fi
68+ fi
69+ echo "Version check passed (old=$old new=$new)"
6870
69- - name : Release with chart-releaser (branch)
70- uses : helm/chart-releaser-action@v1.6.0
71- with :
72- charts_dir : deployments/kubernetes/chart
73- mark_as_latest : false
74- packages_with_index : true
75- env :
76- CR_TOKEN : ${{ github.token }}
77- CR_PAGES_BRANCH : gh-pages
78- CR_SKIP_EXISTING : true
79- CR_CHARTS_REPO_URL : ${{ steps.branch.outputs.repo_url }}
71+ - name : Package chart
72+ run : |
73+ helm package deployments/kubernetes/chart/reloader --destination dist
74+ ls -l dist
8075
81- - name : Relocate index and packages to branch subfolder
82- shell : bash
76+ - name : Push OCI package (optional, ignore failure)
77+ run : |
78+ set -e
79+ echo "Logging into GHCR for OCI push"
80+ echo ${{ github.token }} | helm registry login ghcr.io --username ${{ github.actor }} --password-stdin || true
81+ helm push dist/*.tgz oci://$OCI_REPO || echo "OCI push skipped"
82+
83+ - name : Update gh-pages branch (branch-scoped index)
8384 run : |
8485 set -euo pipefail
85- SAFE="${{ steps.branch.outputs.safe }}"
86- CHART_VERSION="${{ steps.branch.outputs.chart_version }}"
87- ORIG_BRANCH="${GITHUB_REF_NAME}"
88- WORKDIR=$(pwd)
89- TMPDIR=$(mktemp -d)
90- # Collect artifacts produced on source branch before switching
91- [ -f index.yaml ] && mv index.yaml "$TMPDIR/index.yaml" || true
92- for f in *.tgz; do
93- [ -f "$f" ] && mv "$f" "$TMPDIR/" || true
94- done
95- # Switch to gh-pages safely (no untracked artifact conflicts)
96- git checkout gh-pages || git checkout --track origin/gh-pages
97- git fetch origin gh-pages
98- git reset --hard origin/gh-pages
86+ SAFE="${GITHUB_REF_NAME//\//-}"
87+ git fetch origin gh-pages || true
88+ if git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then
89+ git checkout gh-pages
90+ git reset --hard origin/gh-pages
91+ else
92+ git checkout --orphan gh-pages
93+ git reset --hard
94+ touch .nojekyll
95+ git add .nojekyll
96+ git commit -m "init gh-pages"
97+ fi
9998 mkdir -p branches/$SAFE
100- # Copy artifacts into branch-specific folder
101- [ -f "$TMPDIR/index.yaml" ] && cp "$TMPDIR/index.yaml" branches/$SAFE/index.yaml || true
102- for f in "$TMPDIR"/*.tgz; do
103- [ -f "$f" ] && cp "$f" branches/$SAFE/ || true
104- done
99+ cp dist/*.tgz branches/$SAFE/
100+ if [ -f branches/$SAFE/index.yaml ]; then
101+ helm repo index branches/$SAFE --url "https://${{ github.repository_owner }}.github.io/${GITHUB_REPOSITORY#*/}/branches/${SAFE}" --merge branches/$SAFE/index.yaml
102+ else
103+ helm repo index branches/$SAFE --url "https://${{ github.repository_owner }}.github.io/${GITHUB_REPOSITORY#*/}/branches/${SAFE}"
104+ fi
105105 git add branches/$SAFE
106- git commit -m "Branch chart repo for $SAFE ( version $CHART_VERSION) " || echo "Nothing new to commit "
106+ git commit -m "chore( chart): publish reloader ${{ steps.newver.outputs. version }} for branch $SAFE " || echo "No changes "
107107 git push origin gh-pages
108- # Cleanup and return to original branch
109- rm -rf "$TMPDIR"
110- git checkout "$ORIG_BRANCH"
108+ git checkout "${GITHUB_REF_NAME}"
111109
112- # - name: Notify Slack
113- # uses: 8398a7/action-slack@v3
114- # if: always()
115- # with:
116- # status: ${{ job.status }}
117- # fields: repo,author,action,eventName,ref,workflow
118- # env:
119- # SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }}
110+ - name : Create chart tag
111+ run : |
112+ set -e
113+ ver="${{ steps.newver.outputs.version }}"
114+ git tag -f chart-v$ver || true
115+ git push -f origin refs/tags/chart-v$ver
116+
117+ - name : Summary
118+ run : |
119+ echo "Branch chart published. Add repo via:"
120+ echo "helm repo add reloader https://${{ github.repository_owner }}.github.io/${GITHUB_REPOSITORY#*/}/branches/${GITHUB_REF_NAME//\//-}"
0 commit comments