-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (147 loc) · 4.52 KB
/
ci.yml
File metadata and controls
178 lines (147 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: ci
on:
push:
branches: ["develop"]
tags: ["v*"]
pull_request:
permissions:
contents: read
jobs:
go:
name: go (vet, build)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@main
with:
submodules: true
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.23.x"
cache: true
- name: Verify gofmt
run: |
files=$(gofmt -l .)
if [ -n "$files" ]; then
echo "gofmt needed on:"
echo "$files"
exit 1
fi
- name: Tidy check (no diff)
run: |
go mod tidy
git diff --exit-code
- name: Vet
run: go vet ./...
- name: Build
run: go build -trimpath -ldflags="-s -w" -o cacheppuccino .
docker:
name: docker (build and push)
runs-on: ubuntu-latest
needs: [go]
permissions:
contents: read
packages: write
outputs:
docker_image_tag: ${{ steps.meta.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@main
with:
submodules: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=short,prefix=0.1.0-c
type=ref,event=tag
- name: Build and push docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
helm:
name: helm (package and push)
runs-on: ubuntu-latest
needs: [docker]
# if: github.event_name != 'pull_request'
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@main
with:
submodules: true
- name: Setup Helm
uses: azure/setup-helm@v4
with:
version: v3.15.4
- name: Determine chart version
id: ver
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
# Tag format: v0.1.0 -> 0.1.0
VERSION="${GITHUB_REF_NAME#v}"
else
# Unique semver prerelease for main pushes
SHORT_SHA="$(echo "${GITHUB_SHA}" | cut -c1-7)"
VERSION="0.1.0-c${SHORT_SHA}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Login to GHCR (Helm OCI)
shell: bash
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io -u "${{ github.actor }}" --password-stdin
- name: Lint chart
run: helm lint helm
- name: 🐳 Helm template (snapshot)
run: ./helm/update-snapshots.sh --check-diff-only
- name: Tag docker image in Helm Chart values.yaml
working-directory: helm
env:
IMAGE_TAG: ${{ needs.docker.outputs.docker_image_tag }}
run: |
# Update values.yaml with latest docker image
sed -i "s/SET-BY-CICD-TAG/$IMAGE_TAG/" ./values.yaml
- name: Package chart
shell: bash
run: |
set -euo pipefail
mkdir -p dist
helm package helm \
--destination dist \
--version "${{ steps.ver.outputs.version }}" \
--app-version "${{ steps.ver.outputs.version }}"
- name: Push chart to GHCR (OCI)
shell: bash
run: |
set -euo pipefail
OWNER_LC="$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')"
OCI_REPO="oci://ghcr.io/${OWNER_LC}"
PACKAGE_FILE="$(ls -1 dist/cacheppuccino-*.tgz | head -n 1)"
IMAGE="${{ needs.docker.outputs.docker_image_tag }}"
# Add GitHub Actions summary
echo "# Helm Chart" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```yaml' >> $GITHUB_STEP_SUMMARY
helm push "$PACKAGE_FILE" "$OCI_REPO" 2>> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY