-
Notifications
You must be signed in to change notification settings - Fork 81
1147 lines (988 loc) · 39.1 KB
/
main-workflow.yml
File metadata and controls
1147 lines (988 loc) · 39.1 KB
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: Main Workflow - Lint, Build, Test
on:
push:
branches:
- master
- main
tags:
- "**"
pull_request:
workflow_dispatch:
inputs:
python-version:
description: "Python version to use"
required: false
default: "3.12" # PY_VER
rust-version:
description: "Rust version to use"
required: false
default: "1.91" # RUST_VER
env:
PYTHON_VERSION: ${{ inputs.python-version || '3.12' }} # PY_VER
RUST_VERSION: ${{ inputs.rust-version || '1.91' }} # RUST_VER
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
permissions: {} # workflow-level default — deny all
jobs:
# Setup Python ======
python-env:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip and Poetry virtualenv
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.cache/pip
~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-python-${{ hashFiles('pyproject.toml', 'poetry.lock') }}
lookup-only: true
- name: Install Poetry
run: pip3 install poetry
- name: Install Python dependencies
run: poetry install --with tokenserver-unit-tests,dev --no-interaction --no-ansi
- name: Display Python Version Info
run: |
if [ "$(which python)" != "" ]; then python --version; fi
uname -a
cat /etc/os-release
# Setup Rust ======
rust-env:
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Cache Rust toolchain
id: cache-rust-toolchain
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.rustup/toolchains
~/.rustup/update-hashes
key: ${{ runner.os }}-rust-toolchain-${{ env.RUST_VERSION }}
lookup-only: true
- name: Install Rust toolchain
if: steps.cache-rust-toolchain.outputs.cache-hit != 'true'
run: rustup toolchain install ${RUST_VERSION} --component rustfmt --component clippy --component llvm-tools-preview --no-self-update && rustup default ${RUST_VERSION}
- name: Display Rust Version Info
shell: bash
run: |
if [ "$(which rustc)" != "" ]; then rustc --version; fi
uname -a
cat /etc/os-release
# Python lint and format checks ======
python-checks:
needs: python-env
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Restore pip and Poetry virtualenv
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.cache/pip
~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-python-${{ hashFiles('pyproject.toml', 'poetry.lock') }}
- name: Install Poetry
run: pip3 install poetry
- name: Python Format Check
run: poetry run ruff format --diff tools
- name: Python Lint Check
run: poetry run ruff check tools
- name: Python Docstring Check
run: poetry run pydocstyle -es --count --config=pyproject.toml tools
- name: Python Security Check
run: poetry run bandit --quiet -r -c pyproject.toml tools
- name: Python Type Check
run: poetry run mypy --config-file=pyproject.toml tools
# Rust lint and format checks ======
rust-checks:
needs: rust-env
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Restore Rust toolchain
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.rustup/toolchains
~/.rustup/update-hashes
key: ${{ runner.os }}-rust-toolchain-${{ env.RUST_VERSION }}
- name: Set Rust toolchain
run: rustup default ${RUST_VERSION}
- name: Cache cargo-audit
id: cache-cargo-audit
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: ~/.cargo/bin/cargo-audit
key: ${{ runner.os }}-cargo-audit-${{ hashFiles('.github/workflows/main-workflow.yml') }}
- name: Install cargo-audit
if: steps.cache-cargo-audit.outputs.cache-hit != 'true'
run: cargo install --locked cargo-audit
- name: Cache mdbook
id: cache-mdbook
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.cargo/bin/mdbook
~/.cargo/bin/mdbook-mermaid
key: ${{ runner.os }}-mdbook-${{ hashFiles('Makefile') }}
- name: Setup documentation checks
if: steps.cache-mdbook.outputs.cache-hit != 'true'
run: make doc-install-deps
- name: Rust Format Check
run: cargo fmt -- --check
- name: Cargo Audit
run: cargo audit
- name: Documentation checks
run: make doc-test
# Rust clippy lint checker
clippy:
needs: rust-env
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
target: [spanner, mysql, postgres]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Restore Rust toolchain
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.rustup/toolchains
~/.rustup/update-hashes
key: ${{ runner.os }}-rust-toolchain-${{ env.RUST_VERSION }}
- name: Set Rust toolchain
run: rustup default ${RUST_VERSION}
- name: Rust Clippy ${{ matrix.target }}
run: make clippy_${{ matrix.target }}
# Rust clippy release mode lint checker
clippy-release:
needs: rust-env
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
target: [spanner, mysql, postgres]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Restore Rust toolchain
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.rustup/toolchains
~/.rustup/update-hashes
key: ${{ runner.os }}-rust-toolchain-${{ env.RUST_VERSION }}
- name: Restore Rust cache
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-release-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-release-${{ matrix.target }}-
- name: Set Rust toolchain
run: rustup default ${RUST_VERSION}
- name: Rust Clippy release ${{ matrix.target }}
run: make clippy_release_${{ matrix.target }}
# Postgres unit tests ======
build-and-unit-test-postgres:
needs: [rust-env, python-env]
runs-on: ubuntu-latest
permissions:
contents: read
checks: write
services:
postgres:
image: postgres:18.0
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: syncstorage
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U test"
--health-interval=10s
--health-timeout=5s
--health-retries=5
env:
SYNC_SYNCSTORAGE__DATABASE_URL: postgres://test:test@127.0.0.1/syncstorage
SYNC_TOKENSERVER__DATABASE_URL: postgres://test:test@127.0.0.1/tokenserver
SYNC_TOKENSERVER__NODE_TYPE: postgres
RUST_BACKTRACE: 1
RUST_TEST_THREADS: 1
CARGO_INCREMENTAL: "0"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Restore Rust toolchain
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.rustup/toolchains
~/.rustup/update-hashes
key: ${{ runner.os }}-rust-toolchain-${{ env.RUST_VERSION }}
- name: Set Rust toolchain
run: rustup default ${RUST_VERSION}
- name: Restore pip and Poetry virtualenv
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.cache/pip
~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-python-${{ hashFiles('pyproject.toml', 'poetry.lock') }}
- name: Cache Cargo build artifacts
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-postgres-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-postgres-
- name: Create test results directory
run: mkdir -p workflow/test-results
- name: Install PostgreSQL client
run: sudo apt-get update && sudo apt-get install -y postgresql-client
- name: Create Tokenserver database
run: |
PGPASSWORD=test psql -U test -h 127.0.0.1 -d syncstorage -c 'CREATE DATABASE tokenserver;'
- name: Create version.json
run: |
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \
"${GITHUB_SHA}" \
"${GITHUB_REF_NAME}" \
"${GITHUB_REPOSITORY_OWNER}" \
"${GITHUB_REPOSITORY_NAME}" \
"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
> version.json
env:
GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
- name: Cache cargo-nextest
id: cache-cargo-nextest-postgres
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: ~/.cargo/bin/cargo-nextest
key: ${{ runner.os }}-cargo-nextest-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-nextest
if: steps.cache-cargo-nextest-postgres.outputs.cache-hit != 'true'
run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
- name: Cache cargo-llvm-cov
id: cache-cargo-llvm-cov-postgres
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: ~/.cargo/bin/cargo-llvm-cov
key: ${{ runner.os }}-cargo-llvm-cov-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-llvm-cov
if: steps.cache-cargo-llvm-cov-postgres.outputs.cache-hit != 'true'
run: cargo install --locked cargo-llvm-cov
- name: Run unit tests with coverage
run: make postgres_test_with_coverage
- name: Run unit tests with coverage (quota enforced)
run: make postgres_test_with_coverage
env:
SYNC_SYNCSTORAGE__ENFORCE_QUOTA: 1
- name: Install Poetry
run: pip3 install poetry
- name: Run Postgres utils tests
working-directory: tools/postgres
run: |
poetry install --no-interaction --no-ansi
WORKFLOW=$(echo "${GITHUB_WORKFLOW}" | tr ' ' '-' | tr '[:upper:]' '[:lower:]')
poetry run pytest test_purge_ttl.py -v --junit-xml="../../workflow/test-results/${GITHUB_RUN_NUMBER}__$(date +%s)__$(basename ${GITHUB_REPOSITORY})__${WORKFLOW}__postgres_utils__results.xml"
env:
SYNC_SYNCSTORAGE__DATABASE_URL: postgresql://test:test@127.0.0.1/syncstorage
- name: Publish Test Report
uses: dorny/test-reporter@29672c52a8220c09bd9f79b5b6cf6315f1763996
if: always()
with:
name: Postgres Unit Tests
path: workflow/test-results/*.xml
reporter: java-junit
fail-on-error: false
- name: Upload test results
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: postgres-test-results
path: workflow/test-results/
# Upload to GCS on master
- name: Authenticate to Google Cloud
if: github.ref == 'refs/heads/master'
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3
with:
credentials_json: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }}
- name: Upload JUnit results to GCS
if: github.ref == 'refs/heads/master'
uses: google-github-actions/upload-cloud-storage@6397bd7208e18d13ba2619ee21b9873edc94427a # v3.0.0
with:
path: workflow/test-results
destination: ecosystem-test-eng-metrics/syncstorage-rs/junit
glob: "*.xml"
parent: false
process_gcloudignore: false
- name: Upload coverage results to GCS
if: github.ref == 'refs/heads/master'
uses: google-github-actions/upload-cloud-storage@6397bd7208e18d13ba2619ee21b9873edc94427a # v3.0.0
with:
path: workflow/test-results
destination: ecosystem-test-eng-metrics/syncstorage-rs/coverage
glob: "*.json"
parent: false
process_gcloudignore: false
# Docker build Postgres Image ======
build-postgres-image:
runs-on: ubuntu-latest
needs: [rust-env, python-env]
permissions:
contents: read
actions: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Create version.json
run: |
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \
"${GITHUB_SHA}" \
"${GITHUB_REF_NAME}" \
"${GITHUB_REPOSITORY_OWNER}" \
"${GITHUB_REPOSITORY_NAME}" \
"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
> version.json
env:
GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
- name: Cache Docker image tar
id: cache-postgres-image
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: /tmp/postgres-image.tar
key: ${{ runner.os }}-postgres-image-${{ hashFiles('Dockerfile', 'Cargo.lock', '**/*.rs', '**/Cargo.toml', 'tools/**', 'scripts/**') }}
- name: Set up Docker Buildx
if: steps.cache-postgres-image.outputs.cache-hit != 'true'
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
- name: Build Postgres Docker image
if: steps.cache-postgres-image.outputs.cache-hit != 'true'
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7
with:
context: .
push: false
tags: app:build
build-args: |
SYNCSTORAGE_DATABASE_BACKEND=postgres
TOKENSERVER_DATABASE_BACKEND=postgres
outputs: type=docker,dest=/tmp/postgres-image.tar
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Upload Docker image artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: postgres-docker-image
path: /tmp/postgres-image.tar
retention-days: 1
# End-to-end tests for Postgres build ======
postgres-e2e-tests:
runs-on: ubuntu-latest
needs: build-postgres-image
permissions:
contents: read
checks: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Download Docker image
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: postgres-docker-image
path: /tmp
- name: Load Docker image
run: docker load --input /tmp/postgres-image.tar
- name: Create test results directory
run: mkdir -p workflow/test-results
- name: Run Postgres e2e tests
run: make docker_run_postgres_e2e_tests
env:
SYNCSTORAGE_RS_IMAGE: app:build
- name: Publish E2E Test Report
uses: dorny/test-reporter@29672c52a8220c09bd9f79b5b6cf6315f1763996
if: always()
with:
name: Postgres E2E Tests
path: workflow/test-results/*.xml
reporter: java-junit
fail-on-error: false
- name: Upload e2e test results
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: postgres-e2e-test-results
path: workflow/test-results/
# Upload to GCS on master
- name: Authenticate to Google Cloud
if: github.ref == 'refs/heads/master'
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3
with:
credentials_json: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }}
- name: Upload e2e test results to GCS
if: github.ref == 'refs/heads/master'
uses: google-github-actions/upload-cloud-storage@6397bd7208e18d13ba2619ee21b9873edc94427a # v3.0.0
with:
path: workflow/test-results
destination: ecosystem-test-eng-metrics/syncstorage-rs/junit
glob: "*.xml"
parent: false
process_gcloudignore: false
# MySQL Unit tests ======
build-and-unit-test-mysql:
runs-on: ubuntu-latest
needs: [rust-env, python-env]
permissions:
contents: read
checks: write
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: test
MYSQL_PASSWORD: test
MYSQL_DATABASE: syncstorage
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=5
env:
SYNC_SYNCSTORAGE__DATABASE_URL: mysql://test:test@127.0.0.1/syncstorage
SYNC_TOKENSERVER__DATABASE_URL: mysql://test:test@127.0.0.1/tokenserver
SYNC_TOKENSERVER__NODE_TYPE: spanner
RUST_BACKTRACE: 1
RUST_TEST_THREADS: 1
CARGO_INCREMENTAL: "0"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Restore Rust toolchain
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.rustup/toolchains
~/.rustup/update-hashes
key: ${{ runner.os }}-rust-toolchain-${{ env.RUST_VERSION }}
- name: Set Rust toolchain
run: rustup default ${RUST_VERSION}
- name: Restore pip and Poetry virtualenv
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.cache/pip
~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-python-${{ hashFiles('pyproject.toml', 'poetry.lock') }}
- name: Cache Cargo build artifacts
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-mysql-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-mysql-
- name: Create test results directory
run: mkdir -p workflow/test-results
- name: Install MySQL client
run: sudo apt-get update && sudo apt-get install -y default-mysql-client
- name: Create Tokenserver database
run: |
mysql -u root -ppassword -h 127.0.0.1 -e 'CREATE DATABASE tokenserver;'
mysql -u root -ppassword -h 127.0.0.1 -e "GRANT ALL ON tokenserver.* to 'test'@'%';"
- name: Create version.json
run: |
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \
"${GITHUB_SHA}" \
"${GITHUB_REF_NAME}" \
"${GITHUB_REPOSITORY_OWNER}" \
"${GITHUB_REPOSITORY_NAME}" \
"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
> version.json
env:
GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
- name: Cache cargo-nextest
id: cache-cargo-nextest-mysql
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: ~/.cargo/bin/cargo-nextest
key: ${{ runner.os }}-cargo-nextest-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-nextest
if: steps.cache-cargo-nextest-mysql.outputs.cache-hit != 'true'
run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
- name: Cache cargo-llvm-cov
id: cache-cargo-llvm-cov-mysql
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: ~/.cargo/bin/cargo-llvm-cov
key: ${{ runner.os }}-cargo-llvm-cov-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-llvm-cov
if: steps.cache-cargo-llvm-cov-mysql.outputs.cache-hit != 'true'
run: cargo install --locked cargo-llvm-cov
- name: Run unit tests with coverage
run: make test_with_coverage
- name: Run unit tests with coverage (quota enforced)
run: make test_with_coverage
env:
SYNC_SYNCSTORAGE__ENFORCE_QUOTA: 1
- name: Publish Test Report
uses: dorny/test-reporter@29672c52a8220c09bd9f79b5b6cf6315f1763996
if: always()
with:
name: MySQL Unit Tests
path: workflow/test-results/*.xml
reporter: java-junit
fail-on-error: false
- name: Upload test results
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: mysql-test-results
path: workflow/test-results/
# Upload to GCS on master
- name: Authenticate to Google Cloud
if: github.ref == 'refs/heads/master'
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3
with:
credentials_json: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }}
- name: Upload JUnit results to GCS
if: github.ref == 'refs/heads/master'
uses: google-github-actions/upload-cloud-storage@6397bd7208e18d13ba2619ee21b9873edc94427a # v3.0.0
with:
path: workflow/test-results
destination: ecosystem-test-eng-metrics/syncstorage-rs/junit
glob: "*.xml"
parent: false
process_gcloudignore: false
- name: Upload coverage results to GCS
if: github.ref == 'refs/heads/master'
uses: google-github-actions/upload-cloud-storage@6397bd7208e18d13ba2619ee21b9873edc94427a # v3.0.0
with:
path: workflow/test-results
destination: ecosystem-test-eng-metrics/syncstorage-rs/coverage
glob: "*.json"
parent: false
process_gcloudignore: false
# Docker build for MySQL Image
build-mysql-image:
runs-on: ubuntu-latest
needs: [rust-env, python-env]
permissions:
contents: read
actions: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Create version.json
run: |
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \
"${GITHUB_SHA}" \
"${GITHUB_REF_NAME}" \
"${GITHUB_REPOSITORY_OWNER}" \
"${GITHUB_REPOSITORY_NAME}" \
"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
> version.json
env:
GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
- name: Cache Docker image tar
id: cache-mysql-image
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: /tmp/mysql-image.tar
key: ${{ runner.os }}-mysql-image-${{ hashFiles('Dockerfile', 'Cargo.lock', '**/*.rs', '**/Cargo.toml', 'tools/**', 'scripts/**') }}
- name: Set up Docker Buildx
if: steps.cache-mysql-image.outputs.cache-hit != 'true'
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
- name: Build MySQL Docker image
if: steps.cache-mysql-image.outputs.cache-hit != 'true'
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7
with:
context: .
push: false
tags: app:build
build-args: |
SYNCSTORAGE_DATABASE_BACKEND=mysql
TOKENSERVER_DATABASE_BACKEND=mysql
outputs: type=docker,dest=/tmp/mysql-image.tar
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Upload Docker image artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: mysql-docker-image
path: /tmp/mysql-image.tar
retention-days: 1
# End-to-end tests for MySQL ======
mysql-e2e-tests:
runs-on: ubuntu-latest
needs: build-mysql-image
permissions:
contents: read
checks: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Download Docker image
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: mysql-docker-image
path: /tmp
- name: Load Docker image
run: docker load --input /tmp/mysql-image.tar
- name: Create test results directory
run: mkdir -p workflow/test-results
- name: Run MySQL e2e tests
run: make docker_run_mysql_e2e_tests
env:
SYNCSTORAGE_RS_IMAGE: app:build
- name: Publish E2E Test Report
uses: dorny/test-reporter@29672c52a8220c09bd9f79b5b6cf6315f1763996
if: always()
with:
name: MySQL E2E Tests
path: workflow/test-results/*.xml
reporter: java-junit
fail-on-error: false
- name: Upload e2e test results
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: mysql-e2e-test-results
path: workflow/test-results/
# Upload to GCS on master
- name: Authenticate to Google Cloud
if: github.ref == 'refs/heads/master'
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3
with:
credentials_json: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }}
- name: Upload e2e test results to GCS
if: github.ref == 'refs/heads/master'
uses: google-github-actions/upload-cloud-storage@6397bd7208e18d13ba2619ee21b9873edc94427a # v3.0.0
with:
path: workflow/test-results
destination: ecosystem-test-eng-metrics/syncstorage-rs/junit
glob: "*.xml"
parent: false
process_gcloudignore: false
# Spanner Unit tests ======
build-and-unit-test-spanner:
runs-on: ubuntu-latest
needs: [rust-env, python-env]
permissions:
contents: read
checks: write
services:
spanner-emulator:
# SPANNER_EMULATOR_VER (unit tests) — keep in sync with docker/docker-compose.spanner.yaml
image: gcr.io/cloud-spanner-emulator/emulator:1.5.52
ports:
- 9010:9010
- 9020:9020
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: test
MYSQL_PASSWORD: test
MYSQL_DATABASE: syncstorage
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
env:
# The code expects a spanner URL like:
SYNC_SYNCSTORAGE__DATABASE_URL: spanner://projects/test-project/instances/test-instance/databases/test-database
RUST_BACKTRACE: 1
RUST_TEST_THREADS: 1
CARGO_INCREMENTAL: "0"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Restore Rust toolchain
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.rustup/toolchains
~/.rustup/update-hashes
key: ${{ runner.os }}-rust-toolchain-${{ env.RUST_VERSION }}
- name: Set Rust toolchain
run: rustup default ${RUST_VERSION}
- name: Restore pip and Poetry virtualenv
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.cache/pip
~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-python-${{ hashFiles('pyproject.toml', 'poetry.lock') }}
- name: Cache Cargo build artifacts
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-spanner-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-spanner-
- name: Create test results directory
run: mkdir -p workflow/test-results
- name: Create version.json
run: |
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \
"${GITHUB_SHA}" \
"${GITHUB_REF_NAME}" \
"${GITHUB_REPOSITORY_OWNER}" \
"${GITHUB_REPOSITORY_NAME}" \
"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
> version.json
env:
GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
- name: Cache cargo-nextest
id: cache-cargo-nextest-spanner
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: ~/.cargo/bin/cargo-nextest
key: ${{ runner.os }}-cargo-nextest-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-nextest
if: steps.cache-cargo-nextest-spanner.outputs.cache-hit != 'true'
run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
- name: Cache cargo-llvm-cov
id: cache-cargo-llvm-cov-spanner
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: ~/.cargo/bin/cargo-llvm-cov
key: ${{ runner.os }}-cargo-llvm-cov-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-llvm-cov
if: steps.cache-cargo-llvm-cov-spanner.outputs.cache-hit != 'true'
run: cargo install --locked cargo-llvm-cov
- name: Build workspace (spanner feature)
run: |
# Build with the spanner feature so any compile-time issues surface early
cargo build --workspace --no-default-features --features=syncstorage-db/spanner --features=py_verifier
- name: Wait for Spanner Emulator to be ready
run: |
echo "Waiting for Spanner emulator to be ready..."
for i in {1..30}; do
if curl -s http://localhost:9020/ > /dev/null 2>&1; then
echo "Spanner emulator is ready (REST port 9020 responding)"
break
fi
echo "Attempt $i/30: Spanner emulator not ready yet, waiting..."
sleep 2
done
# Verify both ports are accessible
if ! curl -s http://localhost:9020/ > /dev/null 2>&1; then
echo "ERROR: Cannot connect to Spanner emulator REST API at localhost:9020"
exit 1
fi
echo "Spanner emulator is fully ready"
- name: Setup Spanner schema & instance (prepare-spanner.sh)
env:
SYNC_SYNCSTORAGE__DATABASE_URL: spanner://projects/test-project/instances/test-instance/databases/test-database
SYNC_SYNCSTORAGE__SPANNER_EMULATOR_HOST: http://localhost:9020
run: |
# prepare-spanner.sh uses the REST API (port 9020)
scripts/prepare-spanner.sh
- name: Create Tokenserver database
run: |
mysql -u root -ppassword -h 127.0.0.1 -e 'CREATE DATABASE tokenserver;'
mysql -u root -ppassword -h 127.0.0.1 -e "GRANT ALL ON tokenserver.* to 'test'@'%';"
- name: Run Spanner unit tests with coverage
env:
SYNC_SYNCSTORAGE__DATABASE_URL: spanner://projects/test-project/instances/test-instance/databases/test-database
SYNC_SYNCSTORAGE__SPANNER_EMULATOR_HOST: localhost:9010
SYNC_TOKENSERVER__DATABASE_URL: mysql://test:test@127.0.0.1/tokenserver
SYNC_TOKENSERVER__NODE_TYPE: spanner
RUST_TEST_THREADS: 1
run: make spanner_test_with_coverage
- name: Publish Test Report
uses: dorny/test-reporter@29672c52a8220c09bd9f79b5b6cf6315f1763996
if: always()
with:
name: Spanner Unit Tests
path: workflow/test-results/*.xml
reporter: java-junit
fail-on-error: false
- name: Upload test results
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: spanner-test-results