Skip to content

Commit

Permalink
fix: convert the tests to an action
Browse files Browse the repository at this point in the history
  • Loading branch information
jpantos committed Aug 16, 2024
1 parent 0b0077a commit e5f50c5
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 78 deletions.
105 changes: 105 additions & 0 deletions .github/actions/run-tests/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Run E2E Tests
description: Run end-to-end tests for Pantos
inputs:
ethereum-contracts-version:
description: 'The version of the ethereum-contracts repository to use'
required: false
default: ''
servicenode-version:
description: 'The version of the servicenode images to use. Use local if you want to use locally built images'
required: false
default: ''
validatornode-version:
description: 'The version of the validatornode repository to use'
required: false
default: ''

env:
PANTOS_ETHEREUM_CONTRACTS: ${{ github.workspace }}/ethereum-contracts
PANTOS_SERVICE_NODE: ${{ github.workspace }}/servicenode
PANTOS_VALIDATOR_NODE: ${{ github.workspace }}/validatornode
PANTOS_E2E_TESTS: ${{ github.workspace }}/e2e-tests

steps:
- uses: actions/checkout@v4
with:
path: ${{ env.PANTOS_E2E_TESTS }}

- uses: pantos-io/ci-workflows/.github/actions/install-python-deps@v1
with:
working-directory: ${{ env.PANTOS_E2E_TESTS }}

- name: Check for folder existence
id: check-folder
run: |
echo "PANTOS_ETHEREUM_CONTRACTS_EXISTS=$(test -d ${{ env.PANTOS_ETHEREUM_CONTRACTS }} && echo true || echo false)" >> $GITHUB_OUTPUT
echo "PANTOS_SERVICE_NODE_EXISTS=$(test -d ${{ env.PANTOS_SERVICE_NODE }} && echo true || echo false)" >> $GITHUB_OUTPUT
echo "PANTOS_VALIDATOR_NODE_EXISTS=$(test -d ${{ env.PANTOS_VALIDATOR_NODE }} && echo true || echo false)" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
if: steps.check-folder.outputs.PANTOS_ETHEREUM_CONTRACTS_EXISTS == 'false'
with:
repository: pantos-io/ethereum-contracts
path: ${{ env.PANTOS_ETHEREUM_CONTRACTS }}
sparse-checkout: |
docker-compose.yml
Makefile
- uses: actions/checkout@v4
if: steps.check-folder.outputs.PANTOS_SERVICE_NODE_EXISTS == 'false'
with:
repository: pantos-io/servicenode
path: ${{ env.PANTOS_SERVICE_NODE }}
sparse-checkout: |
docker-compose.yml
docker-compose.override.yml
Makefile
- uses: actions/checkout@v4
if: steps.check-folder.outputs.PANTOS_VALIDATOR_NODE_EXISTS == 'false'
with:
repository: pantos-io/validatornode
path: ${{ env.PANTOS_VALIDATOR_NODE }}
sparse-checkout: |
docker-compose.yml
docker-compose.override.yml
Makefile
- name: Create local signer_key
run: |
ssh-keygen -t ed25519 -f signer_key.pem -N ''
chmod 777 signer_key.pem
working-directory: ${{ env.PANTOS_SERVICE_NODE }}

- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
id: buildx

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-v1.0-e2e-test-${{ github.ref_name }}
restore-keys: |
${{ runner.os }}-buildx-v1.0-test-
- name: Check docker config and disable live reload
run: |
cat /etc/docker/daemon.json
echo '{ "live-restore": false }' | sudo tee /etc/docker/daemon.json
sudo systemctl reload docker
make check-swarm-init
working-directory: ${{ env.PANTOS_E2E_TESTS }}

- name: Run Tests
run: |
make test
working-directory: ${{ env.PANTOS_E2E_TESTS }}
env:
PANTOS_ETHEREUM_CONTRACTS_VERSION: ${{ inputs.ethereum-contracts-version }}
PANTOS_SERVICE_NODE_VERSION: ${{ inputs.servicenode-version }}
PANTOS_VALIDATOR_NODE_VERSION: ${{ inputs.validatornode-version }}

74 changes: 3 additions & 71 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,80 +4,12 @@ on:
branches:
- main
pull_request:
workflow_call:

jobs:
test:
name: Run tests
runs-on: ubuntu-latest
env:
PANTOS_ETHEREUM_CONTRACTS: ${{ github.workspace }}/ethereum-contracts
PANTOS_SERVICE_NODE: ${{ github.workspace }}/servicenode
PANTOS_VALIDATOR_NODE: ${{ github.workspace }}/validatornode
steps:
- name: Harden Runner
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
- uses: actions/checkout@v4
- uses: pantos-io/ci-workflows/.github/actions/install-python-deps@v1
- uses: actions/checkout@v4
with:
repository: pantos-io/ethereum-contracts
path: ${{ env.PANTOS_ETHEREUM_CONTRACTS }}
sparse-checkout: |
docker-compose.yml
Makefile
- uses: actions/checkout@v4
with:
repository: pantos-io/servicenode
path: ${{ env.PANTOS_SERVICE_NODE }}
sparse-checkout: |
docker-compose.yml
docker-compose.override.yml
Makefile
- uses: actions/checkout@v4
with:
repository: pantos-io/validatornode
path: ${{ env.PANTOS_VALIDATOR_NODE }}
sparse-checkout: |
docker-compose.yml
docker-compose.override.yml
Makefile
- name: Create local signer_key
run: |
ssh-keygen -t ed25519 -f signer_key.pem -N ''
chmod 777 signer_key.pem
working-directory: servicenode
- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
id: buildx
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-v1.0-e2e-test-${{ github.ref_name }}
restore-keys: |
${{ runner.os }}-buildx-v1.0-test-
- name: Check docker config and disable live reload
run: |
cat /etc/docker/daemon.json
echo '{ "live-restore": false }' | sudo tee /etc/docker/daemon.json
sudo systemctl reload docker
make check-swarm-init
- name: Run Tests
run: |
make test
- name: Dump service node logs
if: always()
run: |
make docker-logs || true
working-directory: ${{ env.PANTOS_SERVICE_NODE }}
- name: Dump validator node logs
if: always()
run: |
make docker-logs || true
working-directory: ${{ env.PANTOS_VALIDATOR_NODE }}
- name: Dump ethereum contract logs
if: always()
run: |
make docker-logs || true
working-directory: ${{ env.PANTOS_ETHEREUM_CONTRACTS }}
uses: ./.github/actions/run-tests
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
"python.testing.pytestEnabled": true,
"python.testing.cwd": "${workspaceFolder}/tests",
"python.testing.autoTestDiscoverOnSaveEnabled": true,
"prettier.requireConfig": true,
"prettier.yamlSpacing": true,
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
20 changes: 13 additions & 7 deletions tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,22 @@ def configure_nodes(config, stack_id):

# Teardown
if not config:
# Remove Validator Node
validator_node_command = 'make docker-remove'
service_node_command = 'make docker-remove'
ethereum_contracts_command = 'make docker-remove'
# Dump all the logs
env_vars = {'STACK_IDENTIFIER': stack_id}
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [
executor.submit(run_command, validator_node_command, pantos_validator_node_dir, env_vars),
executor.submit(run_command, service_node_command, pantos_service_node_dir, env_vars),
executor.submit(run_command, ethereum_contracts_command, pantos_ethereum_contracts_dir, env_vars)
executor.submit(run_command, 'make docker-logs', pantos_validator_node_dir, env_vars),
executor.submit(run_command, 'make docker-logs', pantos_service_node_dir, env_vars),
executor.submit(run_command, 'make docker-logs', pantos_ethereum_contracts_dir, env_vars)
]
concurrent.futures.wait(futures)

# Remove the containers
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [
executor.submit(run_command, 'make docker-remove', pantos_validator_node_dir, env_vars),
executor.submit(run_command, 'make docker-remove', pantos_service_node_dir, env_vars),
executor.submit(run_command, 'make docker-remove', pantos_ethereum_contracts_dir, env_vars)
]
concurrent.futures.wait(futures)

Expand Down

0 comments on commit e5f50c5

Please sign in to comment.