Skip to content

Python CI

Python CI #725

name: Python CI
on:
push:
pull_request:
schedule:
- cron: '0 23 * * 1,2,3,4,5'
jobs:
fetch-data:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12.2'
architecture: 'x64'
- name: Display Python version
run: python --version
- name: Install dependencies
run: python -m pip install -r requirements.txt
- name: Fetch data
uses: nick-fields/retry@v3
with:
timeout_seconds: 120
retry_wait_seconds: 3600
max_attempts: 5
retry_on: error
command: python download_script.py
- uses: actions/upload-artifact@v4
with:
name: artifacts
path: build/
if-no-files-found: error
- name: Set up the SSH key and the known_hosts file
uses: shimataro/[email protected]
if: ${{ github.event_name == 'schedule' }}
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
name: id_rsa
known_hosts: unnecessary
if_key_exists: fail
- name: Configure git
shell: bash
if: ${{ github.event_name == 'schedule' }}
run: |
CI_WORK_DIR=`pwd`
mkdir -p ~/workdir
cd ~/workdir
git config --global user.email "[email protected]"
git config --global user.name "GithubActions CI (via TheSnoozer)"
git clone --depth 1 --branch data [email protected]:TheSnoozer/putcallratio.git
cd putcallratio
TODAY=$(date "+%Y-%m-%d")
CURR_YEAR=$(date "+%Y")
CURR_MONTH=$(date "+%m")
mkdir -p "${CURR_YEAR}"
# Merge total_options
[[ ! -e "${CURR_YEAR}/total_options.tsv" ]] && cp "${CI_WORK_DIR}"/build/total_options.tsv ./"${CURR_YEAR}"
awk 'FNR==1 && NR!=1{next;}{print}' "${CI_WORK_DIR}"/build/total_options.tsv "${CURR_YEAR}/total_options.tsv" | awk '!seen[$0]++' > ./"${CURR_YEAR}"/tmp_total_options.tsv
mv ./"${CURR_YEAR}"/tmp_total_options.tsv ./"${CURR_YEAR}"/total_options.tsv
# Merge index_options
[[ ! -e "${CURR_YEAR}/index_options.tsv" ]] && cp "${CI_WORK_DIR}"/build/index_options.tsv ./"${CURR_YEAR}"
awk 'FNR==1 && NR!=1{next;}{print}' "${CI_WORK_DIR}"/build/index_options.tsv "${CURR_YEAR}/index_options.tsv" | awk '!seen[$0]++' > ./"${CURR_YEAR}"/tmp_index_options.tsv
mv ./"${CURR_YEAR}"/tmp_index_options.tsv ./"${CURR_YEAR}"/index_options.tsv
# Merge equity_options
[[ ! -e "${CURR_YEAR}/equity_options.tsv" ]] && cp "${CI_WORK_DIR}"/build/equity_options.tsv ./"${CURR_YEAR}"
awk 'FNR==1 && NR!=1{next;}{print}' "${CI_WORK_DIR}"/build/equity_options.tsv "${CURR_YEAR}/equity_options.tsv" | awk '!seen[$0]++' > ./"${CURR_YEAR}"/tmp_equity_options.tsv
mv ./"${CURR_YEAR}"/tmp_equity_options.tsv ./"${CURR_YEAR}"/equity_options.tsv
# Raw data
mkdir -p ./"${CURR_YEAR}"/raw/"${CURR_MONTH}"
cp "${CI_WORK_DIR}"/build/${TODAY}_market_statistics.html ./"${CURR_YEAR}"/raw/"${CURR_MONTH}"/
# Add files and commit
[[ -n $(git status --porcelain) ]] || (echo "Nothing to commit!" && exit 0)
git add "${CURR_YEAR}"
git commit -m "Add data for ${TODAY}"
git push origin -o ci.skip -q