Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): add lightwalletd_update_sync test to CI #4269

Merged
merged 226 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
226 commits
Select commit Hold shift + click to select a range
1aae93e
feat(ci): add lightwalletd_*_sync tests to CI
gustavovalverde Apr 29, 2022
d2e2e2f
feat(ci): add lightwalletd RPC call test
gustavovalverde Apr 30, 2022
7333d4b
feat(ci): add send transactions test with lwd to CI
gustavovalverde Apr 30, 2022
e209289
fix(ci): create a variable to run transactions test
gustavovalverde Apr 30, 2022
66ae72a
refactor(ci): use docker in docker
gustavovalverde Apr 30, 2022
cd7c9d2
fix(build): persist docker login credentials
gustavovalverde May 1, 2022
4c82d76
fix(ci): get sync height from docker logs instead of gcp
gustavovalverde May 1, 2022
7759333
try: use gha cache for faster building
gustavovalverde May 1, 2022
501e74a
fix(ci): mount disk in container to make it available in vm
gustavovalverde May 1, 2022
865dd94
fix(build): do not invalidate cache between images
gustavovalverde May 1, 2022
0b00f41
try(docker): invalidate cache as less as possible
gustavovalverde May 1, 2022
9dbd569
fix(ci): GHA terminal is not a TTY
gustavovalverde May 1, 2022
54db94b
fix(build): do not ignore entrypoint.sh
gustavovalverde May 1, 2022
7a4945b
fix
gustavovalverde May 1, 2022
fd37a02
fix(ci): mount using root priveleges
gustavovalverde May 1, 2022
fc6e20b
fix(ci): use existing disk as cached state
gustavovalverde May 1, 2022
6f622f6
fix(ci): wait for disks to get mounted
gustavovalverde May 1, 2022
4306444
force rebuild
gustavovalverde May 1, 2022
d053daf
fix failed force
gustavovalverde May 1, 2022
e8ef913
fix failed commit
gustavovalverde May 1, 2022
14ee447
WIP
gustavovalverde May 1, 2022
732e187
Merge branch 'main' into ci-gcp-disk
gustavovalverde May 1, 2022
6da4254
fix(ci): some tests does not use a cached state
gustavovalverde May 1, 2022
50ffb12
wip
gustavovalverde May 1, 2022
80cbf67
Merge branch 'ci-gcp-disk' into ref-test-deployment
gustavovalverde May 1, 2022
203041f
refactor(ci): disk names and job segregation
gustavovalverde May 2, 2022
57021db
fix(ci): do not name boot and attached disk the same
gustavovalverde May 2, 2022
3f77965
fix(ci): attach a disk to full sync, to snapshot the state
gustavovalverde May 2, 2022
e914a17
Merge branch 'ci-gcp-disk' into ref-test-deployment
gustavovalverde May 2, 2022
725ce80
Merge branch 'main' into lwd-ci-test
gustavovalverde May 2, 2022
4f21e18
fix(ci): use correct disk implementations
gustavovalverde May 2, 2022
31eacf6
fix(ci): use different disk name to allow test concurrency
gustavovalverde May 2, 2022
eca2475
feat(ci): add lightwalledt send transaction test
gustavovalverde May 2, 2022
f16cd67
feat(ci): add lightwalletd full sync test
gustavovalverde May 2, 2022
da2d64a
feat(ci): add lightwalletd update sync to CI
gustavovalverde May 2, 2022
0427a93
cleanup(ci): remove extra tests
gustavovalverde May 2, 2022
a5514cf
Merge branch 'lwd-ci-test' into lwd-ci-transaction
gustavovalverde May 2, 2022
09a15d2
Merge branch 'lwd-ci-transaction' into lwd-ci-fullsync
gustavovalverde May 2, 2022
7c21d88
Merge branch 'lwd-ci-fullsync' into lwd-ci-updatesync
gustavovalverde May 2, 2022
dfcd3a6
fix(ci): allow disk concurrency with tests
gustavovalverde May 2, 2022
765ea9a
fix(ci): add considerations for different tests
gustavovalverde May 2, 2022
adb165e
fix(reusable): last fixes
gustavovalverde May 2, 2022
97311a1
feat(ci): use reusable workflow for tests
gustavovalverde May 2, 2022
3b6c87c
fix(rw): remove nested worflow
gustavovalverde May 3, 2022
044e944
fix(rw): minor fixes
gustavovalverde May 3, 2022
e71db67
Merge branch 'main' into ref-test-deployment
gustavovalverde May 3, 2022
e76d3f9
force rebuild
gustavovalverde May 3, 2022
63943eb
fix(rw): do not use an input as job name
gustavovalverde May 3, 2022
e6abc27
fix(rw): remove variable id
gustavovalverde May 3, 2022
89331b4
fix(ci): remove explicit conditions and id
gustavovalverde May 3, 2022
7e36851
Merge branch 'main' into ref-test-deployment
mergify[bot] May 3, 2022
ec160fd
Merge branch 'main' into ref-test-deployment
gustavovalverde May 3, 2022
c22f3fd
fix(ci): docker does not need the variable sign ($) to work
gustavovalverde May 3, 2022
58439c2
fix(ci): mount typo
gustavovalverde May 3, 2022
b3f3032
fix(ci): if a sync fails, always delete the instance
gustavovalverde May 3, 2022
95956f0
refactor(ci): make all test depend on the same build
gustavovalverde May 3, 2022
f5aa242
fix(ci): some tests require multiple variables
gustavovalverde May 3, 2022
a9867b6
fix(docker): variable substitution
gustavovalverde May 3, 2022
994c539
fix(ci): allow to run multiple commits from a PR at once
gustavovalverde May 3, 2022
847d406
fix(docker): lower the NETWORK env var for test names
gustavovalverde May 3, 2022
9c94ef2
Merge branch 'main' into ref-test-deployment
gustavovalverde May 3, 2022
573fd7e
reduce uneeded diff
gustavovalverde May 3, 2022
2380151
Merge branch 'main' into ref-test-deployment
gustavovalverde May 3, 2022
cfabd38
imp(keys): use better naming for builds_disks
gustavovalverde May 3, 2022
018d1c2
imp(ci): use input defaults
gustavovalverde May 3, 2022
0cf2f5b
imp(ci): remove test_name in favor of test_id
gustavovalverde May 3, 2022
51c0291
fix(ci): better key naming
gustavovalverde May 3, 2022
1fd699e
fix(ci): long disk names breaks GCP naming convention
gustavovalverde May 3, 2022
0799a68
feat(ci): validate local state version with cached state
gustavovalverde May 3, 2022
6949e8b
fix(ci): add condition to run tests
gustavovalverde May 3, 2022
1b037bd
fix: typo
gustavovalverde May 3, 2022
ebe78cc
fix: app_name should not be required
gustavovalverde May 3, 2022
b6f150f
fix: zebra_state_path shouldn't be required
gustavovalverde May 3, 2022
ca92f3a
fix: reduce diff
gustavovalverde May 3, 2022
538d8c4
Merge branch 'main' into lwd-ci-test
gustavovalverde May 3, 2022
5274978
Merge branch 'main' into ref-test-deployment
gustavovalverde May 3, 2022
36c5e0d
fix(ci): checkout to grep local state version
gustavovalverde May 3, 2022
fc65aa6
Update .github/workflows/test.yml
gustavovalverde May 3, 2022
e6fc2ce
Merge branch 'ref-test-deployment' into lwd-ci-test
gustavovalverde May 3, 2022
7f9a8bb
revert: merge all tests into a single workflow
gustavovalverde May 3, 2022
aeed7d7
Remove unused STATE_VERSION env var
teor2345 May 3, 2022
6cc693d
fix: minor fixes
gustavovalverde May 4, 2022
f3e793c
fix(ci): make test.patch the same as test
gustavovalverde May 4, 2022
8e24220
fix(ci): negate the input value
gustavovalverde May 4, 2022
3d9c24e
Merge branch 'lwd-ci-test' into lwd-ci-transaction
gustavovalverde May 4, 2022
8088efc
Merge branch 'lwd-ci-transaction' into lwd-ci-fullsync
gustavovalverde May 4, 2022
6e242ed
imp(ci): better cached state conditional handling
gustavovalverde May 4, 2022
1dac640
imp(ci): exit code is captured by `docker run`
gustavovalverde May 4, 2022
2ade313
fix(deploy): mount disks with better write performance
gustavovalverde May 4, 2022
755670c
fix(ci): change sync id to a broader id name
gustavovalverde May 4, 2022
a362e4f
fix(ci): use correct input validation
gustavovalverde May 4, 2022
edb9d73
fix(ci): do not make test with cached state dependant on other
gustavovalverde May 4, 2022
1586d1d
imp(ci): organiza keys better
gustavovalverde May 4, 2022
14ed41c
fix(ci): use appropiate naming
gustavovalverde May 4, 2022
c15ec88
fix(ci): create docker volume before mounting
gustavovalverde May 4, 2022
7f00e47
fix(lint): do not fail on all new changes
gustavovalverde May 4, 2022
5d6eb53
imp(ci): do not report in pr review
gustavovalverde May 4, 2022
4f0b21a
fix(ci): partition clean disks
gustavovalverde May 4, 2022
48df0bc
fix: typo
gustavovalverde May 4, 2022
4ad733e
fix: test called the wrong way
gustavovalverde May 4, 2022
a8fbc5f
fix(build): stop using gha cache
gustavovalverde May 4, 2022
1ac8402
ref(ci): validate run condition before calling reusable workflow
gustavovalverde May 4, 2022
ff3ab5c
Merge branch 'ref-test-deployment' into lwd-ci-test
gustavovalverde May 4, 2022
a325798
Merge branch 'lwd-ci-test' into lwd-ci-transaction
gustavovalverde May 4, 2022
05abb14
Merge branch 'lwd-ci-transaction' into lwd-ci-fullsync
gustavovalverde May 4, 2022
c743d28
fix(ci): use a better filesystem dir and fix other values
gustavovalverde May 4, 2022
867864c
fix: linting errors
gustavovalverde May 4, 2022
dbc6743
fix(ci): typo
gustavovalverde May 4, 2022
cb35486
Revert "fix(build): stop using gha cache"
gustavovalverde May 4, 2022
9334661
Merge branch 'ref-test-deployment' into lwd-ci-test
gustavovalverde May 4, 2022
6458b95
fix(build): push cache to another registry
gustavovalverde May 4, 2022
6b61eca
fix(build): repository name should be lower case
gustavovalverde May 4, 2022
28fcfdf
Merge branch 'main' into lwd-ci-test
gustavovalverde May 4, 2022
b07336f
Merge branch 'lwd-ci-test' into lwd-ci-transaction
gustavovalverde May 4, 2022
ce5f4ab
Merge branch 'lwd-ci-transaction' into lwd-ci-fullsync
gustavovalverde May 4, 2022
66ea15b
Merge branch 'lwd-ci-fullsync' into lwd-ci-updatesync
gustavovalverde May 4, 2022
d6be38c
fix: merge fixes
gustavovalverde May 4, 2022
9137483
fix: remove uneeded condition
gustavovalverde May 4, 2022
85c5433
Merge branch 'lwd-ci-fullsync' into lwd-ci-updatesync
gustavovalverde May 4, 2022
b6cfd13
fix: test name with id
gustavovalverde May 4, 2022
3a8d77d
imp(ci): do not set a default for needs_zebra_state
gustavovalverde May 5, 2022
320f58d
Merge branch 'lwd-ci-test' into lwd-ci-transaction
gustavovalverde May 5, 2022
ada64a8
Merge branch 'lwd-ci-transaction' into lwd-ci-fullsync
gustavovalverde May 5, 2022
62d91e4
Merge branch 'lwd-ci-fullsync' into lwd-ci-updatesync
gustavovalverde May 5, 2022
b36bc9e
Update .github/workflows/test.yml
gustavovalverde May 5, 2022
c366df0
Merge branch 'lwd-ci-test' into lwd-ci-transaction
gustavovalverde May 5, 2022
2ac76b0
Merge branch 'lwd-ci-transaction' into lwd-ci-fullsync
gustavovalverde May 5, 2022
a21d16e
Merge branch 'lwd-ci-fullsync' into lwd-ci-updatesync
gustavovalverde May 5, 2022
e5f45bb
fix(deps): change base branch
gustavovalverde May 5, 2022
702912e
fix(deps): remove dependencies
gustavovalverde May 5, 2022
cc83512
force build
gustavovalverde May 5, 2022
096392d
fix(deps): remove dependencies
gustavovalverde May 5, 2022
7d695fd
fix(deps): remove dependencies
gustavovalverde May 5, 2022
82125d8
force rebuild
gustavovalverde May 5, 2022
8b334a2
fix(ci): invalid key
gustavovalverde May 5, 2022
7f89315
Update .github/workflows/test.yml
gustavovalverde May 5, 2022
08fa3d9
fix(docker): add RUST_LOG as an ARG and ENV
gustavovalverde May 5, 2022
97bf88a
Merge branch 'main' into fix-docker-cache
gustavovalverde May 5, 2022
3cada73
Merge branch 'main' into lwd-ci-transaction
gustavovalverde May 5, 2022
193f020
Merge branch 'main' into lwd-ci-fullsync
gustavovalverde May 5, 2022
297520a
ref(build): push test images to GitHub Packages
gustavovalverde May 5, 2022
c71cff9
Merge branch 'main' into lwd-ci-transaction
gustavovalverde May 5, 2022
b8489e1
Merge branch 'main' into lwd-ci-fullsync
gustavovalverde May 5, 2022
4950e3c
fix(test): add `#[ignore]` to send transactions test
gustavovalverde May 5, 2022
acae934
fix(ci): differentiate between root cache path and its dir
gustavovalverde May 5, 2022
24e336a
Remove extra `state` directory
jvff May 5, 2022
a6f39bb
imp(docs): use better test descriptions
gustavovalverde May 5, 2022
cf3892a
fix: reduce unwanted diff with main
gustavovalverde May 5, 2022
4eb2e51
fix(ci): make lwd conditions consistent
gustavovalverde May 5, 2022
60f23ae
Merge branch 'main' into lwd-ci-transaction
mergify[bot] May 5, 2022
af8664c
Remove another extra `state` directory
jvff May 5, 2022
8555cfc
fix(ci): use better conditionals to run test jobs
gustavovalverde May 5, 2022
999927e
Merge branch 'lwd-ci-transaction' into lwd-ci-fullsync
gustavovalverde May 6, 2022
b476ae3
Merge branch 'main' into lwd-ci-fullsync
mergify[bot] May 6, 2022
7129637
test: push to a single registry
gustavovalverde May 6, 2022
a80fee4
ref(docker): just build once for each use case
gustavovalverde May 6, 2022
cdeecd8
fix(docker): do a cargo chef for each build type
gustavovalverde May 6, 2022
b7862bf
fix(docker): run cargo chef only with recipe available
gustavovalverde May 6, 2022
30587a7
ref(build): use inline cache
gustavovalverde May 6, 2022
154309b
Merge branch 'main' into fix-docker-cache
gustavovalverde May 6, 2022
b6199f8
Merge branch 'main' into fix-docker-cache
gustavovalverde May 6, 2022
3b77005
revert: use GAR registry
gustavovalverde May 6, 2022
9bebce9
fix: wrong replacement
gustavovalverde May 6, 2022
8fffe5e
Merge branch 'main' into fix-docker-cache
gustavovalverde May 6, 2022
6b6e097
test(build): remove caching completely
gustavovalverde May 6, 2022
f2f53b5
Merge branch 'main' into fix-docker-cache
gustavovalverde May 9, 2022
299168e
fix(ci): login to the right registry
gustavovalverde May 9, 2022
54cf3d2
fix(ci): rename to the appropiate workflow
gustavovalverde May 10, 2022
6264d1a
revert: add inline cache
gustavovalverde May 10, 2022
f564929
test: try with registry max cache
gustavovalverde May 10, 2022
51a352b
fix(ci): limit caching to branches
gustavovalverde May 10, 2022
aad1005
refactor(build): use better stage naming and document it
gustavovalverde May 10, 2022
8dd8b65
merge `main` into `fix-docker-cache`
gustavovalverde May 10, 2022
8c2acc4
refactort(build): use multiple cache sources
gustavovalverde May 10, 2022
c4dc639
fix(build): specifying multiple cache exports is not supported
gustavovalverde May 10, 2022
7873d84
docs(build): use an appropiate comment for cache
gustavovalverde May 10, 2022
ef7993d
Merge branch 'fix-docker-cache' into lwd-ci-fullsync
gustavovalverde May 10, 2022
fd6ed3e
fix(ci): keep zebrad-cache as the hardcoded disk for zebra
gustavovalverde May 10, 2022
9d241e2
fix(ci): remove enable-sentry feature from tests
gustavovalverde May 10, 2022
f7a63c9
Fix zebrad integration test timeouts
teor2345 May 11, 2022
bb1e360
Merge branch 'main' into lwd-ci-fullsync
gustavovalverde May 11, 2022
e40e953
fix(ci): build the image from a disk that actually exists
gustavovalverde May 11, 2022
d3a8a95
Merge branch 'main' into lwd-ci-fullsync
gustavovalverde May 11, 2022
f71a1f5
Temporarily use an earlier lightwalletd version
teor2345 May 11, 2022
cf95f61
Actually rebuild the lightwalletd image
teor2345 May 11, 2022
d9a4e25
Delete an unfinished comment
teor2345 May 11, 2022
983ef4c
Merge branch 'main' into lwd-ci-fullsync
gustavovalverde May 12, 2022
9f53ddf
Remove duplicate test in entrypoint.sh
teor2345 May 12, 2022
379e663
Keep a recent change to make tests consistent
teor2345 May 12, 2022
e2790ba
Merge branch 'lwd-ci-fullsync' into lwd-ci-updatesync
gustavovalverde May 12, 2022
5e7e6fc
fix(ci): merge fixes
gustavovalverde May 12, 2022
b19888c
fix(ci): remove not used variable `lwd_state_dir`
gustavovalverde May 12, 2022
a2b5940
Merge branch 'lwd-ci-fullsync' into lwd-ci-updatesync
gustavovalverde May 12, 2022
a256810
Merge branch 'main' into lwd-ci-fullsync
gustavovalverde May 12, 2022
cc50445
fix(ci): remove unused variables
gustavovalverde May 12, 2022
2c877d7
fix(ci): state wast not being added to the image name
gustavovalverde May 12, 2022
2c22d9c
Merge branch 'lwd-ci-fullsync' into lwd-ci-updatesync
gustavovalverde May 12, 2022
ad3316e
refactor(ci): use a single step to find a zebra or lwd cache disk
gustavovalverde May 12, 2022
b9e4bbe
test: revert this commit later
gustavovalverde May 12, 2022
3b07da1
fix(ci): allow other tests to run
gustavovalverde May 12, 2022
54e9fee
fix(ci): mount a docker volume with lightwalletd dir
gustavovalverde May 12, 2022
99b2a16
fix(ci): lwd state condition
gustavovalverde May 12, 2022
626ee7d
Merge branch 'lwd-ci-fullsync' into lwd-ci-updatesync
gustavovalverde May 12, 2022
009d604
fix(ci): differentiate tests that need a lwd cached state
gustavovalverde May 12, 2022
98509ba
fix(ci): use the right state and save name for each test
gustavovalverde May 12, 2022
cf089a7
Merge branch 'main' into lwd-ci-fullsync
gustavovalverde May 13, 2022
292dedc
Merge branch 'lwd-ci-fullsync' into lwd-ci-updatesync
gustavovalverde May 13, 2022
1d8405e
docs(ci): explain disk mounting logic
gustavovalverde May 13, 2022
bdb217b
docs(ci): explain disk mounting logic
gustavovalverde May 13, 2022
3a231d3
docs(ci): explain disk search better
gustavovalverde May 13, 2022
9c6dfa0
docs(ci): explain disk mounting decision better
gustavovalverde May 13, 2022
769f92b
docs(ci): add a description for confusing input names
gustavovalverde May 13, 2022
f31c24f
Merge branch 'lwd-ci-fullsync' into lwd-ci-updatesync
gustavovalverde May 13, 2022
fbce166
docs(ci): minor comment fixes
gustavovalverde May 13, 2022
dd1009d
Merge branch 'lwd-ci-fullsync' into lwd-ci-updatesync
gustavovalverde May 13, 2022
0b5620b
docs(ci): better input description
gustavovalverde May 13, 2022
20ac2ae
Merge branch 'main' into lwd-ci-updatesync
gustavovalverde May 13, 2022
174642b
fix(ci): end `if` condition correctly
gustavovalverde May 13, 2022
343e27f
fix(images): pass the state version to following steps
gustavovalverde May 13, 2022
bdab714
fix(ci): $needs_lwd_state condition was inverted
gustavovalverde May 13, 2022
e4d0ddf
fix(ci): reduce disk selection code
gustavovalverde May 13, 2022
566ca78
docs(ci): better disk search conditional explanation
gustavovalverde May 13, 2022
7f7ed65
fix(ci): end if condition correctly
gustavovalverde May 13, 2022
1243d88
fix(ci): evaluate $needs_zebra_state correctly
gustavovalverde May 13, 2022
cbcd4fb
fix(ci): use nested condition for readability
gustavovalverde May 13, 2022
88c1eba
fix(ci): disk search was using the wrong variable
gustavovalverde May 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
290 changes: 290 additions & 0 deletions .github/workflows/gcp-test-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
name: Test instance deployment

on:
workflow_call:
inputs:
network:
required: false
type: string
app_name:
required: false
type: string
default: 'zebra'
test_id:
required: true
type: string
test_description:
required: true
type: string
test_variables:
required: true
type: string
zebra_state_path:
required: false
type: string
default: '/zebrad-cache'
disk_prefix:
required: false
type: string
default: 'zebrad-cache'
disk_suffix:
required: false
type: string
needs_constants:
required: true
type: boolean
saves_to_disk:
required: true
type: boolean
height_grep_text:
required: false
type: string

env:
NETWORK: Mainnet
IMAGE_NAME: zebrad-test
GAR_BASE: us-docker.pkg.dev/zealous-zebra/zebra
ZONE: us-central1-a
MACHINE_TYPE: c2d-standard-16

jobs:
sync:
name: Run ${{ inputs.test_id }} test
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- uses: actions/checkout@v3.0.2
with:
persist-credentials: false
fetch-depth: '2'

# TODO move the `changed-files-specific` step to the build job for a better dependency tree
# Only run this job if the database format version has (likely) changed.
#
# If we have accidentally changed the format, but not changed the version,
# we want to run with the old cached state, so this job fails.
#
# If we change the state path without changing the version,
# this job will take a few hours, because it will do a full rebuild.
- name: Get specific changed files
id: changed-files-specific
uses: tj-actions/changed-files@v19
with:
files: |
zebra-state/**/constants.rs

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
short-length: 7

- name: Downcase network name for disks
run: |
NETWORK_CAPS=${{ inputs.network }}
echo "NETWORK=${NETWORK_CAPS,,}" >> $GITHUB_ENV

# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v0.7.1
with:
workload_identity_provider: 'projects/143793276228/locations/global/workloadIdentityPools/github-actions/providers/github-oidc'
service_account: 'github-service-account@zealous-zebra.iam.gserviceaccount.com'
token_format: 'access_token'

- name: Create GCP compute instance
id: create-instance
if: (${{ inputs.needs_constants }} && steps.changed-files-specific.outputs.any_changed == 'true' && github.event_name == 'push') || ${{ !inputs.needs_constants }}
run: |
gcloud compute instances create-with-container "${{ inputs.test_id }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}" \
--boot-disk-size 100GB \
--boot-disk-type pd-ssd \
--create-disk name="${{ inputs.test_id }}-${{ env.GITHUB_SHA_SHORT }}",device-name="${{ inputs.test_id }}-${{ env.GITHUB_SHA_SHORT }}",size=100GB,type=pd-ssd \
--container-mount-disk mount-path="${{ inputs.zebra_state_path }}",name="${{ inputs.test_id }}-${{ env.GITHUB_SHA_SHORT }}" \
--container-image debian:buster \
--container-restart-policy=never \
--machine-type ${{ env.MACHINE_TYPE }} \
--scopes cloud-platform \
--metadata=google-monitoring-enabled=true,google-logging-enabled=true \
--tags ${{ inputs.app_name }} \
--zone "${{ env.ZONE }}"
sleep 60

- name: Run ${{ inputs.test_id }} test
run: |
gcloud compute ssh \
${{ inputs.test_id }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \
--zone ${{ env.ZONE }} \
--quiet \
--ssh-flag="-o ServerAliveInterval=5" \
--command \
"docker run ${{ inputs.test_variables }} -t --name ${{ inputs.test_id }} \
--mount type=bind,source=/mnt/disks/gce-containers-mounts/gce-persistent-disks/${{ inputs.test_id }}-${{ env.GITHUB_SHA_SHORT }},target=${{ inputs.zebra_state_path }} \
${{ env.GAR_BASE }}/${{ env.IMAGE_NAME }}:sha-${{ env.GITHUB_SHA_SHORT }}"

EXIT_CODE=$(\
gcloud compute ssh \
${{ inputs.test_id }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \
--zone ${{ env.ZONE }} \
--quiet \
--ssh-flag="-o ServerAliveInterval=5" \
--command="docker wait ${{ inputs.test_id }}")

exit ${EXIT_CODE}

- name: Get state version from constants.rs
run: |
STATE_VERSION=""

LOCAL_STATE_VERSION=$(grep -oE "DATABASE_FORMAT_VERSION: .* [0-9]+" $GITHUB_WORKSPACE/zebra-state/src/constants.rs | grep -oE "[0-9]+" | tail -n1)
echo "STATE_VERSION: $LOCAL_STATE_VERSION"

echo "STATE_VERSION=$LOCAL_STATE_VERSION" >> $GITHUB_ENV

- name: Get sync height from logs
run: |
SYNC_HEIGHT=""

DOCKER_LOGS=$(\
gcloud compute ssh \
${{ inputs.test_id }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \
--zone ${{ env.ZONE }} \
--quiet \
--ssh-flag="-o ServerAliveInterval=5" \
--command="docker logs ${{ inputs.test_id }} --tail 20")

SYNC_HEIGHT=$(echo $DOCKER_LOGS | grep -oE '${{ inputs.height_grep_text }}\([0-9]+\)' | grep -oE '[0-9]+' | tail -1 || [[ $? == 1 ]])
echo "SYNC_HEIGHT=$SYNC_HEIGHT" >> $GITHUB_ENV

# Create image from disk that will be used for following tests
# Force the image creation as the disk is still attached even though is not being used by the container
- name: Create image from state disk
if: ${{ inputs.saves_to_disk }}
run: |
gcloud compute images create ${{ inputs.disk_prefix }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}-v${{ env.STATE_VERSION }}-${{ env.NETWORK }}-${{ inputs.disk_suffix }} \
--force \
--source-disk=${{ inputs.test_id }}-${{ env.GITHUB_SHA_SHORT }} \
--source-disk-zone=${{ env.ZONE }} \
--storage-location=us \
--description="Created from commit ${{ env.GITHUB_SHA_SHORT }} with height ${{ env.SYNC_HEIGHT }}"

- name: Delete test instance
# If the disk generation step timeouts (+6 hours) the previous step (creating the image) willl be skipped.
# Even if the instance continues running, no image will be created, so it's better to delete it.
if: always()
continue-on-error: true
run: |
INSTANCE=$(gcloud compute instances list --filter=${{ inputs.test_id }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} --format='value(NAME)')
if [ -z "${INSTANCE}" ]; then
echo "No instance to delete"
else
gcloud compute instances delete "${INSTANCE}" --zone "${{ env.ZONE }}" --delete-disks all --quiet
fi

test-with-cached-state:
name: Test generated cached state
if: ${{ !inputs.saves_to_disk }}
runs-on: ubuntu-latest
needs: sync
permissions:
contents: 'read'
id-token: 'write'
steps:
- uses: actions/checkout@v3.0.2
with:
persist-credentials: false
fetch-depth: '2'

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
short-length: 7

- name: Downcase network name for disks
run: |
NETWORK_CAPS=${{ github.event.inputs.network || env.NETWORK }}
echo "NETWORK=${NETWORK_CAPS,,}" >> $GITHUB_ENV

# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v0.7.1
with:
workload_identity_provider: 'projects/143793276228/locations/global/workloadIdentityPools/github-actions/providers/github-oidc'
service_account: 'github-service-account@zealous-zebra.iam.gserviceaccount.com'
token_format: 'access_token'

# Before executing any further steps, validate the local state and remote version are the same,
# or at least that the local state version is greater than the available cached state version from main.
#
# Aftwards, get the disk name to be used on further steps
- name: Validate local state version with cached state
id: get-disk-name
run: |
LOCAL_STATE_VERSION=$(grep -oE "DATABASE_FORMAT_VERSION: .* [0-9]+" "$GITHUB_WORKSPACE/zebra-state/src/constants.rs" | grep -oE "[0-9]+" | tail -n1)
echo "LOCAL_STATE_VERSION: $LOCAL_STATE_VERSION"

ZEBRA_STATE_DISK=$(gcloud compute images list --filter="name~${{ inputs.disk_prefix }} AND name~-${{ inputs.disk_suffix }}" --format="value(NAME)" --sort-by=~creationTimestamp --limit=1)
echo "Disk: $ZEBRA_STATE_DISK"
echo "Description: $(gcloud compute images describe $ZEBRA_STATE_DISK --format='value(DESCRIPTION)')"

GCP_STATE_VERSION=$(echo "$ZEBRA_STATE_DISK" | grep -oE "v[0-9]+" | grep -oE "[0-9]+")
echo "GCP_STATE_VERSION: $GCP_STATE_VERSION"

if [[ "$LOCAL_STATE_VERSION" -lt "$GCP_STATE_VERSION" ]]; then echo "Local version is lower than cached version" && exit 1; fi

echo "ZEBRA_CACHED_DISK_NAME=$ZEBRA_STATE_DISK" >> $GITHUB_ENV

# Creates Compute Engine virtual machine instance w/ disks
- name: Create GCP compute instance
id: create-instance
run: |
gcloud compute instances create-with-container "${{ inputs.test_id }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}" \
--boot-disk-size 100GB \
--boot-disk-type pd-ssd \
--create-disk image=${{ env.ZEBRA_CACHED_DISK_NAME }},name="${{ inputs.disk_prefix }}-${{ inputs.test_id }}-${{ env.GITHUB_SHA_SHORT }}",device-name="${{ inputs.disk_prefix }}-${{ inputs.test_id }}-${{ env.GITHUB_SHA_SHORT }}",size=100GB,type=pd-ssd \
--container-mount-disk mount-path="${{ inputs.zebra_state_path }}",name="${{ inputs.disk_prefix }}-${{ inputs.test_id }}-${{ env.GITHUB_SHA_SHORT }}" \
--container-image debian:buster \
--container-restart-policy=never \
--machine-type ${{ env.MACHINE_TYPE }} \
--scopes cloud-platform \
--metadata=google-monitoring-enabled=true,google-logging-enabled=true \
--tags ${{ inputs.app_name }} \
--zone "${{ env.ZONE }}"
sleep 60

- name: Run ${{ inputs.test_id }} test
run: |
gcloud compute ssh \
${{ inputs.test_id }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \
--zone ${{ env.ZONE }} \
--quiet \
--ssh-flag="-o ServerAliveInterval=5" \
--command \
"docker run ${{ inputs.test_variables }} -t --name ${{ inputs.test_id }} \
--mount type=bind,source=/mnt/disks/gce-containers-mounts/gce-persistent-disks/${{ inputs.disk_prefix }}-${{ inputs.test_id }}-${{ env.GITHUB_SHA_SHORT }},target=${{ inputs.zebra_state_path }} \
${{ env.GAR_BASE }}/${{ env.IMAGE_NAME }}:sha-${{ env.GITHUB_SHA_SHORT }}"

EXIT_CODE=$(\
gcloud compute ssh \
${{ inputs.test_id }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \
--zone ${{ env.ZONE }} \
--quiet \
--ssh-flag="-o ServerAliveInterval=5" \
--command="docker wait ${{ inputs.test_id }}")

exit ${EXIT_CODE}

- name: Delete test instance
# We don't want to leave a failed instance in GCP using resources
if: always()
continue-on-error: true
run: |
INSTANCE=$(gcloud compute instances list --filter=${{ inputs.test_id }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} --format='value(NAME)')
if [ -z "${INSTANCE}" ]; then
echo "No instance to delete"
else
gcloud compute instances delete "${INSTANCE}" --zone "${{ env.ZONE }}" --delete-disks all --quiet
fi
Loading