Prepare v1.3.8 release: Update to GitHub Container Registry and synch… #59
Workflow file for this run
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 | |
id: 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 | |
# Also set as outputs for the step | |
echo "chart_version=${CHART_VERSION}" >> $GITHUB_OUTPUT | |
echo "app_version=v${APP_VERSION}" >> $GITHUB_OUTPUT | |
- name: Update Chart version if manually triggered | |
id: 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 | |
# Also set as outputs for the step | |
echo "chart_version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | |
echo "app_version=${{ github.event.inputs.appVersion }}" >> $GITHUB_OUTPUT | |
- name: Extract chart version from Chart.yaml | |
id: extract_chart_version | |
if: ${{ !startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch' }} | |
run: | | |
# Extract version from Chart.yaml | |
CHART_VERSION=$(grep '^version:' charts/aws-multi-eni-controller/Chart.yaml | awk '{print $2}') | |
APP_VERSION=$(grep '^appVersion:' charts/aws-multi-eni-controller/Chart.yaml | sed 's/appVersion: "\(.*\)"/\1/') | |
echo "Extracted CHART_VERSION=${CHART_VERSION} and APP_VERSION=${APP_VERSION} from Chart.yaml" | |
echo "CHART_VERSION=${CHART_VERSION}" >> $GITHUB_ENV | |
echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV | |
# Also set as outputs for the step | |
echo "chart_version=${CHART_VERSION}" >> $GITHUB_OUTPUT | |
echo "app_version=${APP_VERSION}" >> $GITHUB_OUTPUT | |
# 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 | |
id: create_index | |
run: | | |
# Create a simple index file for the chart | |
CHART_VERSION="${{ steps.set_chart_version_from_tag.outputs.chart_version || steps.update_chart_version_if_manually_triggered.outputs.chart_version || steps.extract_chart_version.outputs.chart_version }}" | |
helm repo index .helm-charts --url https://github.com/${{ github.repository }}/releases/download/helm-chart-${CHART_VERSION}/ | |
# Login to GHCR for OCI chart push | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ 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" | |
# Get chart version | |
CHART_VERSION="${{ steps.set_chart_version_from_tag.outputs.chart_version || steps.update_chart_version_if_manually_triggered.outputs.chart_version || steps.extract_chart_version.outputs.chart_version }}" | |
# 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:${CHART_VERSION}" | |
# Create GitHub release with chart as asset | |
- name: Create GitHub Release for Helm Chart | |
id: create_release | |
env: | |
GH_TOKEN: ${{ github.token }} | |
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) | |
# Get chart and app versions | |
CHART_VERSION="${{ steps.set_chart_version_from_tag.outputs.chart_version || steps.update_chart_version_if_manually_triggered.outputs.chart_version || steps.extract_chart_version.outputs.chart_version }}" | |
APP_VERSION="${{ steps.set_chart_version_from_tag.outputs.app_version || steps.update_chart_version_if_manually_triggered.outputs.app_version || steps.extract_chart_version.outputs.app_version }}" | |
# Create release notes | |
cat > release_notes.md << EOF | |
# AWS Multi-ENI Controller Helm Chart ${CHART_VERSION} | |
This release contains the Helm chart for AWS Multi-ENI Controller version ${APP_VERSION}. | |
## Installation Options | |
### Option 1: Install from GitHub Release | |
\`\`\`bash | |
# Download the chart | |
wget https://github.com/${{ github.repository }}/releases/download/helm-chart-${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 ${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 | |
# Check if release exists and delete it if it does | |
if gh release view helm-chart-${CHART_VERSION} &>/dev/null; then | |
echo "Release helm-chart-${CHART_VERSION} already exists, deleting it first..." | |
gh release delete helm-chart-${CHART_VERSION} --yes | |
fi | |
# Create GitHub release | |
gh release create helm-chart-${CHART_VERSION} \ | |
--title "Helm Chart ${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: | | |
# Get chart version | |
CHART_VERSION="${{ steps.set_chart_version_from_tag.outputs.chart_version || steps.update_chart_version_if_manually_triggered.outputs.chart_version || steps.extract_chart_version.outputs.chart_version }}" | |
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-${CHART_VERSION}/aws-multi-eni-controller-${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 ${CHART_VERSION}" |