Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: conditionally run unit tests #15347

Merged
merged 9 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions .github/actions/setup-ci-core-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Setup CI Core Tests
description: Shared setup steps for ci-core
inputs:

go-mod-download-directory:
description: |
The directory to run go mod download in. If not provided, it will not run go mod download.
required: false
default: ""

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

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

build-cache-version:
description: |
The version of the build cache to use. Used for scoping build caches.
required: false

restore-build-cache-only:
description: |
Whether to create a build cache
required: false
default: "false"

runs:
using: composite
steps:
- name: Setup NodeJS
uses: ./.github/actions/setup-nodejs
with:
prod: "true"

- name: Setup Go
uses: ./.github/actions/setup-go
with:
build-cache-version: ${{ inputs.build-cache-version }}
restore-build-cache-only: ${{ inputs.restore-build-cache-only }}

- 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-override }}

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

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

- name: Setup Postgres
uses: ./.github/actions/setup-postgres

- name: Touching core/web/assets/index.html
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 (optional)
if: ${{ inputs.go-mod-download-directory != '' }}
shell: bash
working-directory: ${{ inputs.go-mod-download-directory }}
run: go mod download

- name: Build binary
shell: bash
run: go build -o chainlink.test .

- name: Setup DB
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

256 changes: 256 additions & 0 deletions .github/workflows/ci-core-partial.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
name: Core Unit Tests

on:
push:
branches:
- develop
# - "release/*"
# merge_group:
pull_request:
schedule:
- cron: "0 0 * * *"


jobs:
filter:
name: Detect Changes
permissions:
pull-requests: read
outputs:
should-run-all-tests: ${{ steps.match-some.outputs.test-data == 'true' }}
should-collect-coverage: ${{ github.event_name == 'schedule' }}
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/[email protected]
with:
repository: smartcontractkit/chainlink
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: match-some
with:
# "if any changed file matches one or more of the conditions" (https://github.com/dorny/paths-filter/issues/225)
predicate-quantifier: some
# test-data - any changes to any testdata files/paths
filters: |
test-data:
- '**/testdata/**'

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

Check failure on line 41 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"
module-directory: "./"
build-flags: "-tags=integration"
- test-suite: "ccip-deployment"
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/[email protected]

- name: Setup CI Core Environment
uses: ./.github/actions/setup-ci-core-tests
with:
build-cache-version: ${{ matrix.type.test-suite }}
restore-build-cache-only: "true"
db-url: ${{ env.DB_URL }}
go-mod-download-directory: ${{ matrix.type.test-suite == 'ccip-deployment' && matrix.type.module-directory || '' }}

- name: Build Tests
uses: smartcontractkit/.github/apps/go-conditional-tests@37882e110590e636627a26371bdbd56ddfcce821 # [email protected]
timeout-minutes: 10
with:
pipeline-step: "build"
build-concurrency: "32"
collect-coverage: ${{ needs.filter.outputs.should-collect-coverage }}
test-suite: ${{ matrix.type.test-suite }}
module-directory: ${{ matrix.type.module-directory }}
github-token: ${{ secrets.GITHUB_TOKEN }}
build-flags: ${{ matrix.type.build-flags }}

- name: Run Tests
uses: smartcontractkit/.github/apps/go-conditional-tests@37882e110590e636627a26371bdbd56ddfcce821 # [email protected]
timeout-minutes: 15
env:
CL_DATABASE_URL: ${{ env.DB_URL }}
with:
pipeline-step: "run"
run-concurrency: "16"
run-all-tests: ${{ needs.filter.outputs.should-run-all-tests }}
collect-coverage: ${{ needs.filter.outputs.should-collect-coverage }}
test-suite: ${{ matrix.type.test-suite }}
module-directory: ${{ matrix.type.module-directory }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Update Test Index
uses: smartcontractkit/.github/apps/go-conditional-tests@37882e110590e636627a26371bdbd56ddfcce821 # [email protected]
with:
pipeline-step: "update"
collect-coverage: ${{ needs.filter.outputs.should-collect-coverage }}
test-suite: ${{ matrix.type.test-suite }}
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

scan:
name: SonarQube Scan
needs: [ run-unit-tests, filter ]
if: ${{ needs.filter.outputs.should-collect-coverage == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/[email protected]
with:
# fetches all history for all tags and branches to provide more metadata for sonar reports
fetch-depth: 0

- name: Download all workflow run artifacts
uses: actions/[email protected]
with:
path: coverage
pattern: coverage-*
merge-multiple: true

- name: Check and Set SonarQube Report Paths
shell: bash
run: |
ARGS=""
sonarqube_coverage_report_paths=$(find ./coverage -name '*.cover.out' | paste -sd "," -)

# TODO uncomment when linting in enabled
# Check and assign paths for lint reports
# if [ -d "golangci-lint-report" ]; then
# sonarqube_lint_report_paths=$(find golangci-lint-report -name 'golangci-lint-report.xml' | paste -sd "," -)
# else
# sonarqube_lint_report_paths=""
# fi
# if [[ -z "$sonarqube_lint_report_paths" ]]; then
# echo "::warning::No lint report paths found, will not pass to sonarqube"
# else
# echo "Found lint report paths: $sonarqube_lint_report_paths"
# ARGS="$ARGS -Dsonar.go.golangci-lint.reportPaths=$sonarqube_lint_report_paths"
# fi

if [[ -z "$sonarqube_coverage_report_paths" ]]; then
echo "::warning::No coverage report paths found, will not pass to sonarqube"
else
echo "Found coverage report paths: $sonarqube_coverage_report_paths"
ARGS="$ARGS -Dsonar.go.coverage.reportPaths=$sonarqube_coverage_report_paths"
fi

echo "Final SONARQUBE_ARGS: $ARGS"
echo "SONARQUBE_ARGS=$ARGS" >> $GITHUB_ENV

- name: SonarQube Scan
if: ${{ env.SONARQUBE_ARGS != '' }}
uses: sonarsource/sonarqube-scan-action@aecaf43ae57e412bd97d70ef9ce6076e672fe0a9 # v2.3.0
with:
args: ${{ env.SONARQUBE_ARGS }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_SCANNER_OPTS: "-Xms6g -Xmx8g"


run-fuzz-tests:
name: Tests (fuzz)
runs-on: ubuntu22.04-32cores-128GB

Check failure on line 171 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/[email protected]

- 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:
build-cache-version: "fuzz"
restore-build-cache-only: "true"
db-url: ${{ env.DB_URL }}

- name: Increase Timeouts
if: ${{ github.event_name == '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)
runs-on: ubuntu22.04-32cores-128GB

Check failure on line 208 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/[email protected]

- 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:
build-cache-version: "race"
restore-build-cache-only: "true"
db-url: ${{ env.DB_URL }}

- name: Increase Timeouts
if: ${{ github.event_name == '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
Loading
Loading