1313 GO_VERSION : ' 1.25.1'
1414
1515jobs :
16- release :
17- name : Build and Push
16+ build-image :
17+ name : Build and Push Image
1818 runs-on : ubuntu-latest
19- # Don't run on PRs, only on direct pushes to main or tags
2019 if : github.event_name == 'push'
2120 permissions :
2221 contents : read
2322 packages : write
24- id-token : write # For cosign signing
23+ id-token : write
24+ outputs :
25+ digest : ${{ steps.build.outputs.digest }}
26+ tags : ${{ steps.meta.outputs.tags }}
27+ version : ${{ steps.version.outputs.version }}
2528 steps :
2629 - name : Checkout code
2730 uses : actions/checkout@v4
@@ -34,11 +37,24 @@ jobs:
3437 - name : Cache Go modules
3538 uses : actions/cache@v4
3639 with :
37- path : ~/go/pkg/mod
40+ path : |
41+ ~/go/pkg/mod
42+ ~/.cache/go-build
3843 key : ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
3944 restore-keys : |
4045 ${{ runner.os }}-go-
4146
47+ - name : Extract version
48+ id : version
49+ run : |
50+ if [[ "${{ github.ref_type }}" == "tag" ]]; then
51+ VERSION="${{ github.ref_name }}"
52+ VERSION="${VERSION#v}"
53+ else
54+ VERSION="0.0.0-dev"
55+ fi
56+ echo "version=$VERSION" >> $GITHUB_OUTPUT
57+ echo "Version: $VERSION"
4258
4359 - name : Set up QEMU
4460 uses : docker/setup-qemu-action@v3
7793 labels : ${{ steps.meta.outputs.labels }}
7894 cache-from : type=gha
7995 cache-to : type=gha,mode=max
96+ provenance : false
97+ sbom : false
8098 build-args : |
8199 GO_VERSION=${{ env.GO_VERSION }}
82100
88106 fi
89107 echo "✅ Docker build successful with digest: ${{ steps.build.outputs.digest }}"
90108
91- # Image signing
92109 - name : Install cosign
9311094111
@@ -100,30 +117,95 @@ jobs:
100117 echo "$TAGS" | while IFS= read -r tag; do
101118 if [[ -n "$tag" ]]; then
102119 echo "Signing: $tag@${DIGEST}"
103- if ! cosign sign --yes "$tag@${DIGEST}"; then
104- echo "First attempt failed, retrying in 10 seconds..."
105- sleep 10
106- if ! cosign sign --yes "$tag@${DIGEST}"; then
107- echo "❌ Failed to sign $tag after retry"
108- echo "::warning::Failed to sign image $tag - continuing with unsigned image"
109- else
110- echo "✅ Successfully signed $tag on retry"
111- fi
112- else
113- echo "✅ Successfully signed $tag"
114- fi
120+ cosign sign --yes "$tag@${DIGEST}" || echo "::warning::Failed to sign image $tag"
115121 fi
116122 done
117123
118- - name : Generate SBOM
119- 124+ release-helm :
125+ name : Release Helm Chart
126+ runs-on : ubuntu-latest
127+ needs : build-image
128+ permissions :
129+ contents : read
130+ packages : write
131+ steps :
132+ - name : Checkout code
133+ uses : actions/checkout@v4
134+
135+ - name : Set up Helm
136+ uses : azure/setup-helm@v4
120137 with :
121- image : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}
122- format : spdx-json
123- output-file : sbom.spdx.json
138+ version : v3.17.0
139+
140+ - name : Log in to GHCR for Helm
141+ run : |
142+ echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ${{ env.REGISTRY }} --username ${{ github.actor }} --password-stdin
143+
144+ - name : Update Helm chart with image digest
145+ if : github.ref_type == 'tag'
146+ run : |
147+ DIGEST="${{ needs.build-image.outputs.digest }}"
148+ VERSION="${{ needs.build-image.outputs.version }}"
124149
125- - name : Upload SBOM
126- uses : actions/upload-artifact@v4
150+ # Update values.yaml with digest
151+ sed -i "s|tag:.*|digest: \"$DIGEST\"|g" charts/homer-operator/values.yaml
152+
153+ # Update Chart.yaml version
154+ sed -i "s|^version:.*|version: $VERSION|g" charts/homer-operator/Chart.yaml
155+ sed -i "s|^appVersion:.*|appVersion: $VERSION|g" charts/homer-operator/Chart.yaml
156+
157+ - name : Package and push Helm chart
158+ run : |
159+ VERSION="${{ needs.build-image.outputs.version }}"
160+
161+ # Package chart
162+ helm package charts/homer-operator --version "$VERSION"
163+
164+ # Push to GHCR
165+ helm push homer-operator-${VERSION}.tgz oci://${{ env.REGISTRY }}/${{ github.repository }}/charts
166+
167+ create-github-release :
168+ name : Create GitHub Release
169+ runs-on : ubuntu-latest
170+ if : github.ref_type == 'tag'
171+ needs : [build-image, release-helm]
172+ permissions :
173+ contents : write
174+ steps :
175+ - name : Checkout code
176+ uses : actions/checkout@v4
177+
178+ - name : Generate release notes
179+ id : notes
180+ run : |
181+ VERSION="${{ needs.build-image.outputs.version }}"
182+ DIGEST="${{ needs.build-image.outputs.digest }}"
183+
184+ cat > release-notes.md <<EOF
185+ ## Homer Operator $VERSION
186+
187+ ### Container Image
188+ \`\`\`
189+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$VERSION
190+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@$DIGEST
191+ \`\`\`
192+
193+ ### Helm Chart
194+ \`\`\`bash
195+ helm install homer-operator oci://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/charts/homer-operator --version $VERSION
196+ \`\`\`
197+
198+ ### Verification
199+ \`\`\`bash
200+ # Verify image signature
201+ cosign verify ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@$DIGEST
202+ \`\`\`
203+ EOF
204+
205+ - name : Create GitHub Release
206+ uses : softprops/action-gh-release@v2
127207 with :
128- name : sbom
129- path : sbom.spdx.json
208+ body_path : release-notes.md
209+ draft : false
210+ prerelease : false
211+ generate_release_notes : true
0 commit comments