-
Notifications
You must be signed in to change notification settings - Fork 208
125 lines (118 loc) · 6.12 KB
/
sub-find-cached-disks.yml
File metadata and controls
125 lines (118 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Check if Cached State Disks Exist Workflow
# This workflow is designed to check the availability of cached state disks in Google Cloud Platform (GCP) for different types of Zcash applications.
# - Accepts network type as input to determine which disks to search for.
# - Checks for the existence of three types of disks: lightwalletd tip, Zebra tip, and Zebra checkpoint.
# - Uses Google Cloud SDK to query and identify available disks based on network and version.
# - Outputs the availability of each disk type, which can be utilized in subsequent workflows.
# The workflow streamlines the process of verifying disk availability, crucial for optimizing and speeding up integration tests and deployments.
name: Check if cached state disks exist
on:
workflow_call:
inputs:
network:
description: 'The Zcash network used to look up the disks'
required: true
type: string
disk_prefix:
required: false
type: string
disk_suffix:
required: false
type: string
test_id:
description: 'The test ID requiring the cached state disks'
required: false
type: string
outputs:
state_version:
description: 'The version of the cached state disks'
value: ${{ jobs.get-cached-disks.outputs.state_version }}
cached_disk_name:
description: 'The name of the cached state disk'
value: ${{ jobs.get-cached-disks.outputs.cached_disk_name }}
lwd_tip_disk:
description: 'true if there is a lightwalletd and Zebra cached state disk, synced near the chain tip'
value: ${{ jobs.get-cached-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-cached-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-cached-disks.outputs.zebra_checkpoint_disk }}
jobs:
get-cached-disks:
name: Get ${{ inputs.test_id || inputs.network }} cached disk
runs-on: ubuntu-latest
environment: ${{ github.event_name == 'release' && 'prod' || 'dev' }}
outputs:
state_version: ${{ steps.get-available-disks.outputs.state_version || steps.set-release-defaults.outputs.state_version }}
cached_disk_name: ${{ steps.get-available-disks.outputs.cached_disk_name || steps.set-release-defaults.outputs.cached_disk_name }}
lwd_tip_disk: ${{ steps.get-available-disks.outputs.lwd_tip_disk || steps.set-release-defaults.outputs.lwd_tip_disk }}
zebra_tip_disk: ${{ steps.get-available-disks.outputs.zebra_tip_disk || steps.set-release-defaults.outputs.zebra_tip_disk }}
zebra_checkpoint_disk: ${{ steps.get-available-disks.outputs.zebra_checkpoint_disk || steps.set-release-defaults.outputs.zebra_checkpoint_disk }}
permissions:
contents: 'read'
id-token: 'write'
steps:
- uses: actions/checkout@v4.2.2
with:
persist-credentials: false
fetch-depth: 0
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v5
with:
short-length: 7
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2.1.10
with:
workload_identity_provider: '${{ vars.GCP_WIF }}'
service_account: '${{ vars.GCP_DEPLOYMENTS_SA }}'
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2.1.4
# Performs formatting on disk name components.
#
# Disk images in GCP are required to be in lowercase, but the blockchain network
# uses sentence case, so we need to downcase ${{ inputs.network }}.
#
# Disk image names in GCP are limited to 63 characters, so we need to limit
# branch names to 12 characters.
# Check the `create-state-image` in `sub-deploy-integration-tests-gcp.yml` for more details in image names.
# More info: https://cloud.google.com/compute/docs/naming-resources#resource-name-format
#
# Passes ${{ inputs.network }} to subsequent steps using $NETWORK env variable.
# Passes ${{ env.GITHUB_REF_POINT_SLUG_URL }} to subsequent steps using $SHORT_GITHUB_REF env variable.
- name: Format network name and branch name for disks
run: |
NETWORK_CAPS="${{ inputs.network }}"
echo "ZEBRA_NETWORK__NETWORK=${NETWORK_CAPS,,}" >> "$GITHUB_ENV"
LONG_GITHUB_REF="${{ env.GITHUB_REF_POINT_SLUG_URL }}"
echo "SHORT_GITHUB_REF=${LONG_GITHUB_REF:0:12}" >> "$GITHUB_ENV"
# Check if there are cached state disks available for subsequent jobs to use.
# Skip disk lookup for releases - they should deploy from scratch or use production disks
- name: Check if cached state disks exists
id: get-available-disks
if: ${{ github.event_name != 'release' }}
env:
GITHUB_REF: ${{ env.SHORT_GITHUB_REF }}
NETWORK: ${{ env.NETWORK }} # use lowercase version from env, not input
DISK_PREFIX: ${{ inputs.disk_prefix }}
DISK_SUFFIX: ${{ inputs.disk_suffix }}
run: |
source ./.github/workflows/scripts/gcp-get-cached-disks.sh
echo "state_version=${LOCAL_STATE_VERSION}" >> "${GITHUB_OUTPUT}"
echo "cached_disk_name=${CACHED_DISK_NAME}" >> "${GITHUB_OUTPUT}"
echo "lwd_tip_disk=${LWD_TIP_DISK}" >> "${GITHUB_OUTPUT}"
echo "zebra_tip_disk=${ZEBRA_TIP_DISK}" >> "${GITHUB_OUTPUT}"
echo "zebra_checkpoint_disk=${ZEBRA_CHECKPOINT_DISK}" >> "${GITHUB_OUTPUT}"
# For releases, set default outputs indicating no cached disks are available
- name: Set default outputs for releases
id: set-release-defaults
if: ${{ github.event_name == 'release' }}
run: |
echo "state_version=" >> "${GITHUB_OUTPUT}"
echo "cached_disk_name=" >> "${GITHUB_OUTPUT}"
echo "lwd_tip_disk=false" >> "${GITHUB_OUTPUT}"
echo "zebra_tip_disk=false" >> "${GITHUB_OUTPUT}"
echo "zebra_checkpoint_disk=false" >> "${GITHUB_OUTPUT}"