-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (197 loc) · 6.91 KB
/
golang.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
name: Golang
concurrency:
group: ${{ github.ref_name }}-go
cancel-in-progress: true
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# updated CHANGELOG back to the repository.
# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
contents: write
on:
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
proto:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
if: ${{ github.event_name == 'pull_request' }}
with:
ref: ${{github.event.pull_request.head.ref}}
- uses: actions/checkout@v4
if: ${{ github.event_name != 'pull_request' }}
- run: git config --global url.https://[email protected]/.insteadOf https://github.com/
- uses: bufbuild/buf-setup-action@v1
- uses: bufbuild/buf-lint-action@v1
with:
input: "proto"
# on main there are no protos... so it cannot work for now
# - uses: bufbuild/buf-breaking-action@v1
# with:
# # The 'main' branch of the GitHub repository that defines the module.
# against: "https://github.com/${GITHUB_REPOSITORY}.git#branch=main"
# input: "proto"
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
- name: Clone and build proto-gen-md-diagrams
run: |
cd ..
git clone https://github.com/GoogleCloudPlatform/proto-gen-md-diagrams
cd proto-gen-md-diagrams
go build
- name: Generate docs
run: |
cd ..
cd protobuf
../proto-gen-md-diagrams/proto-gen-md-diagrams -d proto
ls -la
ls -la proto/fault/v1
mkdir -p docs
ls -la
ls -la docs
mv -f ./proto/**/*.md docs
ls -la docs
- name: Generating protos
run: |
buf generate
# - name: Commit buf changes
# run: |
# git config --global user.name 'Bot'
# git config --global user.email '[email protected]'
# git add --all && git commit -m "Buf re-generated protos" || echo "No changes to commit"
# git push
lint:
needs: proto
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ["1.21"]
env:
GOPRIVATE: github.com/zaphiro-technologies/*
GH_ACCESS_TOKEN: ${{ secrets.REPO_PRIVATE_READ_PAT }}
steps:
- uses: actions/checkout@v4
if: ${{ github.event_name == 'pull_request' }}
with:
ref: ${{github.event.pull_request.head.ref}}
- uses: actions/checkout@v4
if: ${{ github.event_name != 'pull_request' }}
- run: git config --global url.https://[email protected]/.insteadOf https://github.com/
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Golines
if: ${{ github.event_name == 'pull_request' }}
run: |
go install github.com/segmentio/golines@latest
golines . -w
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: --fix
version: latest
skip-pkg-cache: true
- name: Commit golines & golangci-lint changes
if: ${{ github.event_name == 'pull_request' }}
run: |
git config --global user.name 'Bot'
git config --global user.email '[email protected]'
git commit -am "Automated lint fixes" || echo "No changes to commit"
git push
test:
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ["1.21"]
env:
GOPRIVATE: github.com/zaphiro-technologies/*
GH_ACCESS_TOKEN: ${{ secrets.REPO_PRIVATE_READ_PAT }}
steps:
- uses: actions/checkout@v4
- run: git config --global url.https://[email protected]/.insteadOf https://github.com/
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Install gcov2lcov
run: |
go install github.com/jandelgado/gcov2lcov@latest
- name: Test
run: |
mkdir coverage
go test ./... -coverprofile=./coverage/coverage.out && \
gcov2lcov -infile=./coverage/coverage.out -outfile=./coverage/lcov.info
- name: Test main
run: |
git fetch origin main --depth 1
git checkout origin/main
export myarray=(`find ./ -maxdepth 3 -name "*.go"`)
if [ ${#myarray[@]} -gt 0 ]; then
go test ./... -coverprofile=./coverage/base-coverage.out && \
gcov2lcov -infile=./coverage/base-coverage.out -outfile=./coverage/base-lcov.info
else
touch ./coverage/base-lcov.info
echo "end_of_record" >> ./coverage/base-lcov.info
fi
- name: Generate Code Coverage report
id: code-coverage
uses: barecheck/code-coverage-action@v1
with:
barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
lcov-file: "./coverage/lcov.info"
base-lcov-file: "./coverage/base-lcov.info"
minimum-ratio: 70
send-summary-comment: true
show-annotations: "warning"
benchmark:
needs: test
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ["1.21"]
env:
GOPRIVATE: github.com/zaphiro-technologies/*
GH_ACCESS_TOKEN: ${{ secrets.REPO_PRIVATE_READ_PAT }}
steps:
- uses: actions/checkout@v4
- run: git config --global url.https://[email protected]/.insteadOf https://github.com/
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
# Run benchmark with `go test -bench` and stores the output to a file
- name: Run benchmark
run: |
set -euxo pipefail
go test ./... -bench 'Benchmark' -run ^$ | tee output.txt
# Download previous benchmark result from cache (if exists)
- name: Download previous benchmark data
uses: actions/cache@v3
with:
path: ./cache
key: ${{ runner.os }}-benchmark
# Run `github-action-benchmark` action
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
# What benchmark tool the output.txt came from
tool: "go"
# Where the output from the benchmark tool is stored
output-file-path: output.txt
# Where the previous data file is stored
external-data-json-path: ./cache/benchmark-data.json
# Workflow will fail when an alert happens
fail-on-alert: true
# Enable alert commit comment
comment-on-alert: true
github-token: ${{ secrets.GITHUB_TOKEN }}
alert-threshold: 150%
summary-always: true