diff --git a/.github/workflows/scripts/gcp-get-cached-disks.sh b/.github/workflows/scripts/gcp-get-cached-disks.sh index 6d82c27096e..9b33359b4f8 100755 --- a/.github/workflows/scripts/gcp-get-cached-disks.sh +++ b/.github/workflows/scripts/gcp-get-cached-disks.sh @@ -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 diff --git a/.github/workflows/sub-deploy-integration-tests-gcp.yml b/.github/workflows/sub-deploy-integration-tests-gcp.yml index 5e23715fa3b..c1427497c67 100644 --- a/.github/workflows/sub-deploy-integration-tests-gcp.yml +++ b/.github/workflows/sub-deploy-integration-tests-gcp.yml @@ -97,6 +97,29 @@ 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. # @@ -104,10 +127,12 @@ jobs: 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' @@ -152,38 +177,8 @@ jobs: - name: Set up Cloud SDK uses: google-github-actions/setup-gcloud@v2.1.1 - # 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 @@ -191,8 +186,8 @@ jobs: 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 \ diff --git a/.github/workflows/sub-find-cached-disks.yml b/.github/workflows/sub-find-cached-disks.yml index faab86a860c..392caa2597a 100644 --- a/.github/workflows/sub-find-cached-disks.yml +++ b/.github/workflows/sub-find-cached-disks.yml @@ -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 }}