Skip to content

Commit

Permalink
[TT-737] Build and Run Compiled Tests (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalverra authored Nov 29, 2023
1 parent 8a907ce commit 912bed7
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 3 deletions.
85 changes: 85 additions & 0 deletions chainlink-testing-framework/build-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: chainlink-testing-framework-test-builder
description: Builds a test binary for chainlink integration tests
inputs:
binary_name:
required: false
description: Name of the artifact to upload
default: test-logs
test_download_vendor_packages_command:
required: false
description: The command to download the go modules
default: make download
test_type:
required: false
description: The name of the test type you plan to run, e.g. smoke
default: smoke
token:
required: false
description: The GITHUB_TOKEN for the workflow
default: ${{ github.token }}
go_version:
required: false
description: Go version to install
go_mod_path:
required: false
description: The go.mod file path
cache_restore_only:
required: false
description: Only restore the cache, set to true if you want to restore and save on cache hit miss
default: "false"
cache_key_id:
required: false
description: Cache go vendors unique id
default: go
dep_chainlink_integration_tests:
required: false
description: chainlink/integration-tests commit or branch
CGO_ENABLED:
required: false
description: Whether to have cgo enabled, defaults to disabled
default: "0"

runs:
using: composite
steps:
# Setup Tools and libraries
- name: Setup Go
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-go@v2.3.0
with:
test_download_vendor_packages_command: ${{ inputs.test_download_vendor_packages_command }}
go_version: ${{ inputs.go_version }}
go_mod_path: ${{ inputs.go_mod_path }}
cache_restore_only: ${{ inputs.cache_restore_only }}
cache_key_id: ${{ inputs.cache_key_id }}

- name: Replace chainlink/integration-tests deps
if: ${{ inputs.dep_chainlink_integration_tests }}
shell: bash
run: |
# find test go root by using the go_mod_path and change to that directory
TEST_LIB_PATH="${{ inputs.go_mod_path }}"
if [ "${#TEST_LIB_PATH}" -gt "6" ]; then
TEST_LIB_PATH=${TEST_LIB_PATH%go.mod}
cd "${TEST_LIB_PATH}"
fi
go version
# update the integration-tests lib to the branch or commit
go get github.com/smartcontractkit/chainlink/integration-tests@${{ inputs.dep_chainlink_integration_tests }}
go mod tidy
- name: Build Tests
shell: bash
env:
CGO_ENABLED: ${{ inputs.CGO_ENABLED }}
run: |
PATH=$PATH:$(go env GOPATH)/bin
export PATH
cd ./integration-tests && go test -c -ldflags="-s -w" -o ./tests ./${{ inputs.test_type }}
echo "Built binary at ./integration-tests/tests"
- name: Publish Binary
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.binary_name }}
path: ./integration-tests/tests
139 changes: 139 additions & 0 deletions chainlink-testing-framework/run-tests-binary/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: chainlink-testing-framework-binary-test-runner
description: Used to run Chainlink tests only after the binary has been built with the build-tests action
inputs:
artifacts_location:
required: false
description: Location of where error logs are written
default: ./logs
artifacts_name:
required: false
description: Name of the artifact to upload
default: test-logs
test_command_to_run:
required: true
description: The command to run the tests by calling your binary (note that -test.json is not supported)
# https://github.com/golang/go/issues/22996
cl_repo:
required: false
description: The Chainlink ecr repository to use
default: public.ecr.aws/z0b1w9r9/chainlink
cl_image_tag:
required: false
description: The chainlink image to use
default: develop
build_gauntlet_command:
required: false
description: How to build gauntlet if necessary
default: "false"
download_contract_artifacts_path:
required: false
description: Path where the contract artifacts need to be placed
default: "none"
token:
required: false
description: The GITHUB_TOKEN for the workflow
default: ${{ github.token }}
triggered_by:
required: true
description: The triggered-by label for the k8s namespace, required for cleanup
default: ci
cache_restore_only:
required: false
description: Only restore the cache, set to true if you want to restore and save on cache hit miss
default: "false"
cache_key_id:
required: false
description: Cache go vendors unique id
default: go
aws_registries:
required: false
description: AWS registries to log into for the test if needed
aws_role_duration_seconds:
required: false
default: "3600"
description: The duration to be logged into the aws role for
dockerhub_username:
description: Username for Docker Hub to avoid rate limits when pulling public images
required: false
dockerhub_password:
description: Password for Docker Hub to avoid rate limits when pulling public images
required: false
QA_AWS_REGION:
required: true
description: The AWS region to use
QA_AWS_ROLE_TO_ASSUME:
required: true
description: The AWS role to assume
QA_KUBECONFIG:
required: false
description: The kubernetes configuration to use
should_cleanup:
required: false
description: Whether to run the cleanup at the end, soak tests and such would not want to automatically cleanup
default: "false"
binary_name:
required: true
description: Name of the binary artifact to run
default: tests

runs:
using: composite
steps:
- name: Setup Environment
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-run-tests-environment@v2.3.0
with:
go_necessary: "false"
cache_restore_only: ${{ inputs.cache_restore_only }}
cache_key_id: ${{ inputs.cache_key_id }}
aws_registries: ${{ inputs.aws_registries }}
aws_role_duration_seconds: ${{ inputs.aws_role_duration_seconds }}
dockerhub_username: ${{ inputs.dockerhub_username }}
dockerhub_password: ${{ inputs.dockerhub_password }}
QA_AWS_REGION: ${{ inputs.QA_AWS_REGION }}
QA_AWS_ROLE_TO_ASSUME: ${{ inputs.QA_AWS_ROLE_TO_ASSUME }}
QA_KUBECONFIG: ${{ inputs.QA_KUBECONFIG }}

# Download any external artifacts
- name: Download Artifacts
if: inputs.download_contract_artifacts_path != 'none'
uses: actions/download-artifact@v3
with:
name: artifacts
path: ${{ inputs.download_contract_artifacts_path }}

# Generate any excutables needed to run tests
- name: Generate gauntlet executable
if: inputs.build_gauntlet_command != 'false'
shell: bash
run: ${{ inputs.build_gauntlet_command }}

# Run the tests
- name: Run Tests
shell: bash
env:
CHAINLINK_IMAGE: ${{ inputs.cl_repo }}
CHAINLINK_VERSION: ${{ inputs.cl_image_tag }}
CHAINLINK_ENV_USER: ${{ github.actor }}
CGO_ENABLED: ${{ inputs.CGO_ENABLED }}
run: |
export TEST_TRIGGERED_BY=${{ inputs.triggered_by }}-${{ github.event.pull_request.number || github.run_id }}
# Handle bots as users
export CHAINLINK_ENV_USER=${CHAINLINK_ENV_USER//"[bot]"/-bot}
chmod +x ./${{ inputs.binary_name }}
${{ inputs.test_command_to_run }}
- name: Publish Artifacts
if: failure()
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.artifacts_name }}
path: ${{ inputs.artifacts_location }}

- name: cleanup
if: always()
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/cleanup@v2.3.0
with:
triggered_by: ${{ inputs.triggered_by }}
should_cleanup: ${{ inputs.should_cleanup }}
4 changes: 2 additions & 2 deletions chainlink-testing-framework/run-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ runs:
# Setup Tools and libraries
- name: Setup environment
if: inputs.run_setup == 'true'
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-run-tests-environment@v2.2.15
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-run-tests-environment@v2.3.0
with:
test_download_vendor_packages_command: ${{ inputs.test_download_vendor_packages_command }}
go_version: ${{ inputs.go_version }}
Expand Down Expand Up @@ -187,7 +187,7 @@ runs:

- name: cleanup
if: always()
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/cleanup@v2.2.15
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/cleanup@v2.3.0
with:
triggered_by: ${{ inputs.triggered_by }}
should_cleanup: ${{ inputs.should_cleanup }}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ inputs:
required: false
description: The go.mod file path
default: "go.mod"
go_necessary:
required: false
description: Whether to install go, should be true unless you already have a test binary
default: "true"
cache_restore_only:
required: false
description: Only restore the cache, set to true if you want to restore and save on cache hit miss
Expand Down Expand Up @@ -48,7 +52,8 @@ runs:
steps:
# Go setup and caching
- name: Setup Go
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-go@v2.2.15
if: inputs.go_necessary == 'true'
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-go@v2.3.0
with:
test_download_vendor_packages_command: ${{ inputs.test_download_vendor_packages_command }}
go_version: ${{ inputs.go_version }}
Expand Down

0 comments on commit 912bed7

Please sign in to comment.