Package and Publish Helm Chart #6
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 | |
# List the packaged chart for debugging | |
echo "Packaged chart files:" | |
ls -la .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..." | |
# Find the chart file | |
CHART_FILE=$(find .helm-charts -name "*.tgz" | head -n 1) | |
if [ -z "$CHART_FILE" ]; then | |
echo "Error: No chart file found in .helm-charts directory" | |
exit 1 | |
fi | |
echo "Found chart file: $CHART_FILE" | |
# Push the chart to GHCR | |
helm push $CHART_FILE 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 | |
run: | | |
# Find the chart file | |
CHART_FILE=$(find .helm-charts -name "*.tgz" | head -n 1) | |
if [ -z "$CHART_FILE" ]; then | |
echo "Error: No chart file found in .helm-charts directory" | |
exit 1 | |
fi | |
# Extract the chart filename | |
CHART_FILENAME=$(basename $CHART_FILE) | |
# Create release notes | |
cat > release_notes.md << EOF | |
# 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 }}/$CHART_FILENAME | |
# Install the chart | |
helm install my-release ./$CHART_FILENAME | |
\`\`\` | |
### Option 2: Install from OCI Registry (Recommended) | |
\`\`\`bash | |
# Install directly from 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. | |
EOF | |
# Create GitHub release | |
gh release create helm-chart-${{ env.CHART_VERSION }} \ | |
--title "Helm Chart ${{ env.CHART_VERSION }}" \ | |
--notes-file release_notes.md \ | |
$CHART_FILE .helm-charts/index.yaml | |
# 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 }}" |