Skip to content

Commit

Permalink
fix(ci): convert the get-disk-name to a job
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavovalverde committed Sep 12, 2024
1 parent 40fdc5c commit 6fb9f10
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/scripts/gcp-get-cached-disks.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#!/usr/bin/env bash

# Description:
# This script finds a cached Google Cloud Compute image based on specific criteria.
# It prioritizes images from the current commit, falls back to the main branch,
# and finally checks other branches if needed. The selected image is used for
# setting up the environment in a CI/CD pipeline. It also checks if specific
# disk types are available for subsequent jobs.
#
# If there are multiple disks:
# - prefer images generated from the same commit, then
# - if prefer_main_cached_state is true, prefer images from the `main` branch, then
# - use any images from any other branch or commit.
#
# Within each of these categories:
# - prefer newer images to older images
#
# The selected image is used for setting up the environment in a CI/CD pipeline.
# It also checks if specific disk types are available for subsequent jobs.

set -exo pipefail

Expand Down
65 changes: 30 additions & 35 deletions .github/workflows/sub-deploy-integration-tests-gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,42 @@ env:
CACHED_STATE_UPDATE_LIMIT: 576

jobs:
# Find a cached state disk for ${{ inputs.test_id }}, matching all of:
# - disk cached state prefix -> zebrad-cache or lwd-cache
# - state version (from the source code) - v{N}
# - network (network) - mainnet or testnet
# - disk target height kind (disk_suffix) - checkpoint or tip
#
# If the test needs a lightwalletd state (needs_lwd_state) set the input disk_prefix accordingly
# - To lwd-cache if needed
# - To zebrad-cache if not
#
# Passes the disk name to subsequent steps using `cached_disk_name` output
# Passes the state version to subsequent steps using `state_version` output
#
get-test-disk:
name: Get ${{ inputs.test_id }} disk name
if: ${{ inputs.needs_zebra_state || inputs.needs_lwd_state }}
uses: ./.github/workflows/sub-find-cached-disks.yml
with:
network: ${{ inputs.network || vars.ZCASH_NETWORK }}
disk_prefix: ${{ inputs.needs_lwd_state && 'lwd-cache' || inputs.needs_zebra_state && 'zebrad-cache' }}
disk_suffix: ${{ inputs.disk_suffix }}
prefer_main_cached_state: ${{ inputs.prefer_main_cached_state }}}

# Show all the test logs, then follow the logs of the test we just launched, until it finishes.
# Then check the result of the test.
#
# If `inputs.is_long_test` is `true`, the timeout is 5 days, otherwise it's 3 hours.
test-result:
name: Run ${{ inputs.test_id }} test
runs-on: zfnd-runners
needs: [ get-test-disk ]
if: ${{ !cancelled() && !failure() }}
timeout-minutes: ${{ inputs.is_long_test && 7200 || 180 }}
outputs:
cached_disk_name: ${{ steps.get-disk-name.outputs.cached_disk_name }}
state_version: ${{ steps.get-disk-name.outputs.state_version }}
cached_disk_name: ${{ needs.get-test-disk.outputs.cached_disk_name }}
state_version: ${{ needs.get-test-disk.outputs.state_version }}
permissions:
contents: 'read'
id-token: 'write'
Expand Down Expand Up @@ -152,47 +177,17 @@ jobs:
- name: Set up Cloud SDK
uses: google-github-actions/[email protected]

# Find a cached state disk for this job, matching all of:
# - disk cached state prefix -> zebrad-cache or lwd-cache
# - state version (from the source code) - v{N}
# - network (network) - mainnet or testnet
# - disk target height kind (disk_suffix) - checkpoint or tip
#
# If the test needs a lightwalletd state (needs_lwd_state) set the variable CACHE_PREFIX accordingly
# - To lwd-cache if needed
# - To zebrad-cache if not
#
# If there are multiple disks:
# - prefer images generated from the same commit, then
# - if prefer_main_cached_state is true, prefer images from the `main` branch, then
# - use any images from any other branch or commit.
# Within each of these categories:
# - prefer newer images to older images
#
# Passes the disk name to subsequent steps using $CACHED_DISK_NAME env variable
# Passes the state version to subsequent steps using $STATE_VERSION env variable
#
- name: Find ${{ inputs.test_id }} cached state disk
id: get-disk-name
if: ${{ inputs.needs_zebra_state || inputs.needs_lwd_state }}
uses: ./.github/workflows/sub-find-cached-disks.yml
with:
network: ${{ inputs.network || vars.ZCASH_NETWORK }}
disk_prefix: ${{ inputs.needs_lwd_state && 'lwd-cache' || inputs.needs_zebra_state && 'zebrad-cache' }}
disk_suffix: ${{ inputs.disk_suffix }}
prefer_main_cached_state: ${{ inputs.prefer_main_cached_state }}

# Create a Compute Engine virtual machine and attach a cached state disk using the
# $CACHED_DISK_NAME variable as the source image to populate the disk cached state
# cached_disk_name output as the source image to populate the disk cached state
# if the test needs it.
- name: Create ${{ inputs.test_id }} GCP compute instance
id: create-instance
shell: /usr/bin/bash -x {0}
run: |
NAME="${{ inputs.test_id }}-${{ env.GITHUB_SHA_SHORT }}"
DISK_PARAMS="size=400GB,type=pd-ssd,name=${NAME},device-name=${NAME}"
if [ -n "${{ steps.get-disk-name.outputs.cached_disk_name }}" ]; then
DISK_PARAMS+=",image=${{ steps.get-disk-name.outputs.cached_disk_name }}"
if [ -n "${{ needs.get-test-disk.outputs.cached_disk_name }}" ]; then
DISK_PARAMS+=",image=${{ needs.get-test-disk.outputs.cached_disk_name }}"
fi
gcloud compute instances create-with-container "${{ inputs.test_id }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}" \
--boot-disk-size 50GB \
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/sub-find-cached-disks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ on:

jobs:
get-cached-disks:
name: Check if cached state disks exist
runs-on: ubuntu-latest
outputs:
state_version: ${{ steps.get-available-disks.outputs.state_version }}
Expand Down

0 comments on commit 6fb9f10

Please sign in to comment.