-
-
Notifications
You must be signed in to change notification settings - Fork 6
211 lines (189 loc) · 7.89 KB
/
release.yml
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
---
name: Release
on:
push:
tags:
- 'v*.*.*'
jobs:
release:
name: Create release and upload binaries
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
strategy:
matrix:
target:
- "linux:arm64:"
- "linux:arm:"
- "linux:amd64:"
- "darwin:arm64:"
- "darwin:amd64:"
- "windows:amd64:.exe"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.21"
- name: Prepare
id: prep
run: |-
PRE_RELEASE=false
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
if [[ $VERSION =~ ^*-pre$ ]]; then
PRE_RELEASE=true
fi
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=buildtime::$(date -u +'%FT%TZ%:z')
echo ::set-output name=pre::${PRE_RELEASE}
echo ::set-output name=go-version::$(go version | sed -r 's/go version go(.+)\s.+/\1/')
- name: Cache
id: cache
uses: actions/cache@v2
with:
path: |-
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |-
${{ runner.os }}-go-
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |-
go mod download
- name: Build
run: |-
export GOOS="$(echo ${{ matrix.target }} | cut -d':' -f1)"
export GOARCH="$(echo ${{ matrix.target }} | cut -d':' -f2)"
export EXT="$(echo ${{ matrix.target }} | cut -d':' -f3)"
if [ $GOARCH = arm ]; then
go build \
-trimpath \
-mod=readonly \
-modcacherw \
-o ${{ secrets.APP_NAME }}.${GOOS}.${GOARCH} \
-ldflags "\
-X ${{ github.repository }}/version.APPNAME=${{ secrets.APP_NAME }} \
-X ${{ github.repository }}/version.VERSION=${{ steps.prep.outputs.version }} \
-X ${{ github.repository }}/version.GOVERSION=${{ steps.prep.outputs.go-version }} \
-X ${{ github.repository }}/version.BUILDTIME=${{ steps.prep.outputs.buildtime }} \
-X ${{ github.repository }}/version.COMMITHASH=${{ github.sha }} \
-s -w"
else
go build \
-trimpath \
-buildmode=pie \
-mod=readonly \
-modcacherw \
-o ${{ secrets.APP_NAME }}.${GOOS}.${GOARCH} \
-ldflags "\
-X ${{ github.repository }}/version.APPNAME=${{ secrets.APP_NAME }} \
-X ${{ github.repository }}/version.VERSION=${{ steps.prep.outputs.version }} \
-X ${{ github.repository }}/version.GOVERSION=${{ steps.prep.outputs.go-version }} \
-X ${{ github.repository }}/version.BUILDTIME=${{ steps.prep.outputs.buildtime }} \
-X ${{ github.repository }}/version.COMMITHASH=${{ github.sha }} \
-s -w"
fi
if [ ! -z "${EXT}" ]; then
mv ${{ secrets.APP_NAME }}.${GOOS}.${GOARCH} ${{ secrets.APP_NAME }}${EXT}
sha256sum ${{ secrets.APP_NAME }}${EXT} > ${{ secrets.APP_NAME }}${EXT}.sha256sum.txt
else
sha256sum ${{ secrets.APP_NAME }}.${GOOS}.${GOARCH} > ${{ secrets.APP_NAME }}.${GOOS}.${GOARCH}.sha256sum.txt
fi
- name: Extract release notes
id: extract-release-notes
uses: ffurrer2/extract-release-notes@v1
- name: Upload binary and sum file
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ secrets.APP_NAME }}.*
file_glob: true
tag: ${{ github.ref }}
overwrite: true
release_name: ${{ steps.prep.outputs.version }}
body: ${{ steps.extract-release-notes.outputs.release_notes }}
prerelease: steps.prep.outputs.pre != 'false'
docker:
name: Release Docker Images
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare
id: prep
run: |-
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
if [[ $VERSION =~ ^v([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
TAGS="${{ secrets.DOCKER_IMAGE }}:latest"
TAGS="${TAGS},${{ secrets.DOCKER_IMAGE }}:v${MAJOR}"
TAGS="${TAGS},${{ secrets.DOCKER_IMAGE }}:v${MAJOR}.${MINOR}"
TAGS="${TAGS},${{ secrets.DOCKER_IMAGE }}:v${MAJOR}.${MINOR}.${PATCH}"
TAGS="${TAGS},${{ secrets.QUAY_IMAGE }}:latest"
TAGS="${TAGS},${{ secrets.QUAY_IMAGE }}:v${MAJOR}"
TAGS="${TAGS},${{ secrets.QUAY_IMAGE }}:v${MAJOR}.${MINOR}"
TAGS="${TAGS},${{ secrets.QUAY_IMAGE }}:v${MAJOR}.${MINOR}.${PATCH}"
else
TAGS="${{ secrets.DOCKER_IMAGE }}:${VERSION}"
TAGS="${TAGS},${{ secrets.QUAY_IMAGE }}:${VERSION}"
fi
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=edge
fi
TAGS="${{ secrets.DOCKER_IMAGE }}:${VERSION}"
TAGS="${TAGS},${{ secrets.QUAY_IMAGE }}:${VERSION}"
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
TAGS="${{ secrets.DOCKER_IMAGE }}:${VERSION}"
TAGS="${TAGS},${{ secrets.QUAY_IMAGE }}:${VERSION}"
fi
echo ::set-output name=tags::${TAGS}
echo ::set-output name=version::${VERSION}
echo ::set-output name=buildtime::$(date -u +'%FT%TZ%:z')
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to docker container registry
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
- name: Login to quay container registry
uses: docker/login-action@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_REGISTRY_USERNAME }}
password: ${{ secrets.QUAY_REGISTRY_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: ${{ steps.prep.outputs.tags }}
build-args: |-
APPNAME=${{ secrets.APP_NAME }}
PKG=${{ github.repository }}
VERSION=${{ steps.prep.outputs.version }}
COMMITHASH=${{ github.sha }}
BUILDTIME=${{ steps.prep.outputs.buildtime }}
labels: |-
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}