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

change(ci): Generate testnet checkpoints in CI #6581

Merged
merged 17 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Split checking for cached state disks into its own workflow
  • Loading branch information
teor2345 committed Apr 27, 2023
commit 1e559d9fbb78fe7d9ef70330d02cffd9330607de
89 changes: 15 additions & 74 deletions .github/workflows/continous-integration-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,84 +77,26 @@ on:
- '.github/workflows/build-docker-image.yml'

jobs:

get-available-disks:
runs-on: ubuntu-latest
name: Find available cached state disks
name: Check if cached state disks exist for ${{ inputs.network || vars.ZCASH_NETWORK }}
outputs:
lwd_tip_disk: ${{ steps.get-available-disks.outputs.lwd_tip_disk }}
zebra_tip_disk: ${{ steps.get-available-disks.outputs.zebra_tip_disk }}
zebra_checkpoint_disk: ${{ steps.get-available-disks.outputs.zebra_checkpoint_disk }}
permissions:
contents: 'read'
id-token: 'write'
steps:
- uses: actions/checkout@v3.5.2
with:
persist-credentials: false
fetch-depth: 0

# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v1.1.0
with:
retries: '3'
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}'

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1.1.0

# Disk images in GCP are required to be in lowercase, but the blockchain network
# uses sentence case, so we need to downcase ${{ vars.ZCASH_NETWORK or github.event.inputs.network }}
#
# Passes a lowercase Network name to subsequent steps using $NETWORK env variable
- name: Downcase network name for disks
run: |
NETWORK_CAPS=${{ github.event.inputs.network || vars.ZCASH_NETWORK }}
echo "NETWORK=${NETWORK_CAPS,,}" >> $GITHUB_ENV
uses: ./.github/workflows/find-cached-disks.yml
with:
network: ${{ inputs.network || vars.ZCASH_NETWORK }}

# Find a cached state disk for subsequent jobs needing a cached state without
# restricting the result from any branch.
#
# This search is executed considering the actual version from constants.rs
#
# Generate one of the following outputs with a boolean to pass to subsequent jobs:
# - lwd_tip_disk
# - zebra_tip_disk
# - zebra_checkpoint_disk
- name: Find cached state disks
id: get-available-disks
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 "STATE_VERSION: $LOCAL_STATE_VERSION"

LWD_TIP_DISK=$(gcloud compute images list --filter="status=READY AND name~lwd-cache-.+-[0-9a-f]+-v${LOCAL_STATE_VERSION}-${NETWORK}-tip" --format="value(NAME)" --sort-by=~creationTimestamp --limit=1)
if [[ -z "$LWD_TIP_DISK" ]]; then
echo "No TIP disk found for LWD"
echo "lwd_tip_disk=${{ toJSON(false) }}" >> "$GITHUB_OUTPUT"
else
echo "Disk: $LWD_TIP_DISK"
echo "lwd_tip_disk=${{ toJSON(true) }}" >> "$GITHUB_OUTPUT"
fi

ZEBRA_TIP_DISK=$(gcloud compute images list --filter="status=READY AND name~zebrad-cache-.+-[0-9a-f]+-v${LOCAL_STATE_VERSION}-${NETWORK}-tip" --format="value(NAME)" --sort-by=~creationTimestamp --limit=1)
if [[ -z "$ZEBRA_TIP_DISK" ]]; then
echo "No TIP disk found for ZEBRA"
echo "zebra_tip_disk=${{ toJSON(false) }}" >> "$GITHUB_OUTPUT"
else
echo "Disk: $ZEBRA_TIP_DISK"
echo "zebra_tip_disk=${{ toJSON(true) }}" >> "$GITHUB_OUTPUT"
fi

ZEBRA_CHECKPOINT_DISK=$(gcloud compute images list --filter="status=READY AND name~zebrad-cache-.+-[0-9a-f]+-v${LOCAL_STATE_VERSION}-${NETWORK}-checkpoint" --format="value(NAME)" --sort-by=~creationTimestamp --limit=1)
if [[ -z "$ZEBRA_CHECKPOINT_DISK" ]]; then
echo "No CHECKPOINT found for ZEBRA"
echo "zebra_checkpoint_disk=${{ toJSON(false) }}" >> "$GITHUB_OUTPUT"
else
echo "Disk: $ZEBRA_CHECKPOINT_DISK"
echo "zebra_checkpoint_disk=${{ toJSON(true) }}" >> "$GITHUB_OUTPUT"
fi
get-available-disks-testnet:
name: Check if cached state disks exist for Testnet
outputs:
lwd_tip_disk: ${{ steps.get-available-disks.outputs.lwd_tip_disk }}
zebra_tip_disk: ${{ steps.get-available-disks.outputs.zebra_tip_disk }}
zebra_checkpoint_disk: ${{ steps.get-available-disks.outputs.zebra_checkpoint_disk }}
uses: ./.github/workflows/find-cached-disks.yml
with:
network: 'Testnet'

build:
name: Build CI Docker
Expand All @@ -163,8 +105,7 @@ jobs:
dockerfile_path: ./docker/Dockerfile
dockerfile_target: tests
image_name: ${{ vars.CI_IMAGE_NAME }}
# The default network in the image is based on the default network variable in GitHub
network: ${{ vars.ZCASH_NETWORK }}
network: ${{ inputs.network || vars.ZCASH_NETWORK }}
checkpoint_sync: true
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
rust_backtrace: full
rust_lib_backtrace: full
Expand Down
99 changes: 99 additions & 0 deletions .github/workflows/find-cached-disks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Check if cached state disks exist
teor2345 marked this conversation as resolved.
Show resolved Hide resolved

on:
workflow_call:
inputs:
network:
description: 'The Zcash network used to look up the disks'
required: true
type: string
outputs:
lwd_tip_disk:
description: 'true if there is a lightwalletd and Zebra cached state disk, synced near the chain tip'
value: ${{ jobs.get-available-disks.outputs.lwd_tip_disk }}
zebra_tip_disk:
description: 'true if there is a Zebra cached state disk synced near the chain tip'
value: ${{ jobs.get-available-disks.outputs.zebra_tip_disk }}
zebra_checkpoint_disk:
description: 'true if there is a Zebra cached state disk synced to the mandatory Zebra checkpoint'
value: ${{ jobs.get-available-disks.outputs.zebra_checkpoint_disk }}

jobs:
get-available-disks:
name: Check if cached state disks exist
runs-on: ubuntu-latest
outputs:
lwd_tip_disk: ${{ steps.get-available-disks.outputs.lwd_tip_disk }}
zebra_tip_disk: ${{ steps.get-available-disks.outputs.zebra_tip_disk }}
zebra_checkpoint_disk: ${{ steps.get-available-disks.outputs.zebra_checkpoint_disk }}
permissions:
contents: 'read'
id-token: 'write'
steps:
- uses: actions/checkout@v3.5.2
with:
persist-credentials: false
fetch-depth: 0

# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v1.1.0
with:
retries: '3'
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}'

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1.1.0

# Disk images in GCP are required to be in lowercase, but the blockchain network
# uses sentence case, so we need to downcase ${{ inputs.network }}
#
# Passes a lowercase Network name to subsequent steps using $NETWORK env variable
- name: Downcase network name for disks
run: |
NETWORK_CAPS=${{ inputs.network }}
echo "NETWORK=${NETWORK_CAPS,,}" >> $GITHUB_ENV

# Check if there are cached state disks available for subsequent jobs to use.
#
# This lookup uses the state version from constants.rs.
# It accepts disks generated by any branch, including draft and unmerged PRs.
#
# If the disk exists, sets the corresponding output to "true":
# - lwd_tip_disk
# - zebra_tip_disk
# - zebra_checkpoint_disk
- name: Check if cached state disks exist
id: get-available-disks
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 "STATE_VERSION: $LOCAL_STATE_VERSION"

LWD_TIP_DISK=$(gcloud compute images list --filter="status=READY AND name~lwd-cache-.+-[0-9a-f]+-v${LOCAL_STATE_VERSION}-${NETWORK}-tip" --format="value(NAME)" --sort-by=~creationTimestamp --limit=1)
if [[ -z "$LWD_TIP_DISK" ]]; then
echo "No TIP disk found for LWD"
echo "lwd_tip_disk=${{ toJSON(false) }}" >> "$GITHUB_OUTPUT"
else
echo "Disk: $LWD_TIP_DISK"
echo "lwd_tip_disk=${{ toJSON(true) }}" >> "$GITHUB_OUTPUT"
fi

ZEBRA_TIP_DISK=$(gcloud compute images list --filter="status=READY AND name~zebrad-cache-.+-[0-9a-f]+-v${LOCAL_STATE_VERSION}-${NETWORK}-tip" --format="value(NAME)" --sort-by=~creationTimestamp --limit=1)
if [[ -z "$ZEBRA_TIP_DISK" ]]; then
echo "No TIP disk found for ZEBRA"
echo "zebra_tip_disk=${{ toJSON(false) }}" >> "$GITHUB_OUTPUT"
else
echo "Disk: $ZEBRA_TIP_DISK"
echo "zebra_tip_disk=${{ toJSON(true) }}" >> "$GITHUB_OUTPUT"
fi

ZEBRA_CHECKPOINT_DISK=$(gcloud compute images list --filter="status=READY AND name~zebrad-cache-.+-[0-9a-f]+-v${LOCAL_STATE_VERSION}-${NETWORK}-checkpoint" --format="value(NAME)" --sort-by=~creationTimestamp --limit=1)
if [[ -z "$ZEBRA_CHECKPOINT_DISK" ]]; then
echo "No CHECKPOINT found for ZEBRA"
echo "zebra_checkpoint_disk=${{ toJSON(false) }}" >> "$GITHUB_OUTPUT"
else
echo "Disk: $ZEBRA_CHECKPOINT_DISK"
echo "zebra_checkpoint_disk=${{ toJSON(true) }}" >> "$GITHUB_OUTPUT"
fi