Skip to content

Commit

Permalink
feat: conditionally run unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erikburt committed Nov 20, 2024
1 parent 226211a commit 676111a
Show file tree
Hide file tree
Showing 2 changed files with 268 additions and 0 deletions.
109 changes: 109 additions & 0 deletions .github/actions/setup-ci-core-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Setup CI Core Tests
description: Shared setup steps for ci-core
inputs:
test-suite:
description: |
The test suite's name
required: true

evm-ref-override:
description: |
Overrides the evm/relayer dependency version
required: false

db-url:
description: |
The expected database URL
required: true

build-only:
description: |
Only setup the necessary dependencies for building the binary
default: "false"

runs:
using: composite
steps:
- name: Log Start
shell: bash
run: |
echo "===================================="
echo "Setting up CI Core Tests Environment"
echo "===================================="
- name: Setup NodeJS
uses: ./.github/actions/setup-nodejs
with:
prod: "true"

- name: Setup Go
uses: ./.github/actions/setup-go
with:
# only restore for now
restore-build-cache-only: "true"
build-cache-version: ${{ inputs.test-suite }}

- name: Replace chainlink-evm deps
if: ${{ inputs.evm-ref-override != ''}}
shell: bash
run: go get github.com/smartcontractkit/chainlink-integrations/evm/relayer@${{ inputs.evm-ref }}

- name: Setup Solana
uses: ./.github/actions/setup-solana

- name: Setup wasmd
uses: ./.github/actions/setup-wasmd

- name: Setup Postgres
if: ${{ inputs.build-only == 'false' }}
uses: ./.github/actions/setup-postgres

- name: Touching core/web/assets/index.html
if: ${{ inputs.build-only == 'false' }}
shell: bash
run: mkdir -p core/web/assets && touch core/web/assets/index.html

- name: Download Go vendor packages
shell: bash
run: go mod download

- name: Go Mod Download (deployment)
if: ${{ matrix.type.test-suite == 'ccip-deployment' }}
shell: bash
working-directory: "./deployment"
run: go mod download

- name: Build binary
if: ${{ inputs.build-only == 'false' }}
shell: bash
run: go build -o chainlink.test .

- name: Setup DB
if: ${{ inputs.build-only == 'false' }}
shell: bash
run: ./chainlink.test local db preparetest
env:
CL_DATABASE_URL: ${{ inputs.db-url }}

- name: Install LOOP Plugins
shell: bash
run: |
pushd $(go list -m -f "{{.Dir}}" github.com/smartcontractkit/chainlink-feeds)
go install ./cmd/chainlink-feeds
popd
pushd $(go list -m -f "{{.Dir}}" github.com/smartcontractkit/chainlink-data-streams)
go install ./mercury/cmd/chainlink-mercury
popd
pushd $(go list -m -f "{{.Dir}}" github.com/smartcontractkit/chainlink-solana)
go install ./pkg/solana/cmd/chainlink-solana
popd
pushd $(go list -m -f "{{.Dir}}" github.com/smartcontractkit/chainlink-starknet/relayer)
go install ./pkg/chainlink/cmd/chainlink-starknet
popd
- name: Log End
shell: bash
run: |
echo "============================================="
echo "Finished Setting up CI Core Tests Environment"
echo "============================================="
159 changes: 159 additions & 0 deletions .github/workflows/ci-core-partial.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: Core Unit Tests

# Run on key branches to make sure integration is good, otherwise run on all PR's
on:
push:
branches:
- develop
- main
- "release/*"
merge_group:
pull_request:

jobs:
run-unit-tests:
name: Tests (${{ matrix.type.test-suite }})
runs-on: ubuntu22.04-32cores-128GB

Check failure on line 16 in .github/workflows/ci-core-partial.yml

View workflow job for this annotation

GitHub Actions / Validate Workflow Changes

1. This Ubuntu runner is 8-16 more expensive than a base Ubuntu runner. Consider using a smaller Ubuntu runner. (runner-ubuntu / error)
permissions:
id-token: write
contents: write
strategy:
fail-fast: false
matrix:
type:
- test-suite: "core"
tag-filter: ""
module-directory: "./"
- test-suite: "integration"
tag-filter: "integration"
module-directory: "./"
- test-suite: "ccip-deployment"
tag-filter: ""
module-directory: "./deployment"
env:
# We explicitly have this env var not be "CL_DATABASE_URL" to avoid having it be used by core related tests
# when they should not be using it, while still allowing us to DRY up the setup
DB_URL: postgresql://postgres:postgres@localhost:5432/chainlink_test?sslmode=disable
steps:
- name: Checkout the repo
uses: actions/checkout@v4.2.1

- name: Change Modtime of Files (cache optimization)
shell: bash
run: |
find . -type f,d -exec touch -r {} -d '1970-01-01T00:00:01' {} \; || true
- name: Setup CI Core Environment
uses: ./.github/actions/setup-ci-core-tests
with:
test-suite: ${{ matrix.type.cmd }}
db-url: ${{ env.DB_URL }}

- name: Run Tests
uses: smartcontractkit/.github/apps/go-test-caching@feat/go-test-binary-comparison
env:
CL_DATABASE_URL: ${{ env.DB_URL }}
with:
test-suite: ${{ matrix.type.test-suite }}
module-directory: ${{ matrix.type.module-directory }}
tag-filter: ${{ matrix.type.tag-filter }}
update-index: "true"
force-update-index: "true"
build-concurrency: "32"
run-concurrency: "32"
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Print postgres logs
if: ${{ always() }}
run: docker compose logs postgres | tee ../../../postgres_logs.txt
working-directory: ./.github/actions/setup-postgres


run-fuzz-tests:
name: Tests (fuzz)
if: ${{ github.ref == 'refs/heads/dont-run' }}
runs-on: ubuntu22.04-32cores-128GB

Check failure on line 75 in .github/workflows/ci-core-partial.yml

View workflow job for this annotation

GitHub Actions / Validate Workflow Changes

1. This Ubuntu runner is 8-16 more expensive than a base Ubuntu runner. Consider using a smaller Ubuntu runner. (runner-ubuntu / error)
env:
DB_URL: postgresql://postgres:postgres@localhost:5432/chainlink_test?sslmode=disable
steps:
- name: Checkout the repo
uses: actions/checkout@v4.2.1

- name: Change Modtime of Files (cache optimization)
shell: bash
run: |
find . -type f,d -exec touch -r {} -d '1970-01-01T00:00:01' {} \; || true
- name: Setup CI Core Environment
uses: ./.github/actions/setup-ci-core-tests
with:
test-suite: "fuzz"
db-url: ${{ env.DB_URL }}

- name: Increase Timeouts
if: ${{ github.event.schedule != ''}}
run: |
echo "FUZZ_TIMEOUT_MINUTES=10">> $GITHUB_ENV
- name: Run Fuzz Tests
env:
OUTPUT_FILE: ./output.txt
CL_DATABASE_URL: ${{ env.DB_URL }}
run: ./tools/bin/go_core_fuzz ./...

- name: Print postgres logs
if: ${{ always() }}
run: docker compose logs postgres | tee ../../../postgres_logs.txt
working-directory: ./.github/actions/setup-postgres

run-race-tests:
name: Tests (race)
if: ${{ github.ref == 'refs/heads/dont-run' }}
runs-on: ubuntu22.04-32cores-128GB

Check failure on line 112 in .github/workflows/ci-core-partial.yml

View workflow job for this annotation

GitHub Actions / Validate Workflow Changes

1. This Ubuntu runner is 8-16 more expensive than a base Ubuntu runner. Consider using a smaller Ubuntu runner. (runner-ubuntu / error)
env:
DB_URL: postgresql://postgres:postgres@localhost:5432/chainlink_test?sslmode=disable
steps:
- name: Checkout the repo
uses: actions/checkout@v4.2.1

- name: Change Modtime of Files (cache optimization)
shell: bash
run: |
find . -type f,d -exec touch -r {} -d '1970-01-01T00:00:01' {} \; || true
- name: Setup CI Core Environment
uses: ./.github/actions/setup-ci-core-tests
with:
test-suite: "race"
db-url: ${{ env.DB_URL }}

- name: Increase Timeouts
if: ${{ github.event.schedule != ''}}
run: |
echo "TIMEOUT=10m" >> $GITHUB_ENV
echo "COUNT=50" >> $GITHUB_ENV
- name: Run Race Tests
env:
OUTPUT_FILE: ./output.txt
CL_DATABASE_URL: ${{ env.DB_URL }}
run: ./tools/bin/go_core_race_tests ./...

- name: Print Races
id: print-races
if: ${{ failure() }}
run: |
find race.* | xargs cat > race.txt
if [[ -s race.txt ]]; then
cat race.txt
echo "post_to_slack=true" >> $GITHUB_OUTPUT
else
echo "post_to_slack=false" >> $GITHUB_OUTPUT
fi
echo "github.event_name: ${{ github.event_name }}"
echo "github.ref: ${{ github.ref }}"
- name: Print postgres logs
if: ${{ always() }}
run: docker compose logs postgres | tee ../../../postgres_logs.txt
working-directory: ./.github/actions/setup-postgres

0 comments on commit 676111a

Please sign in to comment.