-
Notifications
You must be signed in to change notification settings - Fork 28
161 lines (148 loc) · 5.81 KB
/
test-and-build-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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'
# })