-
Notifications
You must be signed in to change notification settings - Fork 9
189 lines (186 loc) · 5.76 KB
/
build.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
name: Build
on:
push:
branches:
- main
tags:
- v*
pull_request:
jobs:
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Hard-coding version due to this bug: https://github.com/golangci/golangci-lint-action/issues/535
version: v1.52.2
test:
name: go test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4
with:
go-version: 1.18
- name: Set up gotestfmt
uses: GoTestTools/gotestfmt-action@v2
- uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: go-test-${{ hashFiles('**/go.sum') }}
restore-keys: go-test-
- name: Run go test
run: |
set -euo pipefail
go generate
go test -coverprofile /tmp/coverage.out -json -v ./... 2>&1 | tee /tmp/gotest.log | gotestfmt
echo "# Code coverage summary" > /tmp/coverage.md
echo "|File|Type|Coverage|" >> /tmp/coverage.md
echo "|----|----|--------|" >> /tmp/coverage.md
go tool cover -func /tmp/coverage.out | sed -e 's/\s\s*/|/g' -e 's/^/|/g' -e 's/$/|/g' >> /tmp/coverage.md
cat /tmp/coverage.md >> $GITHUB_STEP_SUMMARY
echo "::group::Code coverage summary"
go tool cover -func /tmp/coverage.out
echo "::endgroup::"
- name: Upload test log
uses: actions/upload-artifact@v3
if: always()
with:
name: test-results
path: |
/tmp/gotest.log
/tmp/coverage.out
/tmp/coverage.md
if-no-files-found: error
generate:
name: go generate
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4
with:
go-version: 1.18
- uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: go-test-${{ hashFiles('**/go.sum') }}
restore-keys: go-generate-
- name: Run go generate
run: ./.github/scripts/gogenerate.sh
release:
name: release
runs-on: ubuntu-latest
permissions:
contents: write
needs:
- golangci-lint
- test
- generate
steps:
- name: Checkout
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4
with:
go-version: 1.18
- name: Login to Quay.io
uses: docker/login-action@v2
if: startsWith(github.event.ref, 'refs/tags/')
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Build and release
uses: goreleaser/goreleaser-action@v4
if: startsWith(github.event.ref, 'refs/tags/')
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOPROXY: direct
GOSUMDB: off
- name: Build
uses: goreleaser/goreleaser-action@v4
if: ${{ !startsWith(github.event.ref, 'refs/tags/') }}
with:
distribution: goreleaser
version: latest
args: build --snapshot
env:
GOPROXY: direct
GOSUMDB: off
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: binaries
path: dist
build_python_wheel:
name: build python wheel
runs-on: ubuntu-latest
needs:
- release
steps:
- name: version format check
if: startsWith(github.event.ref, 'refs/tags/')
shell: bash
env:
VERSION: ${{ github.ref_name }}
run: |
[[ ${VERSION//[[:blank:]]/} =~ ^v[[:digit:]]+\.[[:digit:]]\.[[:digit:]]$ ]] && export OK="[INF] version format accepted"
[[ -z $OK ]] && echo "[ERR] wrong version format: $VERSION" && exit 1
echo $OK
- name: Check out code
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
- uses: actions/download-artifact@v3
with:
name: binaries
path: python/artifacts
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
architecture: 'x64'
- name: Grab the License file
run: |
cp LICENSE python/
- name: Fetch python dependencies
working-directory: python
shell: bash
run: |
make setup
- name: Bump version
working-directory: python
if: startsWith(github.event.ref, 'refs/tags/')
env:
VERSION: ${{ github.ref_name }}
shell: bash
run: |
sed -ri "s/^(.+version=')(.+)('.*)/\1${VERSION/v/}\3/g" setup.py
- name: Build python wheel
working-directory: python
run: |
make all
- name: Push to pypi
working-directory: python
if: startsWith(github.event.ref, 'refs/tags/')
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{secrets.PYPI_TOKEN}}
run: |
twine upload dist/*