-
Notifications
You must be signed in to change notification settings - Fork 47
276 lines (272 loc) · 12.2 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
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 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
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew tap messense/macos-cross-toolchains && brew install x86_64-unknown-linux-musl
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/linux
run: |
make download-tantivy-all
echo $FLAGS
mkdir -p .release
echo $SDKROOT
GOOS="darwin" GOARCH="amd64" CGO_ENABLED="1" go build -tags="envproduction nographviz nowatchdog nosigar nomutexdeadlockdetector" -ldflags="$FLAGS" -o darwin-amd64 github.com/anyproto/anytype-heart/cmd/grpcserver
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
echo $SDKROOT
GOOS="darwin" GOARCH="arm64" CGO_ENABLED="1" go build -tags="envproduction nographviz nowatchdog nosigar nomutexdeadlockdetector" -ldflags="$FLAGS" -o darwin-arm64 github.com/anyproto/anytype-heart/cmd/grpcserver
GOOS="windows" GOARCH="amd64" CGO_ENABLED="1" CC="x86_64-w64-mingw32-gcc" CXX="x86_64-w64-mingw32-g++" go build -tags="envproduction nographviz nowatchdog nosigar nomutexdeadlockdetector noheic" -ldflags="$FLAGS -linkmode external -extldflags=-static" -o windows-amd64 github.com/anyproto/anytype-heart/cmd/grpcserver
GOOS="linux" GOARCH="amd64" CGO_ENABLED="1" CC="x86_64-linux-musl-gcc" go build -tags="envproduction nographviz nowatchdog nosigar nomutexdeadlockdetector noheic" -ldflags="$FLAGS -linkmode external -extldflags '-static -Wl,-z stack-size=1000000'" -o linux-amd64 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: 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
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 }}