Skip to content

do it

do it #61

Workflow file for this run

name: do it
on:
push:
branches: [ "main", "dev" ]
workflow_dispatch:
pull_request:
branches: [ "main" ]
schedule:
- cron: 34 12 * * 06
permissions:
contents: read
env:
PYTHON_VERSION: ${{ vars.PYTHON_VERSION || '3.11' }}
SAFE_TO_RUN: ${{ (github.actor == github.repository_owner) || (github.actor == vars.REPOSITORY_OWNER) }}
concurrency:
group: ${{ github.head_ref || github.ref || github.run_id }}-${{ github.actor || github.repository_owner }}
cancel-in-progress: ${{ (github.event_name == 'push' || github.event_name == 'schedule') && (github.actor == github.repository_owner) || (github.actor == vars.REPOSITORY_OWNER) }}
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Lint with flake8
run: |
flake8 . --count --max-complexity=16 --max-line-length=127 --statistics --show-source
doit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install Cython
pip install numpy~=1.26.4 pandas scikit-learn statsmodels stumpy tqdm pathos psutil
pip install fathon EMD-signal pathvalidate --no-deps
#if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint another time with flake8
run: |
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run tests
if: false
run: |
pytest
- name: Login to Kaggle
if: ${{ env.SAFE_TO_RUN == 'true' }}
uses: osbm/kaggle-login@v2.3
with:
KAGGLE_USERNAME: ${{ secrets.KAGGLE_USERNAME || vars.KAGGLE_USERNAME || github.repository_owner }}
KAGGLE_KEY: ${{ secrets.KAGGLE_KEY }}
- name: Setup the dirs
if: ${{ env.SAFE_TO_RUN == 'true' }}
uses: Wandalen/wretry.action@v3.5.0
with:
command: |
mkdir -p tmp
mkdir -p working
mkdir -p input
kaggle datasets download -d ${{ env.KAGGLE_USERNAME }}/${{ env.KAGGLE_DATASET }} -p input --unzip
env:
KAGGLE_USERNAME: ${{ secrets.KAGGLE_USERNAME || vars.KAGGLE_USERNAME || env.KAGGLE_USERNAME || github.repository_owner }}
KAGGLE_DATASET: ${{ secrets.KAGGLE_DATASET || vars.KAGGLE_DATASET || env.KAGGLE_DATASET || 'yahoo-finance-data' }}
- name: Setup testing related environ
run: |
if [ "${{ github.event_name }}" != "schedule" ] && [ "${{ github.event_name }}" != "workflow_dispatch" ] && [ -z "${{ env.MAX_RUNTIME }}" ]; then
echo "MAX_RUNTIME=5m" >> $GITHUB_ENV
echo "MAX_WORKER=1" >> $GITHUB_ENV
echo "ARTIFACT_RETENTION_DAYS=1" >> $GITHUB_ENV
echo "- set to test mode MAX_RUNTIME=5m" > $GITHUB_STEP_SUMMARY
echo "set to test mode (MAX_RUNTIME=5m)"
fi
- name: Run app
if: ${{ env.SAFE_TO_RUN == 'true' }}
run: cd working && python ../main.py
env:
MAX_WORKER: ${{ env.MAX_WORKER || vars.MAX_WORKER || 0.8 }}
MAX_RUNTIME: ${{ env.MAX_RUNTIME || vars.MAX_RUNTIME }}
TRANGE_DISABLED: ${{ env.TRANGE_DISABLED || vars.TRANGE_DISABLED || 'true' }}
- name: Test file creation
shell: python
run: |
import os
import numpy as np
from pathlib import Path
def test_files(file_pattern, dtype, shape=None):
files = sorted(Path('working').rglob(file_pattern))
assert len(files) > 0, f"No files matching {file_pattern}"
for p in files:
mm = np.memmap(p, dtype=dtype, mode='r')
assert len(mm) > 0, f"{p} is empty"
if shape:
mm = mm.reshape(shape)
assert np.nanstd(mm) > 0, f"{p} has no variance"
try:
test_files('*_price.npy', np.float64)
test_files('*_stats.npy', np.float32, (-1, 16))
except Exception:
with open(os.environ['GITHUB_ENV'], 'w') as file:
print('FILE_CREATED=false', file=file)
raise
else:
with open(os.environ['GITHUB_ENV'], 'w') as file:
print('FILE_CREATED=true', file=file)
- name: create 7z archive
if: ${{ env.FILE_CREATED == 'true' }}
run: |
echo "- 7z random password generation" > $GITHUB_STEP_SUMMARY
openssl rand -base64 32 | tr -d '\r\n' > archive_pass.txt
echo ::add-mask::$(cat archive_pass.txt)
pushd working
7z a -t7z -m0=lzma2 -mx=9 -mhe=on -ms=on -p"$(cat ../archive_pass.txt)" ../tmp/fy_memmaps.7z *
popd
mv archive_pass.txt tmp
echo "ARTIFACT_PATH=tmp" >> $GITHUB_ENV
- name: Upload Archive Artifact
if: ${{ env.SAFE_TO_RUN == 'true' && env.FILE_CREATED == 'true' && always() }}
uses: actions/upload-artifact@v4
with:
name: result
path: ${{ env.ARTIFACT_PATH || 'tmp' }}
if-no-files-found: error
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS || vars.ARTIFACT_RETENTION_DAYS || 60 }}
- name: Cleanup
if: ${{ always() }}
run: |
rm -rf ~/.kaggle || :
rm -rf input || :
rm -rf working || :
rm -rf tmp || :
rm -rf ${{ env.ARTIFACT_PATH || 'tmp' }} || :
exit 0