Package and publish Helm chart to GHCR with input #6
This file contains 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 to GHCR with input | |
on: | |
workflow_dispatch: | |
inputs: | |
chartDir: | |
description: 'Directory containing the Helm chart to package and publish' | |
required: true | |
type: string | |
chartName: | |
description: 'Name of the Helm chart to package and publish(optional)' | |
required: false | |
type: string | |
dry-run: | |
description: 'Run the workflow without pushing the Helm chart to the registry' | |
type: boolean | |
required: false | |
permissions: | |
contents: write | |
packages: write | |
env: | |
REGISTRY: ghcr.io | |
ACTIONS_RUNNER_DEBUG: false | |
jobs: | |
helm-release: | |
runs-on: [ ubuntu-latest ] | |
steps: | |
- name: Print inputs | |
run: | | |
echo "chartDir: ${{ inputs.chartDir }}" | |
echo "chartName: ${{ inputs.chartName }}" | |
echo "dry-run: ${{ inputs.dry-run }}" | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Configure Git | |
run: | | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | |
- name: Set up Helm | |
uses: azure/setup-helm@v4.2.0 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: 3.9 | |
check-latest: true | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up chart-testing | |
uses: helm/chart-testing-action@v2.6.1 | |
- name: Run chart-testing (lint) | |
run: ct lint --chart-yaml-schema ci/chart_schema.yaml --lint-conf ci/lintconf.yaml --config ci/config.yaml --since HEAD~1 --chart-dirs ${{ inputs.chartDir }} | |
- name: Push Charts to GHCR | |
run: | | |
helm dependency update ${{ inputs.chartDir }} | |
helm package ${{ inputs.chartDir }} -d ${{ inputs.chartDir }} | |
PKG_NAME=`ls ${{ inputs.chartDir }}/*.tgz` | |
if [ ${{ inputs.chartName }} ]; then | |
mv ${PKG_NAME} ${{ inputs.chartDir }}/${{ inputs.chartName }}.tgz | |
PKG_NAME=${{ inputs.chartName }} | |
fi | |
if [ ${{ inputs.dry-run }} == 'true' ]; then | |
echo "Dry run: Skipping push of $PKG_NAME" | |
exit 0 | |
else | |
helm push ${PKG_NAME} oci://${{ env.REGISTRY }}/${{ github.repository }}/ | |
fi |