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): validate state version with cached state #4074

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0221a74
fix(ci): correctly use lowered network caps
gustavovalverde Apr 9, 2022
0d9dc12
imp(ci): get state version from local constants.rs
gustavovalverde Apr 9, 2022
3904f61
imp(ci): use the same get name approach
gustavovalverde Apr 9, 2022
9833ef2
fix(ci): use the correct name for state version variable
gustavovalverde Apr 9, 2022
dc765b7
Merge branch 'main' into fix-disk-naming
gustavovalverde Apr 9, 2022
1c214ee
imp(ci)!: use different disk names for cached states
gustavovalverde Apr 9, 2022
a0b2eac
imp(ci): test-stateful-sync no longer depends on regenerate-stateful-…
gustavovalverde Apr 9, 2022
8726eda
feat(ci): validate state version with cached state
gustavovalverde Apr 9, 2022
cbbfaf4
Apply suggestions from code review
gustavovalverde Apr 9, 2022
2d026be
fix(ci): use a better name for network string conversion
gustavovalverde Apr 9, 2022
1ea389b
Merge branch 'fix-disk-naming' of github.com:ZcashFoundation/zebra in…
gustavovalverde Apr 9, 2022
22ba55c
Revert "Apply suggestions from code review"
gustavovalverde Apr 9, 2022
c478b2c
Merge branch 'fix-disk-naming' into feat-state-versioning
gustavovalverde Apr 9, 2022
db9b9e9
fix(ci): just validate versions if constants.rs does not change
gustavovalverde Apr 9, 2022
70d3b9e
fix(ci): add same constants.rs validation to full sync
gustavovalverde Apr 9, 2022
a563abf
fix: do not get log information if sync was skipped
gustavovalverde Apr 9, 2022
fdfc886
Merge branch 'fix-disk-naming' into feat-state-versioning
gustavovalverde Apr 9, 2022
42f0f04
fix(ci): do not lower the variable name
gustavovalverde Apr 10, 2022
ac41ef9
fix(ci): use the same lowering case for network everywhere
gustavovalverde Apr 10, 2022
6a36533
test: more .dockerignore conditions
gustavovalverde Apr 10, 2022
a144423
fix: use the right approach to lower caps
gustavovalverde Apr 10, 2022
4bb1725
Merge branch 'fix-disk-naming' into feat-state-versioning
gustavovalverde Apr 10, 2022
c80c677
remove extra .dockerignore
gustavovalverde Apr 10, 2022
f1ea775
trigger a change for stateful disk regeneration
gustavovalverde Apr 10, 2022
4ebec9d
imp(ci): use `checkpoint` as the disk reference
gustavovalverde Apr 11, 2022
39d0b8b
revert wrong delete
gustavovalverde Apr 11, 2022
4a614af
fix(ci): add INSTANCE_ID and correct logging message
gustavovalverde Apr 11, 2022
0b332ab
imp(ci): add `v` prefix to state version number
gustavovalverde Apr 11, 2022
8f0f469
fix(ci): remove typo from logging message to get the height
gustavovalverde Apr 11, 2022
53876d8
Merge branch 'fix-disk-naming' into feat-state-versioning
gustavovalverde Apr 11, 2022
8f24f0f
fix(ci): use correct comments and conditions for constants.rs changes
gustavovalverde Apr 11, 2022
e8a9e76
Update .github/workflows/test-full-sync.yml
gustavovalverde Apr 11, 2022
2ce729a
fix: use newet `checkpoint` disk reference
gustavovalverde Apr 12, 2022
4ea9e93
test: force a change to validate behavior
gustavovalverde Apr 12, 2022
f9f995b
Merge branch 'feat-state-versioning' of github.com:ZcashFoundation/ze…
gustavovalverde Apr 12, 2022
9e9ca0b
revert force rebuild
gustavovalverde Apr 12, 2022
0e45e4c
Merge branch 'main' into feat-state-versioning
gustavovalverde Apr 12, 2022
2564f50
fix(ci): grep correctly and exit with a message
gustavovalverde Apr 12, 2022
09a865f
Merge branch 'main' into feat-state-versioning
gustavovalverde Apr 14, 2022
3e53ee8
Merge branch 'main' into feat-state-versioning
gustavovalverde Apr 14, 2022
e9896eb
Merge branch 'main' into feat-state-versioning
gustavovalverde Apr 18, 2022
8945e57
fix(ci): compare against main branch
gustavovalverde Apr 19, 2022
43b20ad
fix(ci): just create disk when rebuild files are changed
gustavovalverde Apr 19, 2022
9509782
refactor(ci): use latest disk just on PRs and manual triggers
gustavovalverde Apr 19, 2022
a7c6b0f
fix(ci): avoid cross-contamination between PRs
gustavovalverde Apr 19, 2022
45a0aa7
style(ci): fix shellcheck warnings
gustavovalverde Apr 19, 2022
3372cd3
imp(ci): do not repeat conditions if not needed
gustavovalverde Apr 19, 2022
3d7aec7
docs(ci): improve reasoning behind new disk selection conditions
gustavovalverde Apr 19, 2022
ff4e40c
Merge branch 'main' into feat-state-versioning
mergify[bot] Apr 20, 2022
c47cccb
Merge branch 'main' into feat-state-versioning
gustavovalverde Apr 27, 2022
fa5925d
Merge branch 'main' into feat-state-versioning
gustavovalverde May 2, 2022
1099369
fix merge
gustavovalverde May 2, 2022
a82d3e9
fix(ci): use tip disk for full sync
gustavovalverde May 2, 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
30 changes: 22 additions & 8 deletions .github/workflows/test-full-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ jobs:
with:
short-length: 7

- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected]
with:
workload_identity_provider: 'projects/143793276228/locations/global/workloadIdentityPools/github-actions/providers/github-oidc'
service_account: '[email protected]'
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.
- name: Validate constants.rs version vs cached state version
id: validate-state-version
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"

GCP_STATE_DISK=$(gcloud compute images list --filter="name~zebrad-cache-main AND name~-tip" --format="value(NAME)" --sort-by=~creationTimestamp --limit=1)
GCP_STATE_VERSION=$(echo "$GCP_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

# Automatic tag management and OCI Image Format Specification for labels
- name: Docker meta
id: meta
Expand All @@ -105,14 +127,6 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v1

- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected]
with:
workload_identity_provider: 'projects/143793276228/locations/global/workloadIdentityPools/github-actions/providers/github-oidc'
service_account: '[email protected]'
token_format: 'access_token'

- name: Login to Google Artifact Registry
uses: docker/[email protected]
with:
Expand Down
97 changes: 67 additions & 30 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ jobs:
name: Build images
timeout-minutes: 210
runs-on: ubuntu-latest
outputs:
any_changed: ${{ steps.changed-files-specific.outputs.any_changed }}
permissions:
contents: 'read'
id-token: 'write'
Expand All @@ -83,6 +85,40 @@ jobs:
with:
short-length: 7

- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected]
with:
workload_identity_provider: 'projects/143793276228/locations/global/workloadIdentityPools/github-actions/providers/github-oidc'
service_account: '[email protected]'
token_format: 'access_token'

# If we change the version we want to rebuild the cached state disks,
# so we want to run the regenerate-stateful-disks to use the newer state in tests.
#
# If we change the state path without changing the version,
# the regenerate-stateful-disks 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/[email protected]
with:
files: |
zebra-state/**/constants.rs

# 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.
- name: Validate constants.rs version vs cached state version
id: validate-state-version
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"

GCP_STATE_DISK=$(gcloud compute images list --filter="name~zebrad-cache-main AND name~-checkpoint" --format="value(NAME)" --sort-by=~creationTimestamp --limit=1)
GCP_STATE_VERSION=$(echo "$GCP_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

# Automatic tag management and OCI Image Format Specification for labels
- name: Docker meta
id: meta
Expand All @@ -107,14 +143,6 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v1

- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected]
with:
workload_identity_provider: 'projects/143793276228/locations/global/workloadIdentityPools/github-actions/providers/github-oidc'
service_account: '[email protected]'
token_format: 'access_token'

- name: Login to Google Artifact Registry
uses: docker/[email protected]
with:
Expand Down Expand Up @@ -232,8 +260,6 @@ jobs:
name: Regenerate stateful disks
runs-on: ubuntu-latest
needs: build
outputs:
any_changed: ${{ steps.changed-files-specific.outputs.any_changed }}
permissions:
contents: 'read'
id-token: 'write'
Expand All @@ -243,21 +269,6 @@ jobs:
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/[email protected]
with:
files: |
zebra-state/**/constants.rs

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
Expand All @@ -280,7 +291,7 @@ jobs:
# Check if our destination compute instance exists and delete it
- name: Delete existing instance with same SHA
id: delete-old-instance
if: ${{ steps.changed-files-specific.outputs.any_changed == 'true' || github.event.inputs.regenerate-disks == 'true' || github.event_name == 'push'}}
if: ${{ needs.build.outputs.any_changed == 'true' || github.event.inputs.regenerate-disks == 'true' }}
run: |
INSTANCE=$(gcloud compute instances list --filter=regenerate-disk-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} --format='value(NAME)')
if [ -z "${INSTANCE}" ]; then
Expand All @@ -291,7 +302,7 @@ jobs:

- name: Create GCP compute instance
id: create-instance
if: ${{ steps.changed-files-specific.outputs.any_changed == 'true' || github.event.inputs.regenerate-disks == 'true' || github.event_name == 'push'}}
if: ${{ steps.delete-old-instance.outcome == 'skipped' }}
run: |
gcloud compute instances create-with-container "regenerate-disk-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}" \
--boot-disk-size 100GB \
Expand Down Expand Up @@ -446,10 +457,36 @@ jobs:
gcloud compute instances delete "${INSTANCE}" --zone "${{ env.ZONE }}" --delete-disks all --quiet
fi

- name: Get disk state name from gcloud
id: get-disk-name
# If a triggering file for a rebuild was changed on a PR or we manually triggered a rebuild,
# use the latest available disk state as the regenerate-stateful-disks job was executed
#
# In the regenerate-stateful-disks job we don't validate the github.event_name because we
# want to ensure the disk are regenerated on PR syncs and push events (to main), and when
# manually triggered.
#
# In this scenario we also valida that if a file like constants.rs was changed then a disk
# rebuild was triggered and we if this happened on a PR we want to use the cached disk from
# the PR and not the cached disk from main. Otherwise we move to the next step, which is
# get-main-disk-name as this was most likely triggered by a push in main, or constanst.rs
# was not changed, which allows us to use the disk from main, as a disk rebuild did not happened,
# and if the rebuilt happened then it was triggered on main and we want to use main's reference.
- name: Get latest state disk name from gcloud
id: get-latest-disk-name
if: ${{ (needs.build.outputs.any_changed == 'true' && github.event_name == 'pull_request') || github.event.inputs.regenerate-disks == 'true' }}
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
run: |
GCP_STATE_DISK=$(gcloud compute images list --filter="name~zebrad-cache-${{ env.GITHUB_REF_SLUG_URL }} AND name~-checkpoint" --format="value(NAME)" --sort-by=~creationTimestamp --limit=1)
gustavovalverde marked this conversation as resolved.
Show resolved Hide resolved
echo "Disk: $GCP_STATE_DISK"
echo "Description: $(gcloud compute images describe $GCP_STATE_DISK --format='value(DESCRIPTION)')"
teor2345 marked this conversation as resolved.
Show resolved Hide resolved

echo "CACHED_DISK_NAME=$GCP_STATE_DISK" >> $GITHUB_ENV
gustavovalverde marked this conversation as resolved.
Show resolved Hide resolved

# If the conditions in the get-latest-disk-name step were not applied means this was triggered by a push event,
# and we need to use the cached state from the main branch.
- name: Get main state disk name from gcloud
id: get-main-disk-name
if: ${{ steps.get-latest-disk-name.outcome == 'skipped' }}
run: |
GCP_STATE_DISK=$(gcloud compute images list --filter="name~zebrad-cache AND name~-checkpoint" --format="value(NAME)" --sort-by=~creationTimestamp --limit=1)
GCP_STATE_DISK=$(gcloud compute images list --filter="name~zebrad-cache-main AND name~-checkpoint" --format="value(NAME)" --sort-by=~creationTimestamp --limit=1)
echo "Disk: $GCP_STATE_DISK"
echo "Description: $(gcloud compute images describe $GCP_STATE_DISK --format='value(DESCRIPTION)')"

Expand Down