Skip to content

Commit

Permalink
ref(ci): Use a single CI workflow for tests
Browse files Browse the repository at this point in the history
This is an initial implementation to solve the re-building of our Docker image, which is being built multiple times by our Github Actions.

This is meant to fix -> devops: Build CI Docker runs twice for every PR #7816
  • Loading branch information
gustavovalverde committed Jun 3, 2024
1 parent 3147d20 commit 63340c3
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 193 deletions.
146 changes: 146 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# This workflow builds a Zebra Docker image and runs integration and unit tests
# on the Zebra codebase. It is designed to add the different test workflows
name: Run tests

# Ensures that only one workflow task will run at a time. Previous builds, if
# already in process, will get cancelled. Only the latest commit will be allowed
# to run, cancelling any workflows in between
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

on:
schedule:
# Run this job every Friday at mid-day UTC
# This is limited to the Zebra and lightwalletd Full Sync jobs
# TODO: we should move this behavior to a separate workflow
- cron: "0 12 * * 5"

workflow_dispatch:
inputs:
network:
default: "Mainnet"
description: "Network to deploy: Mainnet or Testnet"
required: true
regenerate-disks:
type: boolean
default: false
description: "Just run a Zebra checkpoint sync and update checkpoint disks"
required: true
run-full-sync:
type: boolean
default: false
description: "Just run a Zebra full sync on `network`, and update tip disks"
required: true
run-lwd-sync:
type: boolean
default: false
description: "Just run a lightwalletd full sync and update tip disks"
required: true
force_save_to_disk:
required: false
type: boolean
default: false
description: "Force tests to always create a cached state disk, if they already create disks"
no_cache:
description: "Disable the Docker cache for this build"
required: false
type: boolean
default: false

pull_request:
# Skip PRs where Rust code and dependencies aren't modified.
paths:
# code and tests
- "**/*.rs"
# hard-coded checkpoints and proptest regressions
- "**/*.txt"
# test data snapshots
- "**/*.snap"
# dependencies
- "**/Cargo.toml"
- "**/Cargo.lock"
# configuration files
- ".cargo/config.toml"
- "**/clippy.toml"
# workflow definitions
- "docker/**"
- ".dockerignore"
- ".github/workflows/ci-tests.yml"
- ".github/workflows/sub-deploy-integration-tests-gcp.yml"
- ".github/workflows/sub-find-cached-disks.yml"
- ".github/workflows/sub-build-docker-image.yml"

push:
# Skip main branch updates where Rust code and dependencies aren't modified.
branches:
- main
paths:
# code and tests
- "**/*.rs"
# hard-coded checkpoints and proptest regressions
- "**/*.txt"
# test data snapshots
- "**/*.snap"
# dependencies
- "**/Cargo.toml"
- "**/Cargo.lock"
# configuration files
- ".cargo/config.toml"
- "**/clippy.toml"
# workflow definitions
- "docker/**"
- ".dockerignore"
- ".github/workflows/ci-tests.yml"
- ".github/workflows/sub-deploy-integration-tests-gcp.yml"
- ".github/workflows/sub-find-cached-disks.yml"
- ".github/workflows/sub-build-docker-image.yml"

env:
RUST_LOG: ${{ vars.RUST_LOG }}
RUST_BACKTRACE: ${{ vars.RUST_BACKTRACE }}
RUST_LIB_BACKTRACE: ${{ vars.RUST_LIB_BACKTRACE }}
COLORBT_SHOW_HIDDEN: ${{ vars.COLORBT_SHOW_HIDDEN }}
CARGO_INCREMENTAL: ${{ vars.CARGO_INCREMENTAL }}

#! IMPORTANT
#!
#! The job names in `ci-tests.yml`, `ci-tests.patch.yml` and `ci-tests-.patch-external.yml`
#! must be kept in sync.
jobs:
# Build the docker image used by the tests.
#
# The default network in the Zebra config in the image is mainnet, unless a manually triggered
# workflow or repository variable is configured differently. Testnet jobs change that config to
# testnet when running the image.
build:
name: Build CI image
# Skip PRs from external repositories, let them pass, and then Mergify will check them
if: ${{ !startsWith(github.event_name, 'pull') || !github.event.pull_request.head.repo.fork }}
uses: ./.github/workflows/sub-build-docker-image.yml
with:
dockerfile_path: ./docker/Dockerfile
dockerfile_target: tests
image_name: ${{ vars.CI_IMAGE_NAME }}
no_cache: ${{ inputs.no_cache || false }}
rust_backtrace: full
rust_lib_backtrace: full
rust_log: info

# Runs Zebra unit tests
unit-tests:
name: Unit tests
# Skip Unit tests when the event is a scheduled run, as this is just needed for integration tests
if: ${{ github.event_name != 'schedule' }}
needs: build
uses: ./.github/workflows/sub-ci-unit-tests-docker.yml
with:
image_digest: ${{ needs.build.outputs.image_digest }}
secrets: inherit

# Runs Zebra integration tests
integration-tests:
name: Integration tests
needs: build
uses: ./.github/workflows/sub-ci-integration-tests-gcp.yml
secrets: inherit
Original file line number Diff line number Diff line change
Expand Up @@ -5,103 +5,32 @@
# Each test has a description of the conditions under which it runs.
name: Integration Tests on GCP

# Ensures that only one workflow task will run at a time. Previous builds, if
# already in process, will get cancelled. Only the latest commit will be allowed
# to run, cancelling any workflows in between
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

on:
schedule:
# Run this job every Friday at mid-day UTC
# This is limited to the Zebra and lightwalletd Full Sync jobs
# TODO: we should move this behavior to a separate workflow
- cron: '0 12 * * 5'

workflow_dispatch:
workflow_call:
inputs:
network:
default: 'Mainnet'
description: 'Network to deploy: Mainnet or Testnet'
required: true
type: string
regenerate-disks:
type: boolean
default: false
description: 'Just run a Zebra checkpoint sync and update checkpoint disks'
required: true
run-full-sync:
type: boolean
run-full-sync:
default: false
description: 'Just run a Zebra full sync on `network`, and update tip disks'
required: true
run-lwd-sync:
type: boolean
run-lwd-sync:
default: false
description: 'Just run a lightwalletd full sync and update tip disks'
required: true
force_save_to_disk:
required: false
type: boolean
force_save_to_disk:
default: false
description: 'Force tests to always create a cached state disk, if they already create disks'
no_cache:
description: 'Disable the Docker cache for this build'
required: false
type: boolean
no_cache:
default: false
type: boolean

pull_request:
# Skip PRs where Rust code and dependencies aren't modified.
paths:
# code and tests
- '**/*.rs'
# hard-coded checkpoints and proptest regressions
- '**/*.txt'
# test data snapshots
- '**/*.snap'
# dependencies
- '**/Cargo.toml'
- '**/Cargo.lock'
# configuration files
- '.cargo/config.toml'
- '**/clippy.toml'
# workflow definitions
- 'docker/**'
- '.github/workflows/ci-integration-tests-gcp.yml'
- '.github/workflows/sub-deploy-integration-tests-gcp.yml'
- '.github/workflows/sub-build-docker-image.yml'
- '.github/workflows/sub-find-cached-disks.yml'

push:
# Skip main branch updates where Rust code and dependencies aren't modified.
branches:
- main
paths:
# code and tests
- '**/*.rs'
# hard-coded checkpoints and proptest regressions
- '**/*.txt'
# test data snapshots
- '**/*.snap'
# dependencies
- '**/Cargo.toml'
- '**/Cargo.lock'
# configuration files
- '.cargo/config.toml'
- '**/clippy.toml'
# workflow definitions
- 'docker/**'
- '.dockerignore'
- '.github/workflows/ci-integration-tests-gcp.yml'
- '.github/workflows/sub-deploy-integration-tests-gcp.yml'
- '.github/workflows/sub-find-cached-disks.yml'
- '.github/workflows/sub-build-docker-image.yml'

# IMPORTANT
#
# The job names in `ci-integration-tests-gcp.yml`, `ci-integration-tests-gcp.patch.yml` and
# `ci-integration-tests-gcp.patch-external.yml` must be kept in sync.
#! IMPORTANT
#!
#! The job names in `ci-integration-tests-gcp.yml`, `ci-integration-tests-gcp.patch.yml` and
#! `ci-integration-tests-gcp.patch-external.yml` must be kept in sync.
jobs:
# to also run a job on Mergify head branches,
# add `|| (github.event_name == 'push' && startsWith(github.head_ref, 'mergify/merge-queue/'))`:
Expand Down Expand Up @@ -132,24 +61,6 @@ jobs:
with:
network: 'Testnet'

# Build the docker image used by the tests.
#
# The default network in the Zebra config in the image is mainnet, unless a manually triggered
# workflow or repository variable is configured differently. Testnet jobs change that config to
# testnet when running the image.
build:
name: Build CI Docker
if: ${{ !startsWith(github.event_name, 'pull') || !github.event.pull_request.head.repo.fork }}
uses: ./.github/workflows/sub-build-docker-image.yml
with:
dockerfile_path: ./docker/Dockerfile
dockerfile_target: tests
image_name: ${{ vars.CI_IMAGE_NAME }}
no_cache: ${{ inputs.no_cache || false }}
rust_backtrace: full
rust_lib_backtrace: full
rust_log: info

# zebrad cached checkpoint state tests

# Regenerate mandatory checkpoint Zebra cached state disks.
Expand All @@ -161,7 +72,7 @@ jobs:
# Note: the output from get-available-disks should match with the caller workflow inputs
regenerate-stateful-disks:
name: Zebra checkpoint
needs: [ build, get-available-disks ]
needs: [ get-available-disks ]
uses: ./.github/workflows/sub-deploy-integration-tests-gcp.yml
if: ${{ !fromJSON(needs.get-available-disks.outputs.zebra_checkpoint_disk) || github.event.inputs.regenerate-disks == 'true' }}
with:
Expand Down Expand Up @@ -218,7 +129,7 @@ jobs:
# Note: the output from get-available-disks should match with the caller workflow inputs
test-full-sync:
name: Zebra tip
needs: [ build, get-available-disks ]
needs: [ get-available-disks ]
uses: ./.github/workflows/sub-deploy-integration-tests-gcp.yml
if: ${{ github.event_name == 'schedule' || !fromJSON(needs.get-available-disks.outputs.zebra_tip_disk) || (github.event.inputs.run-full-sync == 'true' && (inputs.network || vars.ZCASH_NETWORK) == 'Mainnet') }}
with:
Expand Down Expand Up @@ -329,7 +240,7 @@ jobs:
# Note: the output from get-available-disks-testnet should match with the caller workflow inputs
test-full-sync-testnet:
name: Zebra tip on testnet
needs: [ build, get-available-disks-testnet ]
needs: [ get-available-disks-testnet ]
uses: ./.github/workflows/sub-deploy-integration-tests-gcp.yml
if: ${{ (github.event_name == 'schedule' && vars.SCHEDULE_TESTNET_FULL_SYNC == 'true') || !fromJSON(needs.get-available-disks-testnet.outputs.zebra_tip_disk) || (github.event.inputs.run-full-sync == 'true' && (inputs.network || vars.ZCASH_NETWORK) == 'Testnet') }}
with:
Expand Down
Loading

0 comments on commit 63340c3

Please sign in to comment.