Skip to content

.github: publish unstable Helm charts. #17

.github: publish unstable Helm charts.

.github: publish unstable Helm charts. #17

Workflow file for this run

name: Package Helm charts
on:
push:
tags:
- "v*.*.*"
branches:
- main
env:
CHARTS_DIR: deployment/helm/
IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/v') && 'true' || 'false' }}
UNSTABLE_CHARTS: unstable-helm-charts
jobs:
release:
if: ${{ github.env.IS_RELEASE == 'true' }}
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Helm
uses: azure/[email protected]
- name: Package Release Helm Charts
run: |
find "$CHARTS_DIR" -name values.yaml | xargs -I '{}' \
sed -e s"/pullPolicy:.*/pullPolicy: IfNotPresent/" -i '{}'
helm package --version "$GITHUB_REF_NAME" --app-version "$GITHUB_REF_NAME" "$CHARTS_DIR"/*
find . -name '*.tgz' -print | while read SRC_FILE; do
DEST_FILE=$(echo $SRC_FILE | sed 's/v/helm-chart-v/g')
mv $SRC_FILE $DEST_FILE
done
- name: Upload Release Helm Chart Packages to GitHub Release
uses: softprops/action-gh-release@v1
with:
name: ${{ github.ref_name }}
draft: true
append_body: true
files: nri-*helm-chart*.tgz
unstable:
if: ${{ github.env.IS_RELEASE != 'true' }}
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Deep Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Helm
uses: azure/[email protected]
- name: Package Unstable Helm Charts
run: |
# Derive unstable chart version: use latest tag +1 patch + -unstable
# Image tag is 'unstable'.
majminpatch="$(git describe | sed -E 's/(v[0-9]*\.[0-9]*\.[0-9]*).*$/\1/')"
majmin=${majminpatch%.*}
patch=${majminpatch##*.}
CHART_VERSION="${majmin}.$((patch+1))-unstable"
APP_VERSION=unstable
# Package charts
find "$CHARTS_DIR" -name values.yaml | xargs -I '{}' \
sed -e s"/pullPolicy:.*/pullPolicy: IfNotPresent/" -i '{}'
helm package --version "$CHART_VERSION" --app-version $APP_VERSION "$CHARTS_DIR"/*
# Create empty worktree, and populate it with unstable charts.
git worktree add --orphan ../$UNSTABLE_CHARTS
find . -name '*.tgz' -print | while read SRC_FILE; do
DEST_FILE=$(echo $SRC_FILE | sed 's/v/helm-chart-v/g')
mv -v $SRC_FILE ../$UNSTABLE_CHARTS/$DEST_FILE
done
# Commit unstable charts to empty worktree.
pushd ../$UNSTABLE_CHARTS
git config user.name "Github Actions"
git config user.email "[email protected]"
git add *helm-chart*.tgz
git commit -s -m "$UNSTABLE_CHARTS: package $CHART_VERSION."
- name: Publish/Push Unstable Helm Charts
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# We only publish unstable Helm charts from main. Therefore cleaning up any
# old unstable chart instances happens by forcibly overwriting the dedicated
# branch with the new content.
git push --force https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git refs/heads/$UNSTABLE_CHARTS