Skip to content

NFL Spread Predictor Pipeline #42

NFL Spread Predictor Pipeline

NFL Spread Predictor Pipeline #42

name: NFL Spread Predictor Pipeline
on:
# schedule:
# - cron: '0 0 * * 2'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.7.1
- name: Install dependencies with Poetry
run: poetry install
# TODO: exit early but without error instead of exit1?
# So job is succesful but doesnt go past this step
- name: Check for matchups
id: check-matchups
# latest_matchups_file is the most recent matchup file by filename timestamp
# errors if matchup file is empty
run: |
poetry run python ./nfl_analytics/main.py --download-upcoming-matchups
latest_matchups_file=$(ls -1t nfl_analytics/assets/matchups-*.json | head -n 1)
if [[ -f "$latest_matchups_file" ]]; then
echo "Latest matchups file: $latest_matchups_file"
matchups_count=$(jq length "$latest_matchups_file")
if [[ $matchups_count -eq 0 ]]; then
echo "Error: Latest matchups file is empty."
exit 1
fi
else
echo "Error: Latest matchups file not found."
exit 1
fi
echo "LATEST_MATCHUP_FILE=$latest_matchups_file" >> "$GITHUB_OUTPUT"
- name: Download data
run: poetry run python ./nfl_analytics/main.py --download
# Necessary for train step
# https://github.com/actions/runner-images/discussions/7188#discussioncomment-6750749
# https://stackoverflow.com/questions/71590851/r8-is-causing-gradle-daemon-to-vanish-on-github-hosted-action-runner/76921482#76921482
- name: Increase swapfile
run: |
df -h
sudo swapoff -a
sudo fallocate -l 12G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
# Seperated from Download data to make debugging easier
- name: Train Model
run: poetry run python ./nfl_analytics/main.py --train
- name: Create release
id: create_release
uses: softprops/action-gh-release@v1
with:
files: ./nfl_analytics/assets/*
tag_name: spread-predictor
draft: true
# Changes to body here dont seem to update existing release
body: |
This release includes the trained model, scaler, and compressed CSV file needed for predictions:
The machine learning model saved using joblib.
- **trained_model-[timstamp].joblib:** The scaler pickled with joblib for scaling matchup inputs.
- **trained_scaler-[timstamp].joblib:** The scaler pickled with joblib for scaling matchup inputs.
- **running_average-[timstamp].csv.gz:** Running averages used to form matchup inputs
To make predictions, use these with the main.py --predict command on asset sets with matching timestamps.
# TODO: predict-upcoming step
# TODO: re-use latest_matchups_file predict-upcoming step
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
- name: Predict upcoming matchups
env:
LATEST_MATCHUP_FILE: ${{ steps.check-matchups.outputs.LATEST_MATCHUP_FILE }}
run: echo "The latest matchup file is $LATEST_MATCHUP_FILE"