-
Notifications
You must be signed in to change notification settings - Fork 4
182 lines (162 loc) · 6.32 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
name: release
on:
push:
tags:
- "v*.*.*"
jobs:
build-and-run-tests:
name: Build & run tests
runs-on: ubuntu-latest
steps:
- name: Checkout
# https://github.com/actions/checkout/tree/v4.1.1
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Get GO version
id: goversion
run: echo "goversion=$(<.goversion)" > "${GITHUB_OUTPUT}"
- name: Set up Go
# https://github.com/actions/setup-go/tree/v5.0.0
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version: ${{steps.goversion.outputs.goversion}}
- name: Generate files
run: go generate ./...
- name: Build
run: go build ./...
- name: Run go vet
run: go vet ./...
- name: Run go tests
run: go test -failfast ./...
- name: Run go tests (noquic)
run: go test -failfast -tags noquic ./...
- name: Run go tests (-race)
run: go test -race -timeout=5m -failfast ./...
- name: Run govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest && govulncheck ./...
- name: Build test docker image
run: |
touch version.sh
docker build -t c2fmzq/tlsproxy:test .
docker run --rm --interactive c2fmzq/tlsproxy:test -v
create-release:
name: Create release
needs: build-and-run-tests
runs-on: ubuntu-latest
steps:
- name: Checkout
# https://github.com/actions/checkout/tree/v4.1.1
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Get GO version
id: goversion
run: echo "goversion=$(<.goversion)" > "${GITHUB_OUTPUT}"
- name: Set up Go
# https://github.com/actions/setup-go/tree/v5.0.0
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version: ${{steps.goversion.outputs.goversion}}
- name: Extract release notes
run: |
./scripts/release-notes.sh "${GITHUB_REF_NAME}" > release-notes.md
if [[ $(stat -c %s release-notes.md) == 0 ]]; then
echo "No release notes for ${GITHUB_REF_NAME}. Please update CHANGELOG.md"
exit 1
fi
- name: Build release binaries
run: |
export GNUPGHOME="$(mktemp -d)"
chmod 700 "${GNUPGHOME}"
cleanup() {
rm -rf "${GNUPGHOME}"
}
trap cleanup EXIT
# The key is generated with:
# GPG_PASSPHRASE=$(dd if=/dev/random bs=32 count=1 | base64)
# gpg --passphrase "${GPG_PASSPHRASE}" --quick-generate-key c2FmZQ-bot ed25519 sign never
# gpg --local-user [email protected] --sign-key c2FmZQ-bot
# gpg --armor --export c2FmZQ-bot > keys/c2FmZQ-bot.pub
# gpg --passphrase "${GPG_PASSPHRASE}" --armor --export-secret-keys c2FmZQ-bot | base64 -w0
echo "${GPG_PRIVATE_KEY}" | base64 -d | gpg --batch --pinentry-mode loopback --passphrase "${GPG_PASSPHRASE}" --import
./scripts/build-release-binaries.sh
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
- name: Create release
# https://github.com/softprops/action-gh-release/releases/tag/v2.0.4
uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564
with:
token: ${{ secrets.UPDATE_TOKEN }}
draft: false
prerelease: ${{ contains(github.ref, '-') }}
body_path: release-notes.md
fail_on_unmatched_files: true
files: bin/*
push-to-registry:
name: Push image to docker hub
needs:
- build-and-run-tests
- create-release
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Check out the repo
# https://github.com/actions/checkout/tree/v4.1.1
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Install cosign
# https://github.com/sigstore/cosign-installer/releases/tag/v3.4.0
uses: sigstore/cosign-installer@e1523de7571e31dbe865fd2e80c5c7c23ae71eb4
- name: Cosign version
run: cosign version
- name: Log in to docker hub
# https://github.com/docker/login-action/tree/v3.0.0
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Check golang image
run: ./scripts/check-golang-image.sh
- name: Get release version
run: |
echo "VERSION=${GITHUB_REF_NAME}" > version.sh
echo "BUILD_TAGS='$(echo ${GITHUB_REF_NAME} | sed -re 's/^v[^+]+[+]?//' -e 's/[.]/,/g')'" >> version.sh
- name: Set up QEMU
# https://github.com/docker/setup-qemu-action/releases/tag/v3.0.0
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3
- name: Set up Docker Buildx
# https://github.com/docker/setup-buildx-action/releases/tag/v3.0.0
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226
- name: Extract metadata (tags, labels) for Docker
id: meta
# https://github.com/docker/metadata-action/releases/tag/v5.0.0
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934
with:
images: c2fmzq/tlsproxy
flavor: ${{ (contains(github.ref, '+') || contains(github.ref, '-')) && 'latest=false' || 'latest=auto' }}
- name: Build and push docker image
# https://github.com/docker/build-push-action/releases/tag/v5.1.0
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
id: build-and-push
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Sign docker image
run: |
images=""
for tag in ${TAGS}; do
images+="${tag}@${DIGEST} "
done
# Sign with key
cosign sign --yes --key env://COSIGN_PRIVATE_KEY ${images}
# Sign with oidc
unset COSIGN_PRIVATE_KEY COSIGN_PASSWORD
cosign sign --yes ${images}
env:
TAGS: ${{ steps.meta.outputs.tags }}
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}