-
Notifications
You must be signed in to change notification settings - Fork 1
257 lines (218 loc) · 7.3 KB
/
ci.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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
name: ci
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
Test:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create Cache Timestamp
id: cache_timestamp
uses: nanzm/[email protected]
with:
format: 'YYYY-MM-DD-HH-mm-ss'
- name: Mount bazel cache
uses: actions/cache@v4
with:
path: "~/.cache/bazel"
key: bazelcache_test_${{ steps.cache_timestamp.outputs.time }}
restore-keys: bazelcache_test_
- name: Test
run: |
export CC=gcc-13
export CXX=g++-13
bazel test --noshow_progress --keep_going ...
MacOsBuild:
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Test
run: |
bazel test --noshow_progress --keep_going ...
- name: Build
run: |
bazel build --noshow_progress -c opt bant:bant
bazel-bin/bant/bant -V # Print version
# TODO: package ?
WindowsBuild:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Test
run: |
bazel test --noshow_progress --keep_going ...
- name: Build
run: |
bazel build --noshow_progress -c opt bant:bant
bazel-bin/bant/bant -V # Print version
# TODO: package ?
CodeFormatting:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Dependencies
run: |
go install github.com/bazelbuild/buildtools/buildifier@latest
echo "PATH=$PATH:$(go env GOPATH)/bin/" >> $GITHUB_ENV
- name: Run formatting style check
run: |
clang-format-17 --version
CLANG_FORMAT=clang-format-17 scripts/run-format.sh
git diff > /tmp/format-diff
if [ -s "/tmp/format-diff" ]; then
echo "Difference to optimal formatting"
cat /tmp/format-diff
echo
echo "=================== To Fix ==========================="
echo "Run scripts/run-format.sh"
echo "then"
echo " git commit -a --amend"
echo " git push -f"
exit 1
fi
RunBantOnBant:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build Project genrules
run: |
# Genrules for bant to see every file.
bazel build //bant:version-header
- name: Get Bant
run: |
# TODO: provide this as action where we simply say with version=...
VERSION="v0.1.9"
STATIC_VERSION="bant-${VERSION}-linux-static-x86_64"
wget "https://github.com/hzeller/bant/releases/download/${VERSION}/${STATIC_VERSION}.tar.gz"
tar xvzf "${STATIC_VERSION}.tar.gz"
mkdir -p bin
ln -sf ../"${STATIC_VERSION}/bin/bant" bin/
bin/bant -V
- name: Run bant on bant
run: |
bin/bant dwyu ...
ClangTidy:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Dependencies
run: |
sudo apt-get install clang-tidy-18
- name: Create Cache Timestamp
id: cache_timestamp
uses: nanzm/[email protected]
with:
format: 'YYYY-MM-DD-HH-mm-ss'
- name: Mount clang-tidy cache
uses: actions/cache@v4
with:
path: |
~/.cache/clang-tidy
~/.cache/bazel
key: clang-tidy-cache_${{ steps.cache_timestamp.outputs.time }}
restore-keys: clang-tidy-cache_
- name: Build Compilation DB
run: |
scripts/make-compilation-db.sh
- name: Run clang-tidy
run: |
clang-tidy-18 --version
CLANG_TIDY=clang-tidy-18 scripts/run-clang-tidy-cached.cc \
|| ( cat bant_clang-tidy.out ; exit 1)
# TODO: can this be done _after_ the tagging had taken place ?
BuildStaticBinary:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create Cache Timestamp
id: cache_timestamp
uses: nanzm/[email protected]
with:
format: 'YYYY-MM-DD-HH-mm-ss'
- name: Mount bazel cache
uses: actions/cache@v4
with:
path: "~/.cache/bazel"
key: bazelcache_release_${{ steps.cache_timestamp.outputs.time }}
restore-keys: bazelcache_release_
- name: Build
run: |
export CC=gcc-13
export CXX=g++-13
bazel build --noshow_progress -c opt --//bant:create_static_linked_executables bant:bant
bazel-bin/bant/bant -V # Print version
# Version number: current tag dot number of commits after tagging.
# If at exactly a tag, that will be left as-is
VERSION=$(git describe --match=v* 2>/dev/null \
| sed 's/v\([^-]*\)-\([0-9]*\)-.*/v\1-\2/')
OUT=bant-${VERSION}-linux-static-x86_64
echo "OUT=${OUT}" >> $GITHUB_ENV
mkdir -p "${OUT}/bin"
install bazel-bin/bant/bant "${OUT}/bin"
strip "${OUT}/bin/bant"
# We need to pack it with with tar to retain proper unix permissions.
# Unfortunately, github then re-packs the result into a *.zip archive.
tar cvzf "${OUT}.tar.gz" ${OUT}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.OUT }}
path: ${{ env.OUT }}.tar.gz
release-tagging:
name: Version Tagging
runs-on: ubuntu-24.04
if: ${{github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/main')}}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Tag with MODULES.bazel version if not already.
run: |
version_from_module_bazel() {
git annotate -l MODULE.bazel \
| awk '/module/ { in_module=1; }
/version/ { if (in_module) { print $0; nextfile; } }' \
| sed 's/\(^[0-9a-f]*\).*version[ ]*=[ ]*"\([0-9.]*\)".*/\1 \2/p;d'
}
git config --local user.name "Development Bot"
git config --local user.email "[email protected]"
# We want to tag whenever the version in MODULE.bazel changes.
# So extract the hash of when the current version was entered.
read TAG_HASH TAG_VERSION <<<$(version_from_module_bazel)
echo "Bant Version v${TAG_VERSION} at hash ${TAG_HASH}"
# If this is the first time we see this tag: apply.
if [ -z "$(git tag -l "v${TAG_VERSION}")" ]; then
git tag -a "v${TAG_VERSION}" ${TAG_HASH} -m "Update to v${TAG_VERSION}"
git push origin "v${TAG_VERSION}"
else
echo "Tag already applied"
fi