Skip to content

Commit

Permalink
(ci): add workflow for alpha Helm chart releases
Browse files Browse the repository at this point in the history
This workflow automates the release process for alpha versions of Helm charts
when a new tag matching v*.*.* -alpha.* is pushed. It:

- Excludes the `tyk-operator` chart from the release process
- Updates chart versions and adds alpha prerelease annotations
- Updates internal chart dependencies to match the release version
- Runs helm lint checks before packaging
- Prepares charts for publishing to the repository

Signed-off-by: Burak Sekili <[email protected]>
  • Loading branch information
buraksekili committed Dec 13, 2024
1 parent 6a0e67b commit cbc72db
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 1 deletion.
138 changes: 138 additions & 0 deletions .github/workflows/release-alpha.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Helm Charts Release Alpha Version

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+"

jobs:
prepare-release:
runs-on: ubuntu-latest
outputs:
charts: ${{ steps.find-charts.outputs.charts }}
version: ${{ steps.extract-version.outputs.version }}
steps:
- uses: actions/checkout@v4

- name: Extract version
id: extract-version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Find charts to release
id: find-charts
run: |
CHARTS=$(find . -type f -name Chart.yaml -not -path "*/components/tyk-operator/*" -exec dirname {} \; | jq -R . | jq -sc .)
echo "charts=${CHARTS}" >> $GITHUB_OUTPUT
update-meta:
needs: prepare-release
runs-on: ubuntu-latest
strategy:
matrix:
chart: ${{ fromJson(needs.prepare-release.outputs.charts) }}
steps:
- uses: actions/checkout@v4

- name: Install yq
run: |
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq
chmod +x /usr/local/bin/yq
- name: Update Chart.yaml with alpha annotations and version
run: |
yq eval '
.version = "${{ needs.prepare-release.outputs.version }}" |
.annotations["artifacthub.io/prerelease"] = "true"
' -i ${{ matrix.chart }}/Chart.yaml
- name: Update dependencies version
run: |
#!/bin/bash
set -e
set -x
CHART_PATH="${{ matrix.chart }}/Chart.yaml"
if [ ! -f "${CHART_PATH}" ]; then
echo "Chart.yaml not found at ${CHART_PATH}"
exit 1
fi
OUR_CHARTS=$(echo "${{ needs.prepare-release.outputs.charts }}" | tr -d '[]' | tr ',' '\n' | xargs -n1 basename | tr '\n' ' ')
NUM_DEPS=$(yq eval '.dependencies | length' "${CHART_PATH}")
if [ "${NUM_DEPS}" -gt 0 ]; then
for i in $(seq 0 $((NUM_DEPS - 1))); do
DEP_NAME=$(yq eval ".dependencies[$i].name" "${CHART_PATH}") || continue
# Check if this dependency is one of our charts (excluding 'tyk-operator')
if [[ " ${OUR_CHARTS} " =~ " ${DEP_NAME} " ]] && [ "${DEP_NAME}" != "tyk-operator" ]; then
yq eval ".dependencies[$i].version = \"${{ needs.prepare-release.outputs.version }}\"" -i "${CHART_PATH}"
fi
done
fi
- name: Upload modified chart
uses: actions/upload-artifact@v4
with:
name: chart-${{ matrix.chart }}
path: ${{ matrix.chart }}
retention-days: 1

release-alpha-version:
needs: [prepare-release, update-meta]
runs-on: ubuntu-latest
strategy:
matrix:
chart: ${{ fromJson(needs.prepare-release.outputs.charts) }}
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
ct.yaml
- name: Download modified chart
uses: actions/download-artifact@v4
with:
name: chart-${{ matrix.chart }}
path: ${{ matrix.chart }}

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: "v3.16.0"

- name: Set up chart-testing
uses: helm/[email protected]
with:
version: v3.3.0

- name: Add dependencies
run: helm repo add tyk-helm https://helm.tyk.io/public/helm/charts/

- name: Update Helm Dependencies
run: helm dependency update ${{ matrix.chart }}

- name: Run chart-testing (lint)
run: |
ct lint --config ct.yaml --all --debug
- name: Package Helm Chart
run: |
helm package ${{ matrix.chart }} --version ${{ needs.prepare-release.outputs.version }}
- name: Helm Chart package file name
id: file-name
run: |
echo "fileName=$(basename ${{ matrix.chart }})-${{ needs.prepare-release.outputs.version }}.tgz"
echo "fileName=$(basename ${{ matrix.chart }})-${{ needs.prepare-release.outputs.version }}.tgz" >> "$GITHUB_OUTPUT"
- name: Push Helm Chart to Cloudsmith
uses: cloudsmith-io/[email protected]
with:
api-key: ${{ secrets.CLOUDSMITH_API_KEY }}
command: "push"
format: "helm"
owner: "tyk"
repo: "helm"
file: "${{ steps.file-name.outputs.fileName }}"
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ jobs:
format: "helm"
owner: "tyk"
repo: "helm"
file: "${{ steps.file-name.outputs.fileName }}"
file: "${{ steps.file-name.outputs.fileName }}"

0 comments on commit cbc72db

Please sign in to comment.