Files
chia-blockchain/.github/workflows/test-single.yml
T
Kyle AltendorfandGitHub 458697b519 reusable workflow for a single test workflow (#11722)
* reusable workflow for a single test workflow with coverage collection

* avoid needing typing-extensions to build workflow jobs

* remove incorrect coverage job

* correct enabling of pytest-monitor

* $Env:GITHUB_*

* tweak concurrency

* add explanation for use of the reusable workflow

* name: Generate matrix configuration

* correct timelord installation choice logic

* avoid * to fix coverage combining on windows

* name: Configure matrix

* bring back the conditional run

* less matrix.os.matrix

* hmm

* again

* exclude instead

* fixup JOB_FILE_NAME

* leave the final coverage step for later

* drop configuration.runs in favor of matrix excludes

* fixup os checks

* actions/cache@v3
2022-06-03 16:56:52 -05:00

228 lines
7.9 KiB
YAML

name: test
# This reusable workflow structure was chosen for the sole purpose of working around
# the 256 job per matrix limit. The initial total test job count was 290. This
# approach shifts the 256 limit to be per OS rather than overall. A simpler single
# regular workflow with matrixing against the OS would be preferred.
on:
workflow_call:
inputs:
emoji:
required: true
type: string
matrix:
required: true
type: string
name:
required: true
type: string
file_name:
required: true
type: string
concurrency_name:
required: true
type: string
configuration:
required: true
type: string
runs-on:
required: true
type: string
concurrency:
# SHA is added to the end if on `main` to let all main workflows run
group: ${{ github.ref }}-${{ github.workflow }}-${{ inputs.concurrency_name }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/heads/long_lived/')) && github.sha || '' }}
cancel-in-progress: true
jobs:
test:
name: ${{ matrix.os.emoji }} ${{ matrix.configuration.name }} - ${{ matrix.python.name }}
runs-on: ${{ matrix.os.runs-on }}
timeout-minutes: ${{ matrix.configuration.job_timeout }}
strategy:
fail-fast: false
matrix:
configuration: ${{ fromJson(inputs.configuration) }}
os:
- emoji: ${{ inputs.emoji }}
matrix: ${{ inputs.matrix }}
name: ${{ inputs.name }}
file_name: ${{ inputs.file_name }}
runs-on: ${{ inputs.runs-on }}
python:
- name: '3.7'
file_name: '3.7'
action: '3.7'
apt: '3.7'
install_sh: '3.7'
matrix: '3.7'
- name: '3.8'
file_name: '3.8'
action: '3.8'
apt: '3.8'
install_sh: '3.8'
matrix: '3.8'
- name: '3.9'
file_name: '3.9'
action: '3.9'
apt: '3.9'
install_sh: '3.9'
matrix: '3.9'
- name: '3.10'
file_name: '3.10'
action: '3.10'
apt: '3.10'
install_sh: '3.10'
matrix: '3.10'
exclude:
- os:
matrix: macos
python:
matrix: '3.7'
- os:
matrix: macos
python:
matrix: '3.8'
- os:
matrix: windows
configuration:
install_timelord: true
- os:
matrix: windows
configuration:
name: core.full_node
env:
CHIA_ROOT: ${{ github.workspace }}/.chia/mainnet
JOB_FILE_NAME: tests_${{ matrix.os.file_name }}_python-${{ matrix.python.file_name }}_${{ matrix.configuration.name }}
steps:
- name: Configure git
run: |
git config --global core.autocrlf false
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python environment
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python.action }}
- name: Create keychain for CI use (macOS)
if: matrix.os.matrix == 'macos'
run: |
security create-keychain -p foo chiachain
security default-keychain -s chiachain
security unlock-keychain -p foo chiachain
security set-keychain-settings -t 7200 -u chiachain
- name: Cache npm (Ubuntu)
if: matrix.os.matrix == 'ubuntu'
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: Cache pip
uses: actions/cache@v3
with:
# Note that new runners may break this https://github.com/actions/cache/issues/292
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache test blocks and plots
if: matrix.configuration.checkout_blocks_and_plots
uses: actions/cache@v3
id: test-blocks-plots
with:
path: |
${{ github.workspace }}/.chia/blocks
${{ github.workspace }}/.chia/test-plots
key: 0.29.0
- name: Checkout test blocks and plots (macOS, Ubuntu)
if: steps.test-blocks-plots.outputs.cache-hit != 'true' && (matrix.os.matrix == 'ubuntu' || matrix.os.matrix == 'macos')
run: |
wget -qO- https://github.com/Chia-Network/test-cache/archive/refs/tags/0.29.0.tar.gz | tar xzf -
mkdir ${{ github.workspace }}/.chia
mv ${{ github.workspace }}/test-cache-0.29.0/* ${{ github.workspace }}/.chia
- name: Checkout test blocks and plots (Windows)
if: steps.test-blocks-plots.outputs.cache-hit != 'true' && matrix.os.matrix == 'windows'
run: |
Invoke-WebRequest -OutFile blocks_and_plots.zip https://github.com/Chia-Network/test-cache/archive/refs/tags/0.29.0.zip; Expand-Archive blocks_and_plots.zip -DestinationPath .
mkdir ${{ github.workspace }}/.chia
mv ${{ github.workspace }}/test-cache-0.29.0/* ${{ github.workspace }}/.chia
- name: Install boost (macOS)
if: matrix.os.matrix == 'macos'
run: |
brew install boost
- name: Run install script (macOS, Ubuntu)
if: matrix.os.matrix == 'macos' || matrix.os.matrix == 'ubuntu'
env:
INSTALL_PYTHON_VERSION: ${{ matrix.python.install_sh }}
run: |
sh install.sh -d
echo "$(cd venv/bin/; pwd)" >> $GITHUB_PATH
echo "VIRTUAL_ENV=$(cd venv/; pwd)" >> $GITHUB_ENV
- name: Run install script (Windows)
if: matrix.os.matrix == 'windows'
env:
INSTALL_PYTHON_VERSION: ${{ matrix.python.install_sh }}
run: |
./Install.ps1 -d
(Resolve-Path venv/Scripts/).Path >> $Env:GITHUB_PATH
$env_path = (Resolve-Path venv/).Path
Write-Output "VIRTUAL_ENV=$env_path" >> $Env:GITHUB_ENV
- name: Install timelord
if: matrix.configuration.install_timelord
run: |
sh install-timelord.sh -n
./vdf_bench square_asm 400000
- name: Test blockchain code with pytest
env:
ENABLE_PYTEST_MONITOR: ${{ matrix.os.matrix == 'ubuntu' && matrix.configuration.enable_pytest_monitor || '' }}
run: |
coverage run --rcfile=.coveragerc --module pytest --durations=10 ${{ matrix.configuration.pytest_parallel_args[matrix.os.matrix] }} -m "not benchmark" ${{ env.ENABLE_PYTEST_MONITOR }} ${{ matrix.configuration.test_files }}
- name: Process coverage data
run: |
coverage combine --rcfile=.coveragerc
coverage xml --rcfile=.coveragerc -o coverage.xml
mkdir coverage_reports
cp .coverage "coverage_reports/.coverage.${{ env.JOB_FILE_NAME }}"
cp coverage.xml "coverage_reports/coverage.${{ env.JOB_FILE_NAME }}.xml"
coverage report --rcfile=.coveragerc --show-missing
- name: Publish coverage
uses: actions/upload-artifact@v3
with:
name: coverage
path: coverage_reports/*
if-no-files-found: error
- name: Check resource usage
if: matrix.os.matrix == 'ubuntu' && matrix.configuration.check_resource_usage
run: |
sqlite3 -readonly -separator " " .pymon "select item,cpu_usage,total_time,mem_usage from TEST_METRICS order by mem_usage desc;" >metrics.out
./tests/check_pytest_monitor_output.py <metrics.out