Update Helm chart workflow to publish to GHCR as OCI artifacts #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Package and Publish Helm Chart | |
on: | |
push: | |
branches: [ main ] | |
# Trigger on tags for releases | |
tags: [ 'v*' ] | |
paths: | |
- 'charts/**' | |
# Allow manual triggering with version input | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Chart version (e.g., 0.1.0)' | |
required: true | |
default: '0.1.0' | |
appVersion: | |
description: 'App version (e.g., v1.1.1)' | |
required: true | |
default: 'v1.1.1' | |
env: | |
REGISTRY: ghcr.io | |
CHART_NAME: aws-multi-eni-controller | |
jobs: | |
package-and-publish: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # Needed for creating releases | |
packages: write # Needed for pushing to GHCR | |
actions: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Helm | |
uses: azure/setup-helm@v3 | |
with: | |
version: 'latest' | |
# Set chart version based on tag or input | |
- name: Set chart version from tag | |
if: startsWith(github.ref, 'refs/tags/v') | |
run: | | |
# Extract version from tag (remove 'v' prefix) | |
APP_VERSION=${GITHUB_REF#refs/tags/v} | |
CHART_VERSION=${APP_VERSION} | |
# Update Chart.yaml with the tag version | |
sed -i "s/^version:.*/version: ${CHART_VERSION}/" charts/aws-multi-eni-controller/Chart.yaml | |
sed -i "s/^appVersion:.*/appVersion: \"v${APP_VERSION}\"/" charts/aws-multi-eni-controller/Chart.yaml | |
echo "CHART_VERSION=${CHART_VERSION}" >> $GITHUB_ENV | |
echo "APP_VERSION=v${APP_VERSION}" >> $GITHUB_ENV | |
- name: Update Chart version if manually triggered | |
if: github.event_name == 'workflow_dispatch' | |
run: | | |
# Update Chart.yaml with the provided version and appVersion | |
sed -i "s/^version:.*/version: ${{ github.event.inputs.version }}/" charts/aws-multi-eni-controller/Chart.yaml | |
sed -i "s/^appVersion:.*/appVersion: \"${{ github.event.inputs.appVersion }}\"/" charts/aws-multi-eni-controller/Chart.yaml | |
# Display the updated Chart.yaml | |
echo "Updated Chart.yaml:" | |
cat charts/aws-multi-eni-controller/Chart.yaml | |
echo "CHART_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV | |
echo "APP_VERSION=${{ github.event.inputs.appVersion }}" >> $GITHUB_ENV | |
# Package the Helm chart | |
- name: Package Helm chart | |
run: | | |
mkdir -p .helm-charts | |
helm package charts/aws-multi-eni-controller -d .helm-charts | |
# Create index file for GitHub release | |
- name: Create Helm repository index | |
run: | | |
# Create a simple index file for the chart | |
helm repo index .helm-charts --url https://github.com/${{ github.repository }}/releases/download/helm-chart-${{ env.CHART_VERSION }}/ | |
# Login to GHCR for OCI chart push | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Push Helm chart to GHCR as OCI artifact | |
- name: Push Helm chart to GHCR | |
run: | | |
echo "Pushing Helm chart to GHCR as OCI artifact..." | |
helm push .helm-charts/aws-multi-eni-controller-${{ env.CHART_VERSION }}.tgz oci://${{ env.REGISTRY }}/${{ github.repository_owner }}/charts | |
echo "Chart pushed to: ${{ env.REGISTRY }}/${{ github.repository_owner }}/charts/aws-multi-eni-controller:${{ env.CHART_VERSION }}" | |
# Create GitHub release with chart as asset | |
- name: Create GitHub Release for Helm Chart | |
id: create_release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: helm-chart-${{ env.CHART_VERSION }} | |
name: Helm Chart ${{ env.CHART_VERSION }} | |
body: | | |
# AWS Multi-ENI Controller Helm Chart ${{ env.CHART_VERSION }} | |
This release contains the Helm chart for AWS Multi-ENI Controller version ${{ env.APP_VERSION }}. | |
## Installation Options | |
### Option 1: Install from GitHub Release | |
```bash | |
# Download the chart | |
wget https://github.com/${{ github.repository }}/releases/download/helm-chart-${{ env.CHART_VERSION }}/aws-multi-eni-controller-${{ env.CHART_VERSION }}.tgz | |
# Install the chart | |
helm install my-release ./aws-multi-eni-controller-${{ env.CHART_VERSION }}.tgz | |
``` | |
### Option 2: Install from OCI Registry (Recommended) | |
```bash | |
# Add the OCI registry | |
helm install my-release oci://${{ env.REGISTRY }}/${{ github.repository_owner }}/charts/aws-multi-eni-controller --version ${{ env.CHART_VERSION }} | |
``` | |
## Configuration | |
See the [Helm Chart README](https://github.com/${{ github.repository }}/blob/main/charts/aws-multi-eni-controller/README.md) for configuration options. | |
files: | | |
.helm-charts/*.tgz | |
.helm-charts/index.yaml | |
draft: false | |
prerelease: false | |
# Display instructions for using the chart | |
- name: Display instructions for using the Helm chart | |
run: | | |
echo "::notice::Helm chart has been published as a GitHub Release and to GHCR as an OCI artifact." | |
echo "::notice::Option 1: Download from GitHub Release:" | |
echo "::notice::https://github.com/${{ github.repository }}/releases/download/helm-chart-${{ env.CHART_VERSION }}/aws-multi-eni-controller-${{ env.CHART_VERSION }}.tgz" | |
echo "::notice::Option 2: Install from OCI Registry (Recommended):" | |
echo "::notice::helm install my-release oci://${{ env.REGISTRY }}/${{ github.repository_owner }}/charts/aws-multi-eni-controller --version ${{ env.CHART_VERSION }}" |