-
Notifications
You must be signed in to change notification settings - Fork 0
239 lines (208 loc) · 7.22 KB
/
release.yaml
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
name: Release
on:
push:
tags:
- '*'
permissions:
contents: write
packages: write
env:
IMAGE_NAME: cardano-validator-watcher
BINARY_NAME: cardano-validator-watcher
CHART_NAME: cardano-validator-watcher
CHART_DIRECTORY: charts
REGISTRY: oci://ghcr.io/kilnfi/charts
jobs:
binaries:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
arch:
- amd64
- arm64
runs-on: ${{ matrix.os }}
env:
ARCH_NAME: ${{ matrix.arch }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Export Variables
id: export-variables
run: |
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
echo "os_name=linux" >> $GITHUB_OUTPUT
elif [ "${{ matrix.os }}" = "macos-latest" ]; then
echo "os_name=darwin" >> $GITHUB_OUTPUT
fi
- name: Install dependencies
run: |
if [ "$OS_NAME" == "linux" ]; then
sudo apt-get update
if [ "${{ matrix.arch }}" == "amd64" ]; then
sudo apt-get install -y build-essential
elif [ "${{ matrix.arch }}" == "arm64" ]; then
sudo apt install -y build-essential gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
fi
elif [ "$OS_NAME" == "darwin" ]; then
brew update
brew install sqlite
fi
env:
OS_NAME: ${{ steps.export-variables.outputs.os_name }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.23
- name: Build ${{matrix.os}}-${{matrix.arch}} binary
id: build
run: |
OUTPUT_NAME="${{ env.BINARY_NAME }}_${{ github.ref_name }}_${OS_NAME}_${ARCH_NAME}"
OUTPUT_DIR=dist/${OUTPUT_NAME}
ARCHIVE_NAME="${OUTPUT_NAME}.tar.gz"
# debug
echo "OUTPUT_NAME=${OUTPUT_NAME}"
echo "DIR=${OUTPUT_DIR}"
echo "ARCH=${ARCH_NAME}"
echo "ARCH2=${{ env.ARCH_NAME}}"
echo "output_dir=${OUTPUT_DIR}" >> $GITHUB_OUTPUT
mkdir -p ${OUTPUT_DIR}
if [ "${OS_NAME}" = "linux" ] && [ "${ARCH_NAME}" = "arm64" ]; then
export CC=aarch64-linux-gnu-gcc
export CXX=aarch64-linux-gnu-g++
fi
CGO_ENABLED=1 GOOS=$OS_NAME GOARCH=$ARCH_NAME \
go build -ldflags="-s -w" -o ${OUTPUT_DIR}/${{ env.BINARY_NAME }} cmd/watcher/main.go
tar -czvf ${OUTPUT_DIR}/${ARCHIVE_NAME} -C ${OUTPUT_DIR} ${{ env.BINARY_NAME }}
env:
OS_NAME: ${{ steps.export-variables.outputs.os_name }}
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: "${{ env.DIRECTORY }}/*.tar.gz"
tag: ${{ github.ref_name }}
file_glob: true
env:
DIRECTORY: ${{ steps.build.outputs.output_dir }}
images:
needs: binaries
strategy:
matrix:
os:
- ubuntu-latest
arch:
- amd64
- arm64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v6
name: Build & Push Container Images
id: build
with:
context: .
file: Dockerfile
labels: |-
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.name=${{ env.IMAGE_NAME }}
org.opencontainers.image.version=${{ github.ref_name }}
org.opencontainers.image.authors=contact@kiln.fi
platforms: linux/${{matrix.arch}}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |-
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-linux-${{matrix.arch}}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
needs:
- images
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create \
-t "${{ env.REGISTRY_IMAGE }}:latest" \
-t "${{ env.REGISTRY_IMAGE }}:${{ github.ref_name }}" \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
env:
REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:latest
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ github.ref_name }}
env:
REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
helm-chart:
if: false
runs-on: ubuntu-latest
needs: images
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Helm
uses: azure/setup-helm@v4.2.0
with:
version: v3.16.4
- name: Verify Chart Version
run: |
TAG=$(echo ${{ github.ref_name }} | sed 's/v//')
CHART_VERSION=$(yq -r .version ${{ env.CHART_DIRECTORY }}/${{ env.CHART_NAME }}/Chart.yaml)
if [ "$TAG" != "${CHART_VERSION}" ]; then
echo "Version mismatch: release tag ${TAG} does not match Chart.yaml version ${CHART_VERSION}"
exit 1
fi
echo "CHART_VERSION=$CHART_VERSION" >> $GITHUB_ENV
- name: Helm Registry Login
run: |
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io --username ${{ env.USERNAME }} --password-stdin
env:
USERNAME: kilnfi
- name: 'Helm Package'
id: helm-package
run: |
helm package ${{ env.CHART_DIRECTORY }}/${{ env.CHART_NAME }} --version $CHART_VERSION
- name: 'Helm Push'
run: |
helm push ./cardano-validator-watcher-$CHART_VERSION.tgz ${{ env.REGISTRY }}