|
| 1 | +name: 🧭 Helm Chart Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'helm-v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + chart_version: |
| 10 | + description: 'Chart version to release' |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +env: |
| 15 | + REGISTRY: ghcr.io |
| 16 | + CHART_NAME: trigger |
| 17 | + |
| 18 | +jobs: |
| 19 | + lint-and-test: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up Helm |
| 28 | + uses: azure/setup-helm@v4 |
| 29 | + with: |
| 30 | + version: "3.18.3" |
| 31 | + |
| 32 | + - name: Lint Helm Chart |
| 33 | + run: | |
| 34 | + helm lint ./hosting/k8s/helm/ |
| 35 | +
|
| 36 | + - name: Render templates |
| 37 | + run: | |
| 38 | + helm template test-release ./hosting/k8s/helm/ \ |
| 39 | + --values ./hosting/k8s/helm/values.yaml \ |
| 40 | + --output-dir ./helm-output |
| 41 | +
|
| 42 | + - name: Validate manifests |
| 43 | + uses: docker://ghcr.io/yannh/kubeconform:v0.7.0 |
| 44 | + with: |
| 45 | + entrypoint: '/kubeconform' |
| 46 | + args: "-summary -output json ./helm-output" |
| 47 | + |
| 48 | + release: |
| 49 | + needs: lint-and-test |
| 50 | + runs-on: ubuntu-latest |
| 51 | + permissions: |
| 52 | + contents: write # for gh-release |
| 53 | + packages: write |
| 54 | + steps: |
| 55 | + - name: Checkout |
| 56 | + uses: actions/checkout@v4 |
| 57 | + |
| 58 | + - name: Set up Helm |
| 59 | + uses: azure/setup-helm@v4 |
| 60 | + with: |
| 61 | + version: "3.18.3" |
| 62 | + |
| 63 | + - name: Log in to Container Registry |
| 64 | + uses: docker/login-action@v3 |
| 65 | + with: |
| 66 | + registry: ${{ env.REGISTRY }} |
| 67 | + username: ${{ github.actor }} |
| 68 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + |
| 70 | + - name: Extract version from tag or input |
| 71 | + id: version |
| 72 | + run: | |
| 73 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 74 | + VERSION="${{ github.event.inputs.chart_version }}" |
| 75 | + else |
| 76 | + VERSION="${{ github.ref_name }}" |
| 77 | + VERSION="${VERSION#helm-v}" |
| 78 | + fi |
| 79 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 80 | + echo "Releasing version: $VERSION" |
| 81 | +
|
| 82 | + - name: Check Chart.yaml version matches release version |
| 83 | + run: | |
| 84 | + VERSION="${{ steps.version.outputs.version }}" |
| 85 | + CHART_VERSION=$(grep '^version:' ./hosting/k8s/helm/Chart.yaml | awk '{print $2}') |
| 86 | + echo "Chart.yaml version: $CHART_VERSION" |
| 87 | + echo "Release version: $VERSION" |
| 88 | + if [ "$CHART_VERSION" != "$VERSION" ]; then |
| 89 | + echo "❌ Chart.yaml version does not match release version!" |
| 90 | + exit 1 |
| 91 | + fi |
| 92 | + echo "✅ Chart.yaml version matches release version." |
| 93 | +
|
| 94 | + - name: Package Helm Chart |
| 95 | + run: | |
| 96 | + helm package ./hosting/k8s/helm/ --destination /tmp/ |
| 97 | +
|
| 98 | + - name: Push Helm Chart to GHCR |
| 99 | + run: | |
| 100 | + VERSION="${{ steps.version.outputs.version }}" |
| 101 | + CHART_PACKAGE="/tmp/${{ env.CHART_NAME }}-${VERSION}.tgz" |
| 102 | + |
| 103 | + # Push to GHCR OCI registry |
| 104 | + helm push "$CHART_PACKAGE" "oci://${{ env.REGISTRY }}/${{ github.repository_owner }}/charts" |
| 105 | +
|
| 106 | + - name: Create GitHub Release |
| 107 | + id: release |
| 108 | + uses: softprops/action-gh-release@v1 |
| 109 | + if: github.event_name == 'push' |
| 110 | + with: |
| 111 | + tag_name: ${{ github.ref_name }} |
| 112 | + name: "Helm Chart ${{ steps.version.outputs.version }}" |
| 113 | + body: | |
| 114 | + ### Installation |
| 115 | + ```bash |
| 116 | + helm upgrade --install trigger \ |
| 117 | + oci://${{ env.REGISTRY }}/${{ github.repository_owner }}/charts/${{ env.CHART_NAME }} \ |
| 118 | + --version ${{ steps.version.outputs.version }} |
| 119 | + ``` |
| 120 | + |
| 121 | + ### Changes |
| 122 | + See commit history for detailed changes in this release. |
| 123 | + files: | |
| 124 | + /tmp/${{ env.CHART_NAME }}-${{ steps.version.outputs.version }}.tgz |
| 125 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 126 | + draft: true |
| 127 | + prerelease: true |
0 commit comments