Skip to content

Merge pull request #1060 from tradingstrategy-ai/py311compat #4115

Merge pull request #1060 from tradingstrategy-ai/py311compat

Merge pull request #1060 from tradingstrategy-ai/py311compat #4115

name: Test suite and Docker image
on:
push:
branches: [ master ]
tags: [ v* ]
pull_request:
branches: [ master ]
jobs:
automated-test-suite:
timeout-minutes: 40
# Use paid faster Github Actions runner
runs-on:
group: Beefy runners
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
# Do not let Poetry to install again if we do not detect a lock file change
- name: Load cached venv
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
# Speed up tests by caching our datasets
# test code downloads
- name: Restore downloaded unit test datasets
id: unit-test-dataset-restore
uses: actions/cache/restore@v3
with:
path: |
/tmp/trading-strategy-tests
key: ${{ runner.os }}-unit-test-dataset
# Needed for Anvil
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
# pick a nightly release from: https://github.com/foundry-rs/foundry/releases
version: 'nightly-de33b6af53005037b463318d2628b5cfcaf39916'
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --no-interaction --all-extras
# Run testa parallel, do not run slow tests before Docker image build.
# Note that we limit concurrency to 2 workers as 4 workers crashed without an error message on Github CI.
# I suspect out of memory situation that is not reported to the user.
# Print 20 slowest tests when done.
# tests/**/test*.py -> workaround issues by scanning tests folder in git submodules and importing them (even if not running)
- name: Run test scripts
run: |
poetry run pytest --tb=native --dist loadscope -n 6 --durations=20 -m "not slow_test_group" --timeout=300
env:
TRADING_STRATEGY_API_KEY: ${{ secrets.TRADING_STRATEGY_API_KEY }}
BNB_CHAIN_JSON_RPC: ${{ secrets.BNB_CHAIN_JSON_RPC }}
# https://stackoverflow.com/a/75274358/315168
PYDEVD_DISABLE_FILE_VALIDATION: 1
JSON_RPC_POLYGON: ${{ secrets.JSON_RPC_POLYGON }}
JSON_RPC_POLYGON_ARCHIVE: ${{ secrets.JSON_RPC_POLYGON_ARCHIVE }}
# Save our current datasets for the next test run
- name: Save unit test datasets
id: unit-test-dataset-save
uses: actions/cache/save@v3
with:
path: |
/tmp/trading-strategy-tests
key: ${{ steps.unit-test-dataset.outputs.cache-primary-key }}
build:
runs-on: ubuntu-latest
# needs: automated-test-suite
# Only build on tag push or branch push with rc-* prefix
if: (github.event_name == 'push' && contains(github.ref, 'refs/tags/v')) || startsWith(github.head_ref, 'rc-')
env:
REGISTRY: ghcr.io
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Read metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}
- name: Log in to Github Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# https://stackoverflow.com/a/58178121/315168
- name: Scrape build info
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
# platforms: ${{ matrix.platform }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# experimental: https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#cache-backend-api
cache-from: type=gha
cache-to: type=gha,mode=max
# https://stackoverflow.com/questions/67051284/how-to-set-a-dockerfile-arg-in-github-actions
# https://stackoverflow.com/a/63619526/315168
build-args: |
GIT_VERSION_TAG=${{ env.RELEASE_VERSION }}
GIT_COMMIT_MESSAGE=${{ github.event.head_commit.message }}
GIT_VERSION_HASH=${{ github.sha }}
# Trigger workflow_dispatch in other repos (binder-env, docs...)
# build-other-repos:
# runs-on: ubuntu-latest
# # needs: automated-test-suite
# # Only trigger on master branch push
# if: github.event_name == 'push' && github.ref == 'refs/heads/master'
# steps:
# - name: Trigger docs build
# uses: actions/github-script@v6
# with:
# github-token: ${{ secrets.PAT }}
# script: |
# await github.rest.actions.createWorkflowDispatch({
# owner: 'tradingstrategy-ai',
# repo: 'docs',
# workflow_id: 'rsync-docs.yml',
# ref: 'master'
# })
# - name: Trigger binder-env build
# uses: actions/github-script@v6
# with:
# github-token: ${{ secrets.PAT }}
# script: |
# await github.rest.actions.createWorkflowDispatch({
# owner: 'tradingstrategy-ai',
# repo: 'binder-env',
# workflow_id: 'binder.yml',
# ref: 'master'
# })