|
| 1 | +name: 🧭 Helm Chart PR Prerelease |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + paths: |
| 7 | + - "hosting/k8s/helm/**" |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: helm-prerelease-${{ github.event.pull_request.number }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +env: |
| 14 | + REGISTRY: ghcr.io |
| 15 | + CHART_NAME: trigger |
| 16 | + |
| 17 | +jobs: |
| 18 | + lint-and-test: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Set up Helm |
| 27 | + uses: azure/setup-helm@v4 |
| 28 | + with: |
| 29 | + version: "3.18.3" |
| 30 | + |
| 31 | + - name: Build dependencies |
| 32 | + run: helm dependency build ./hosting/k8s/helm/ |
| 33 | + |
| 34 | + - name: Extract dependency charts |
| 35 | + run: | |
| 36 | + cd ./hosting/k8s/helm/ |
| 37 | + for file in ./charts/*.tgz; do echo "Extracting $file"; tar -xzf "$file" -C ./charts; done |
| 38 | +
|
| 39 | + - name: Lint Helm Chart |
| 40 | + run: | |
| 41 | + helm lint ./hosting/k8s/helm/ |
| 42 | +
|
| 43 | + - name: Render templates |
| 44 | + run: | |
| 45 | + helm template test-release ./hosting/k8s/helm/ \ |
| 46 | + --values ./hosting/k8s/helm/values.yaml \ |
| 47 | + --output-dir ./helm-output |
| 48 | +
|
| 49 | + - name: Validate manifests |
| 50 | + uses: docker://ghcr.io/yannh/kubeconform:v0.7.0 |
| 51 | + with: |
| 52 | + entrypoint: "/kubeconform" |
| 53 | + args: "-summary -output json ./helm-output" |
| 54 | + |
| 55 | + prerelease: |
| 56 | + needs: lint-and-test |
| 57 | + runs-on: ubuntu-latest |
| 58 | + permissions: |
| 59 | + contents: read |
| 60 | + packages: write |
| 61 | + pull-requests: write |
| 62 | + steps: |
| 63 | + - name: Checkout |
| 64 | + uses: actions/checkout@v4 |
| 65 | + |
| 66 | + - name: Set up Helm |
| 67 | + uses: azure/setup-helm@v4 |
| 68 | + with: |
| 69 | + version: "3.18.3" |
| 70 | + |
| 71 | + - name: Build dependencies |
| 72 | + run: helm dependency build ./hosting/k8s/helm/ |
| 73 | + |
| 74 | + - name: Extract dependency charts |
| 75 | + run: | |
| 76 | + cd ./hosting/k8s/helm/ |
| 77 | + for file in ./charts/*.tgz; do echo "Extracting $file"; tar -xzf "$file" -C ./charts; done |
| 78 | +
|
| 79 | + - name: Log in to Container Registry |
| 80 | + uses: docker/login-action@v3 |
| 81 | + with: |
| 82 | + registry: ${{ env.REGISTRY }} |
| 83 | + username: ${{ github.actor }} |
| 84 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + |
| 86 | + - name: Generate prerelease version |
| 87 | + id: version |
| 88 | + run: | |
| 89 | + BASE_VERSION=$(grep '^version:' ./hosting/k8s/helm/Chart.yaml | awk '{print $2}') |
| 90 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 91 | + SHORT_SHA=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7) |
| 92 | + PRERELEASE_VERSION="${BASE_VERSION}-pr${PR_NUMBER}.${SHORT_SHA}" |
| 93 | + echo "version=$PRERELEASE_VERSION" >> $GITHUB_OUTPUT |
| 94 | + echo "Prerelease version: $PRERELEASE_VERSION" |
| 95 | +
|
| 96 | + - name: Update Chart.yaml with prerelease version |
| 97 | + run: | |
| 98 | + sed -i "s/^version:.*/version: ${{ steps.version.outputs.version }}/" ./hosting/k8s/helm/Chart.yaml |
| 99 | +
|
| 100 | + - name: Package Helm Chart |
| 101 | + run: | |
| 102 | + helm package ./hosting/k8s/helm/ --destination /tmp/ |
| 103 | +
|
| 104 | + - name: Push Helm Chart to GHCR |
| 105 | + run: | |
| 106 | + VERSION="${{ steps.version.outputs.version }}" |
| 107 | + CHART_PACKAGE="/tmp/${{ env.CHART_NAME }}-${VERSION}.tgz" |
| 108 | +
|
| 109 | + # Push to GHCR OCI registry |
| 110 | + helm push "$CHART_PACKAGE" "oci://${{ env.REGISTRY }}/${{ github.repository_owner }}/charts" |
| 111 | +
|
| 112 | + - name: Find existing comment |
| 113 | + uses: peter-evans/find-comment@v3 |
| 114 | + id: find-comment |
| 115 | + with: |
| 116 | + issue-number: ${{ github.event.pull_request.number }} |
| 117 | + comment-author: "github-actions[bot]" |
| 118 | + body-includes: "Helm Chart Prerelease Published" |
| 119 | + |
| 120 | + - name: Create or update PR comment |
| 121 | + uses: peter-evans/create-or-update-comment@v4 |
| 122 | + with: |
| 123 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 124 | + issue-number: ${{ github.event.pull_request.number }} |
| 125 | + body: | |
| 126 | + ### 🧭 Helm Chart Prerelease Published |
| 127 | +
|
| 128 | + **Version:** `${{ steps.version.outputs.version }}` |
| 129 | +
|
| 130 | + **Install:** |
| 131 | + ```bash |
| 132 | + helm upgrade --install trigger \ |
| 133 | + oci://ghcr.io/${{ github.repository_owner }}/charts/trigger \ |
| 134 | + --version "${{ steps.version.outputs.version }}" |
| 135 | + ``` |
| 136 | +
|
| 137 | + > ⚠️ This is a prerelease for testing. Do not use in production. |
| 138 | + edit-mode: replace |
0 commit comments