Skip to content

Commit 73eef38

Browse files
committed
Refactor CI and release workflows for improved caching and versioning
- Removed push trigger from CI workflow, focusing on pull requests. - Enhanced caching in CI and release workflows by adding ~/.cache/go-build. - Updated release workflow to include version extraction and Helm chart updates. - Simplified image signing process and removed redundant SBOM generation steps. - Added steps for creating GitHub releases with generated release notes.
1 parent aa6a525 commit 73eef38

File tree

3 files changed

+115
-35
lines changed

3 files changed

+115
-35
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: CI
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
- 'release/*'
84
pull_request:
95
branches:
106
- main
@@ -30,7 +26,9 @@ jobs:
3026
- name: Cache Go modules
3127
uses: actions/cache@v4
3228
with:
33-
path: ~/go/pkg/mod
29+
path: |
30+
~/go/pkg/mod
31+
~/.cache/go-build
3432
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
3533
restore-keys: |
3634
${{ runner.os }}-go-
@@ -76,7 +74,9 @@ jobs:
7674
- name: Cache Go modules
7775
uses: actions/cache@v4
7876
with:
79-
path: ~/go/pkg/mod
77+
path: |
78+
~/go/pkg/mod
79+
~/.cache/go-build
8080
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
8181
restore-keys: |
8282
${{ runner.os }}-go-

.github/workflows/release.yml

Lines changed: 109 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ env:
1313
GO_VERSION: '1.25.1'
1414

1515
jobs:
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
@@ -77,6 +93,8 @@ jobs:
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
@@ -88,7 +106,6 @@ jobs:
88106
fi
89107
echo "✅ Docker build successful with digest: ${{ steps.build.outputs.digest }}"
90108
91-
# Image signing
92109
- name: Install cosign
93110
uses: sigstore/[email protected]
94111

@@ -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-
uses: anchore/[email protected]
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

api/v1alpha1/dashboard_types_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ func TestDashboardSpecValidation(t *testing.T) {
160160
}
161161
}
162162
}
163-
164163
})
165164
}
166165
}
@@ -349,7 +348,6 @@ func TestDashboardCreation(t *testing.T) {
349348
if dashboard.Spec.HealthCheck.Interval != "45s" {
350349
t.Errorf("Expected interval '45s', got '%s'", dashboard.Spec.HealthCheck.Interval)
351350
}
352-
353351
}
354352

355353
// Helper function to create int32 pointer

0 commit comments

Comments
 (0)