Skip to content

handle build, push, and upload of helm chart (take 1) #5

handle build, push, and upload of helm chart (take 1)

handle build, push, and upload of helm chart (take 1) #5

Workflow file for this run

name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
workflow_dispatch:
inputs:
tag:
description: 'Tag to create (e.g. v1.0.0, v2.3.4-rc1)'
required: true
type: string
permissions:
contents: write
packages: write
jobs:
release:
name: Build and Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Install Helm
uses: azure/setup-helm@v4
- name: Configure git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Validate tag
if: github.event_name == 'workflow_dispatch'
run: |
if ! [[ "${{ inputs.tag }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "Tag must match pattern v[0-9]+.[0-9]+.[0-9]+* (e.g. v1.0.0, v2.3.4-rc1)"
exit 1
fi
- name: Create and push tag
if: github.event_name == 'workflow_dispatch'
run: |
TAG="${{ inputs.tag }}"
if git rev-parse "refs/tags/$TAG" &>/dev/null; then
echo "Tag $TAG already exists"
exit 1
fi
git tag "$TAG"
git push origin "$TAG"
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute version and release type
id: compute_version
run: |
TAG_NAME="${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}"
COMMIT=$(git rev-parse "$TAG_NAME^{commit}")
BRANCHES=$(git branch -r --contains "$COMMIT" | sed 's|^[[:space:]]*origin/||' | grep -v 'HEAD')
if echo "$BRANCHES" | grep -qx 'main'; then
IMAGE_TAG="${TAG_NAME#v}"
PRERELEASE="false"
MAKE_LATEST="true"
else
PRERELEASE="true"
MAKE_LATEST="false"
BRANCH=$(echo "$BRANCHES" | grep -v 'main' | head -1)
if [ -z "$BRANCH" ]; then
SANITIZED="branch-unknown"
else
SANITIZED=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9._-]/-/g' | sed 's/-\+/-/g' | sed 's/^-//;s/-$//')
fi
IMAGE_TAG="${TAG_NAME#v}_${SANITIZED}"
fi
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_OUTPUT
echo "PRERELEASE=$PRERELEASE" >> $GITHUB_OUTPUT
echo "MAKE_LATEST=$MAKE_LATEST" >> $GITHUB_OUTPUT
- name: Build and push application image
run: |
make docker-buildx IMAGE_TAG_BASE="ghcr.io/${{ github.repository }}" VERSION="${{ steps.compute_version.outputs.IMAGE_TAG }}"
- name: Build and push helm chart
run: |
make helm-build IMAGE_TAG_BASE="ghcr.io/${{ github.repository }}" VERSION="${{ steps.compute_version.outputs.IMAGE_TAG }}"
helm push ./build/fortsa-${{ steps.compute_version.outputs.IMAGE_TAG }}.tgz oci://ghcr.io/${{ github.repository }}/helm
# - name: Build and push OLM bundle image
# run: |
# make bundle bundle-build bundle-push IMAGE_TAG_BASE="ghcr.io/${{ github.repository }}" VERSION="${{ steps.compute_version.outputs.IMAGE_TAG }}"
# - name: Build and push OLM catalog image
# run: |
# make catalog-build catalog-push IMAGE_TAG_BASE="ghcr.io/${{ github.repository }}" VERSION="${{ steps.compute_version.outputs.IMAGE_TAG }}"
- name: Rename Helm Chart Tarball File for Upload
run: mv ./build/fortsa-${{ steps.compute_version.outputs.IMAGE_TAG }}.tgz ./build/fortsa-helm-chart-${{ steps.compute_version.outputs.IMAGE_TAG }}.tgz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
draft: true # always create as a draft release
prerelease: ${{ steps.compute_version.outputs.PRERELEASE == 'true' }}
make_latest: ${{ steps.compute_version.outputs.MAKE_LATEST }}
files: |
./build/fortsa-helm-chart-${{ steps.compute_version.outputs.IMAGE_TAG }}.tgz