-
Notifications
You must be signed in to change notification settings - Fork 47
398 lines (391 loc) · 16.6 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
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
alpha_version:
description: 'Alpha version'
default: ''
run-on-runner:
description: 'Specify the runner to use'
required: true
default: 'ARM64'
perf-test:
description: 'Run perf test times'
required: true
default: '0'
schedule:
- cron: '0 0 * * *' # every day at midnight
filters:
branches:
include:
- 'main'
permissions:
actions: 'write'
packages: 'write'
contents: 'write'
name: Build
jobs:
build:
runs-on: ${{ github.event_name == 'push' && 'macos-12' || (github.event.inputs.run-on-runner || 'ARM64') }}
steps:
- name: validate agent
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.run-on-runner }}" != "ARM64" ]]; then
echo "Invalid runner"
exit 1
fi
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.22
if: github.event.inputs.run-on-runner != 'ARM64' && github.event_name != 'schedule'
- name: Setup GO
run: |
go version
echo GOPATH=$(go env GOPATH) >> $GITHUB_ENV
echo GOBIN=$(go env GOPATH)/bin >> $GITHUB_ENV
echo $(go env GOPATH)/bin >> $GITHUB_PATH
- name: Install patched gox
run: |
mkdir -p "$GOPATH/src/github.com/mitchellh"
cd "$GOPATH/src/github.com/mitchellh"
git clone https://github.com/aslakhellesoy/gox
cd gox
git fetch
git checkout db6184738b77fbd5089e5fa1112177f391c91b24
go install github.com/mitchellh/gox
if: github.event.inputs.run-on-runner != 'ARM64' && github.event_name != 'schedule'
- name: Install brew and node deps
run: |
curl https://raw.githubusercontent.com/Homebrew/homebrew-core/31b24d65a7210ea0a5689d5ad00dd8d1bf5211db/Formula/protobuf.rb --output protobuf.rb
curl https://raw.githubusercontent.com/Homebrew/homebrew-core/d600b1f7119f6e6a4e97fb83233b313b0468b7e4/Formula/s/swift-protobuf.rb --output swift-protobuf.rb
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install ./protobuf.rb
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install --ignore-dependencies ./swift-protobuf.rb
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install mingw-w64
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install grpcurl
npm i -g node-gyp
if: github.event.inputs.run-on-runner != 'ARM64' && github.event_name != 'schedule'
- name: Checkout
uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Install old MacOS SDK (for backward compatibility of CGO)
run: source .github/install_macos_sdk.sh 10.15
if: github.event.inputs.run-on-runner != 'ARM64' && github.event_name != 'schedule'
- name: Set env vars
env:
UNSPLASH_KEY: ${{ secrets.UNSPLASH_KEY }}
INHOUSE_KEY: ${{ secrets.INHOUSE_KEY }}
run: |
GIT_SUMMARY=$(git describe --tags --always)
echo "FLAGS=-X github.com/anyproto/anytype-heart/util/vcs.GitSummary=${GIT_SUMMARY} -X github.com/anyproto/anytype-heart/metrics.DefaultInHouseKey=${INHOUSE_KEY} -X github.com/anyproto/anytype-heart/util/unsplash.DefaultToken=${UNSPLASH_KEY}" >> $GITHUB_ENV
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION=${{ github.event.inputs.alpha_version }}
if [ -z "$VERSION" ]; then
VERSION=$(git rev-parse --short HEAD)
fi
fi
if [ -z "$VERSION" ]; then
VERSION=${GITHUB_REF##*/}
fi
echo VERSION=${VERSION} >> $GITHUB_ENV
echo MAVEN_ARTIFACT_VERSION=${VERSION} >> $GITHUB_ENV
echo GOPRIVATE=github.com/anyproto >> $GITHUB_ENV
echo $(pwd)/deps >> $GITHUB_PATH
echo "${GOBIN}" >> $GITHUB_PATH
git config --global url."https://${{ secrets.ANYTYPE_PAT }}@github.com/".insteadOf "https://github.com/"
- name: Go mod download
run: |
go mod download
- name: install protoc
run: |
make setup-protoc
- name: setup go
run: |
make setup-go
make setup-gomobile
which gomobile
- name: Cross-compile library mac/win
run: |
make download-tantivy-all
echo $FLAGS
mkdir -p .release
echo $SDKROOT
gox -cgo -ldflags="$FLAGS" -osarch="darwin/amd64" --tags="envproduction nographviz nowatchdog nosigar nomutexdeadlockdetector" -output="{{.OS}}-{{.Arch}}" github.com/anyproto/anytype-heart/cmd/grpcserver
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
echo $SDKROOT
gox -cgo -ldflags="$FLAGS" -osarch="darwin/arm64" --tags="envproduction nographviz nowatchdog nosigar nomutexdeadlockdetector" -output="{{.OS}}-{{.Arch}}" github.com/anyproto/anytype-heart/cmd/grpcserver
make protos-server
CC="x86_64-w64-mingw32-gcc" CXX="x86_64-w64-mingw32-g++" gox -cgo -ldflags="$FLAGS -linkmode external -extldflags=-static" -osarch="windows/amd64" --tags="envproduction nographviz nowatchdog nosigar nomutexdeadlockdetector noheic" -output="{{.OS}}-{{.Arch}}" github.com/anyproto/anytype-heart/cmd/grpcserver
ls -lha .
- name: run perf tests
run: |
echo "Running perf tests"
make download-tantivy-all
RUN_COUNT=${{ github.event.inputs.perf-test }}
if [[ "${{ github.event_name }}" == "schedule" ]]; then
RUN_COUNT=10
fi
cd cmd/perftester/
CGO_ENABLED="1" go run main.go $RUN_COUNT
env:
ANYTYPE_REPORT_MEMORY: 'true'
TEST_MNEMONIC: ${{ secrets.TEST_MNEMONIC }}
PROM_KEY: ${{ secrets.PROMETHEUS_USERNAME }}
PROM_PASSWORD: ${{ secrets.PROMETHEUS_PASSWORD }}
if: github.event.inputs.perf-test != '0' || github.event_name == 'schedule'
- name: Archive perf tests results
uses: actions/upload-artifact@v4
with:
name: pprofs
path: |
*.pprof
if: github.event.inputs.perf-test != '0' || github.event_name == 'schedule'
- name: end run perf tests
run: |
rm -rf *.pprof
echo "End running perf tests"
gh run cancel ${{ github.run_id }}
gh run watch ${{ github.run_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.event.inputs.perf-test != '0' || github.event_name == 'schedule'
- name: Make JS protos
run: |
make protos-js
mv dist/js/pb protobuf
mkdir -p protobuf/protos
cp pb/protos/*.proto ./protobuf/protos
cp pb/protos/service/*.proto ./protobuf/protos
cp pkg/lib/pb/model/protos/*.proto ./protobuf/protos
if: github.event_name == 'push'
- name: Add system relations/types jsons
run: |
mkdir -p json/
cp pkg/lib/bundle/systemRelations.json ./json
cp pkg/lib/bundle/systemTypes.json ./json
cp pkg/lib/bundle/internalRelations.json ./json
cp pkg/lib/bundle/internalTypes.json ./json
- name: Pack server win
run: |
declare -a arr=("windows-amd64")
for i in "${arr[@]}"
do
OSARCH=${i%.*}
cp ./${i}* ./grpc-server.exe
zip -r js_${VERSION}_${OSARCH}.zip grpc-server.exe protobuf json
mv js_${VERSION}_${OSARCH}.zip .release/
done
if: github.event_name == 'push'
- name: Pack server osx
run: |
declare -a arr=("darwin-amd64" "darwin-arm64")
for i in "${arr[@]}"
do
OSARCH=${i%.*}
cp ./${i}* ./grpc-server
tar -czf js_${VERSION}_${OSARCH}.tar.gz grpc-server protobuf json
mv js_${VERSION}_${OSARCH}.tar.gz .release/
done
if: github.event_name == 'push'
- name: Make swift protos
run: |
mkdir -p .release
make protos-swift
rm -rf protobuf
mv dist/ios/protobuf protobuf
mkdir -p protobuf/protos
cp pb/protos/*.proto ./protobuf/protos
cp pb/protos/service/*.proto ./protobuf/protos
cp pkg/lib/pb/model/protos/*.proto ./protobuf/protos
- name: Add system relations/types jsons
run: |
mkdir -p json/
cp pkg/lib/bundle/systemRelations.json ./json
cp pkg/lib/bundle/relations.json ./json
cp pkg/lib/bundle/systemTypes.json ./json
cp pkg/lib/bundle/internalRelations.json ./json
cp pkg/lib/bundle/internalTypes.json ./json
- name: Compile ios lib
run: |
go install github.com/vektra/mockery/v2@v2.42.2
go install go.uber.org/mock/mockgen@v0.3.0
make test-deps
gomobile bind -tags "envproduction nogrpcserver gomobile nowatchdog nosigar nomutexdeadlockdetector timetzdata" -ldflags "$FLAGS" -v -target=ios -o Lib.xcframework github.com/anyproto/anytype-heart/clientlibrary/service github.com/anyproto/anytype-heart/core || true
mkdir -p dist/ios/ && mv Lib.xcframework dist/ios/
go run cmd/iosrepack/main.go
mv dist/ios/Lib.xcframework .
gtar --exclude ".*" -czvf ios_framework.tar.gz Lib.xcframework protobuf json
gradle publish
mv ios_framework.tar.gz .release/ios_framework_${VERSION}.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USER: ${{ github.actor }}
MAVEN_ARTIFACT_ID: 'anytype-heart-ios'
MAVEN_ARTIFACT_NAME: 'ios_framework.tar.gz'
- name: Make java protos
run: |
make protos-java
rm -rf protobuf
mv dist/android/pb protobuf
mkdir -p protobuf/protos
cp pb/protos/*.proto ./protobuf/protos
cp pb/protos/service/*.proto ./protobuf/protos
cp pkg/lib/pb/model/protos/*.proto ./protobuf/protos
- name: Add system relations/types jsons
run: |
mkdir -p json/
cp pkg/lib/bundle/systemRelations.json ./json
cp pkg/lib/bundle/systemTypes.json ./json
cp pkg/lib/bundle/internalRelations.json ./json
cp pkg/lib/bundle/internalTypes.json ./json
- name: Compile android lib
run: |
gomobile bind -tags "envproduction nogrpcserver gomobile nowatchdog nosigar nomutexdeadlockdetector timetzdata" -ldflags "$FLAGS" -v -target=android -androidapi 19 -o lib.aar github.com/anyproto/anytype-heart/clientlibrary/service github.com/anyproto/anytype-heart/core || true
gtar --exclude ".*" -czvf android_lib_${VERSION}.tar.gz lib.aar protobuf json
mv android_lib_${VERSION}.tar.gz .release/
- name: Publish android lib to maven
run: |
gradle publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USER: ${{ github.actor }}
MAVEN_ARTIFACT_ID: 'anytype-heart-android'
MAVEN_ARTIFACT_NAME: 'lib.aar'
- name: Release
if: github.event_name == 'push'
uses: softprops/action-gh-release@v1
with:
prerelease: ${{ contains(github.ref, '-rc') }}
fail_on_unmatched_files: true
files: '.release/*'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build_linux:
if: github.event_name == 'push'
runs-on: ubuntu-22.04
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.22
- name: Setup GO
run: |
echo GOPATH=$(go env GOPATH) >> $GITHUB_ENV
echo GOBIN=$(go env GOPATH)/bin >> $GITHUB_ENV
echo $(go env GOPATH)/bin >> $GITHUB_PATH
- name: Setup license repositor
uses: actions/checkout@master
with:
repository: anyproto/open
ref: refs/heads/main
path: ./open
- name: Check licenses
run: |
cd open
python3 tools/generate.py --platform golang
cd ..
sudo gem install license_finder
license_finder inherited_decisions add open/decisions.yml
license_finder --enabled-package-managers gomodules
- name: Install patched gox
run: |
rm -rf $GOPATH/src/github.com/mitchellh
mkdir -p $GOPATH/src/github.com/mitchellh
cd $GOPATH/src/github.com/mitchellh
git clone https://github.com/aslakhellesoy/gox
cd gox
git fetch
git checkout db6184738b77fbd5089e5fa1112177f391c91b24
go install github.com/mitchellh/gox
- name: Apt install and node deps
run: |
sudo apt update
sudo apt install -y protobuf-compiler libprotoc-dev
curl -O https://pub-c60a000d68b544109df4fe5837762101.r2.dev/linux-compiler-musl-x86.zip
unzip linux-compiler-musl-x86.zip -d $HOME
npm i -g node-gyp
- name: Checkout
uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Set env vars
env:
UNSPLASH_KEY: ${{ secrets.UNSPLASH_KEY }}
INHOUSE_KEY: ${{ secrets.INHOUSE_KEY }}
run: |
GIT_SUMMARY=$(git describe --tags --always)
echo GOPRIVATE=github.com/anyproto >> $GITHUB_ENV
echo "FLAGS=-X github.com/anyproto/anytype-heart/util/vcs.GitSummary=${GIT_SUMMARY} -X github.com/anyproto/anytype-heart/metrics.DefaultInHouseKey=${INHOUSE_KEY} -X github.com/anyproto/anytype-heart/util/unsplash.DefaultToken=${UNSPLASH_KEY}" >> $GITHUB_ENV
echo VERSION=${GITHUB_REF##*/} >> $GITHUB_ENV
git config --global url."https://${{ secrets.ANYTYPE_PAT }}@github.com/".insteadOf "https://github.com/"
- name: Go mod download
run: |
go mod download
- name: install protoc
run: |
HAS_SYSTEM_PROTOBUF=false make setup-protoc
- name: setup go
run: |
make setup-go
- name: Cross-compile library for linux amd64/arm64
run: |
make download-tantivy-all
echo $FLAGS
mkdir -p .release
CXX=$HOME/linux-compiler-musl-x86/bin/x86_64-linux-musl-g++ CC=$HOME/linux-compiler-musl-x86/bin/x86_64-linux-musl-gcc gox -cgo -osarch="linux/amd64" -ldflags="$FLAGS -linkmode external -extldflags=-static" --tags="envproduction nographviz nowatchdog nosigar nomutexdeadlockdetector" -output="{{.OS}}-{{.Arch}}" github.com/anyproto/anytype-heart/cmd/grpcserver
make protos-server
- name: Make JS protos
run: |
make protos-js
mv dist/js/pb protobuf
mkdir -p protobuf/protos
cp pb/protos/*.proto ./protobuf/protos
cp pb/protos/service/*.proto ./protobuf/protos
cp pkg/lib/pb/model/protos/*.proto ./protobuf/protos
- name: Add system relations
run: |
mkdir -p json/
cp pkg/lib/bundle/systemRelations.json ./json
cp pkg/lib/bundle/systemTypes.json ./json
cp pkg/lib/bundle/internalRelations.json ./json
cp pkg/lib/bundle/internalTypes.json ./json
- name: Upload protobuf artifact for linux build
uses: actions/upload-artifact@v4
with:
name: libs
path: |
protobuf
if-no-files-found: error
retention-days: 1
- name: Pack server unix
run: |
declare -a arr=("linux-amd64")
for i in "${arr[@]}"
do
OSARCH=${i%.*}
cp ./${i}* ./grpc-server
tar -czf js_${VERSION}_${OSARCH}.tar.gz grpc-server protobuf json
mv js_${VERSION}_${OSARCH}.tar.gz .release/
done
- name: Release
if: github.event_name == 'push'
uses: softprops/action-gh-release@v1
with:
prerelease: ${{ contains(github.ref, '-rc') }}
fail_on_unmatched_files: true
files: '.release/*'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}