Skip to content

Commit

Permalink
refactor: test config file in CI and CD with a reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavovalverde committed Oct 17, 2023
1 parent 97e7a14 commit 43ae06e
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 99 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/cd-deploy-nodes-gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,55 @@ jobs:
no_cache: ${{ inputs.no_cache || false }}
rust_log: info

# Test that Zebra works using the default config with the latest Zebra version.
test-configuration-file:
name: Test Zebra default Docker config file
timeout-minutes: 15
runs-on: ubuntu-latest
needs: build
steps:
- name: Test Zebra with default config file
uses: ./.github/workflows/test-zebra-config-files.yml
with:
test_id: 'default-conf-tests'
test_description: 'Test Zebra default Docker config file'
grep_patterns: '-e "net.*=.*Main.*estimated progress to chain tip.*BeforeOverwinter"'
test_variables: '-e NETWORK'
network: 'Mainnet'

# Test reconfiguring the the docker image for tesnet.
test-configuration-file-testnet:
name: Test Zebra testnet Docker config file
timeout-minutes: 15
runs-on: ubuntu-latest
needs: build
steps:
# Make sure Zebra can sync the genesis block on testnet
- name: Test Zebra with Testnet config file
uses: ./.github/workflows/test-zebra-config-files.yml
with:
test_id: 'testnet-conf-tests'
test_description: 'Test Zebra testnet Docker config file'
grep_patterns: '-e "net.*=.*Test.*estimated progress to chain tip.*Genesis" -e "net.*=.*Test.*estimated progress to chain tip.*BeforeOverwinter"'
test_variables: '-e NETWORK -e ZEBRA_CONF_PATH="/etc/zebrad/zebrad.toml"'
network: 'Testnet'

# Test that Zebra works using $ZEBRA_CONF_PATH config
test-zebra-conf-path:
name: Test Zebra custom Docker config file
timeout-minutes: 15
runs-on: ubuntu-latest
needs: build
steps:
- name: Test Zebra with $ZEBRA_CONF_PATH config file
uses: ./.github/workflows/test-zebra-config-files.yml
with:
test_id: 'variable-conf-tests'
test_description: 'Test Zebra custom Docker config file'
grep_patterns: '-e "v1.0.0-rc.2.toml"'
test_variables: '-e NETWORK -e ZEBRA_CONF_PATH="zebrad/tests/common/configs/v1.0.0-rc.2.toml"'
network: ${{ inputs.network || vars.ZCASH_NETWORK }}

# Deploy Managed Instance Groups (MiGs) for Mainnet and Testnet,
# with one node in the configured GCP region.
#
Expand Down
123 changes: 24 additions & 99 deletions .github/workflows/ci-unit-tests-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,122 +214,47 @@ jobs:
runs-on: ubuntu-latest
needs: build
steps:
- uses: r7kamura/[email protected]

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Test Zebra with default config file
uses: ./.github/workflows/test-zebra-config-files.yml
with:
short-length: 7

- name: Run tests using the default config
run: |
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}:sha-${{ env.GITHUB_SHA_SHORT }}
docker run -e NETWORK --detach --name default-conf-tests -t ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}:sha-${{ env.GITHUB_SHA_SHORT }} zebrad start
# Use a subshell to handle the broken pipe error gracefully
(
trap "" PIPE;
docker logs \
--tail all \
--follow \
default-conf-tests | \
tee --output-error=exit /dev/stderr | \
grep --max-count=1 --extended-regexp --color=always \
-e "net.*=.*Main.*estimated progress to chain tip.*BeforeOverwinter"
) || true
LOGS_EXIT_STATUS=$?
docker stop default-conf-tests
EXIT_STATUS=$(docker wait default-conf-tests || echo "Error retrieving exit status");
echo "docker exit status: $EXIT_STATUS";
test_id: 'default-conf-tests'
test_description: 'Test Zebra default Docker config file'
grep_patterns: '-e "net.*=.*Main.*estimated progress to chain tip.*BeforeOverwinter"'
test_variables: '-e NETWORK'
network: 'Mainnet'

# If grep found the pattern, exit with the Docker container exit status
if [ $LOGS_EXIT_STATUS -eq 0 ]; then
exit $EXIT_STATUS;
fi
# Handle other potential errors here
echo "An error occurred while processing the logs.";
exit 1;
env:
NETWORK: Mainnet

# Test reconfiguring the docker image for testnet.
# Test reconfiguring the the docker image for tesnet.
test-configuration-file-testnet:
name: Test Zebra testnet Docker config file
timeout-minutes: 15
runs-on: ubuntu-latest
needs: build
steps:
- uses: r7kamura/[email protected]

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
short-length: 7

# Make sure Zebra can sync the genesis block on testnet
- name: Run tests using a testnet config
run: |
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}:sha-${{ env.GITHUB_SHA_SHORT }}
docker run -e NETWORK -e ZEBRA_CONF_PATH -e ENTRYPOINT_FEATURES='' --detach --name testnet-conf-tests -t ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}:sha-${{ env.GITHUB_SHA_SHORT }} zebrad start
# Use a subshell to handle the broken pipe error gracefully
(
trap "" PIPE;
docker logs \
--tail all \
--follow \
testnet-conf-tests | \
tee --output-error=exit /dev/stderr | \
grep --max-count=1 --extended-regexp --color=always \
-e "net.*=.*Test.*estimated progress to chain tip.*Genesis" \
-e "net.*=.*Test.*estimated progress to chain tip.*BeforeOverwinter";
) || true
LOGS_EXIT_STATUS=$?
docker stop testnet-conf-tests
EXIT_STATUS=$(docker wait testnet-conf-tests || echo "Error retrieving exit status");
echo "docker exit status: $EXIT_STATUS";
# If grep found the pattern, exit with the Docker container exit status
if [ $LOGS_EXIT_STATUS -eq 0 ]; then
exit $EXIT_STATUS;
fi
# Handle other potential errors here
echo "An error occurred while processing the logs.";
exit 1;
env:
ZEBRA_CONF_PATH: '/etc/zebrad/zebrad.toml'
NETWORK: Testnet
- name: Test Zebra with Testnet config file
uses: ./.github/workflows/test-zebra-config-files.yml
with:
test_id: 'testnet-conf-tests'
test_description: 'Test Zebra testnet Docker config file'
grep_patterns: '-e "net.*=.*Test.*estimated progress to chain tip.*Genesis" -e "net.*=.*Test.*estimated progress to chain tip.*BeforeOverwinter"'
test_variables: '-e NETWORK -e ZEBRA_CONF_PATH="/etc/zebrad/zebrad.toml"'
network: 'Testnet'

# Test that Zebra works using the $ZEBRA_CONF_PATH config
# Test that Zebra works using $ZEBRA_CONF_PATH config
test-zebra-conf-path:
name: Test Zebra custom Docker config file
timeout-minutes: 15
runs-on: ubuntu-latest
needs: build
steps:
- uses: r7kamura/[email protected]

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Test Zebra with $ZEBRA_CONF_PATH config file
uses: ./.github/workflows/test-zebra-config-files.yml
with:
short-length: 7

- name: Run tests using the $ZEBRA_CONF_PATH
run: |
set -ex
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}:sha-${{ env.GITHUB_SHA_SHORT }}
docker run -e NETWORK --detach -e ZEBRA_CONF_PATH --name variable-conf-tests -t ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}:sha-${{ env.GITHUB_SHA_SHORT }} zebrad start
EXIT_STATUS=$(docker logs --tail all --follow variable-conf-tests 2>&1 | grep -q --extended-regexp --max-count=1 -e 'v1.0.0-rc.2.toml'; echo $?; )
docker stop variable-conf-tests
docker logs variable-conf-tests
exit "$EXIT_STATUS"
env:
ZEBRA_CONF_PATH: 'zebrad/tests/common/configs/v1.0.0-rc.2.toml'
NETWORK: ${{ inputs.network || vars.ZCASH_NETWORK }}
test_id: 'variable-conf-tests'
test_description: 'Test Zebra custom Docker config file'
grep_patterns: '-e "v1.0.0-rc.2.toml"'
test_variables: '-e NETWORK -e ZEBRA_CONF_PATH="zebrad/tests/common/configs/v1.0.0-rc.2.toml"'
network: ${{ inputs.network || vars.ZCASH_NETWORK }}

failure-issue:
name: Open or update issues for main branch failures
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/sub-test-zebra-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Test Zebra Config Files

on:
workflow_call:
inputs:
# Status and logging
test_id:
required: true
type: string
description: 'Unique identifier for the test'
test_description:
required: true
type: string
description: 'Explains what the test does'
grep_patterns:
required: true
type: string
description: 'Patterns to grep for in the logs'

# Test selection and parameters
test_variables:
required: true
type: string
description: 'Environmental variables used to select and configure the test'
network:
required: false
type: string
default: Mainnet
description: 'Zcash network to test against'

jobs:
test-zebra-config:
name: Test Zebra Docker Config
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: r7kamura/[email protected]

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
short-length: 7

- name: Run ${{ inputs.test_id }} config test
run: |

Check warning on line 45 in .github/workflows/sub-test-zebra-config.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/sub-test-zebra-config.yml#L45

shellcheck reported issue in this script: SC2086:info:23:10: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/sub-test-zebra-config.yml:45:9: shellcheck reported issue in this script: SC2086:info:23:10: Double quote to prevent globbing and word splitting [shellcheck]
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}:sha-${{ env.GITHUB_SHA_SHORT }}
docker run ${{ inputs.test_variables }} --detach --name ${{ inputs.test_id }} -t ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}:sha-${{ env.GITHUB_SHA_SHORT }} zebrad start
# Use a subshell to handle the broken pipe error gracefully
(
trap "" PIPE;
docker logs \
--tail all \
--follow \
${{ inputs.test_id }} | \
tee --output-error=exit /dev/stderr | \
grep --max-count=1 --extended-regexp --color=always \
${{ inputs.grep_patterns }}
) || true
LOGS_EXIT_STATUS=$?
docker stop ${{ inputs.test_id }}
EXIT_STATUS=$(docker wait ${{ inputs.test_id }} || echo "Error retrieving exit status");
echo "docker exit status: $EXIT_STATUS";
# If grep found the pattern, exit with the Docker container exit status
if [ $LOGS_EXIT_STATUS -eq 0 ]; then
exit $EXIT_STATUS;
fi
# Handle other potential errors here
echo "An error occurred while processing the logs.";
exit 1;
env:
NETWORK: '${{ inputs.network }}'

0 comments on commit 43ae06e

Please sign in to comment.