Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 66 additions & 27 deletions .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Build and deploy a Next.js site to GitHub Pages
# Build and deploy a Next.js site to GitHub Pages with Python artifact fallback
name: Deploy Next.js site to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

Expand All @@ -22,10 +21,11 @@ concurrency:
cancel-in-progress: false

jobs:
# Data fetch
data_fetch:
name: Run Python Script
runs-on: ubuntu-latest
outputs:
python_artifact_path: ./python-output
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -40,19 +40,66 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run Python script
- name: Run Python script (with fallback)
id: run-python
run: |
set -e
set +e
python run_scripts.py
# python scripts/ngs_passing.py
# python scripts/ngs_receiving.py
# python scripts/ngs_rushing.py
# python scripts/qb_season.py
# python scripts/qb_weekly.py
# python scripts/team_data.py

# Upload the file the script produced
- name: Upload Python output
status=$?
echo "script_status=$status" >> $GITHUB_OUTPUT
if [ $status -ne 0 ]; then
echo "Python script failed, will use last successful artifact"
fi
exit 0

- name: Download previous successful Python artifact (if needed)
if: steps.run-python.outputs.script_status != '0'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const artifactName = 'python-output';
const owner = context.repo.owner;
const repo = context.repo.repo;
const workflow_id = context.workflow;

// Get last successful run
const runs = await github.actions.listWorkflowRuns({
owner,
repo,
workflow_id,
status: 'success',
per_page: 10
});

if (!runs.data.workflow_runs.length) {
core.setFailed('No previous successful runs found');
}

const lastRunId = runs.data.workflow_runs[0].id;

// Find artifact from that run
const artifacts = await github.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: lastRunId
});

const artifact = artifacts.data.artifacts.find(a => a.name === artifactName);

if (!artifact) {
core.setFailed('No previous artifact found');
}

const artifactUrl = artifact.archive_download_url;
core.info(`Artifact URL: ${artifactUrl}`);

// Download and unzip artifact
const exec = require('@actions/exec');
await exec.exec(`curl -L -o ${artifactName}.zip -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "${artifactUrl}"`);
await exec.exec(`unzip -o ${artifactName}.zip -d ./python-output`);

- name: Upload Python output (always)
uses: actions/upload-artifact@v4
with:
name: python-output
Expand All @@ -65,14 +112,12 @@ jobs:
scripts/generated-files/ngs-data-receiving.ts
scripts/generated-files/ngs-data-rushing.ts

# Build job
build:
needs: data_fetch
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

# Download Python artifact before building
- name: Download Python artifact
uses: actions/download-artifact@v4
Expand All @@ -81,8 +126,7 @@ jobs:
path: ./python-output

- name: Move Python output into project
run: |
cp -r ./python-output/* scripts/generated-files/
run: cp -r ./python-output/* scripts/generated-files/

- name: Detect package manager
id: detect-package-manager
Expand Down Expand Up @@ -115,20 +159,16 @@ jobs:
- name: Restore cache
uses: actions/cache@v4
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
path: .next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
restore-keys: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-

- name: Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}

- name: Verify generated data files
run: |
ls -l scripts
run: ls -l scripts

- name: Build with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next build
Expand All @@ -138,7 +178,6 @@ jobs:
with:
path: ./out

# Deployment job
deploy:
environment:
name: github-pages
Expand Down
2 changes: 1 addition & 1 deletion components/qb-touchdowns/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const QBTouchdowns = () => {
<div className="w-20 h-20 block relative bg-white">
<div className="relative min-w-10 w-full h-full">
<Image
src={`/images/players/qbs/no-bg/${qb.player_name.replace(
src={`./images/players/qbs/no-bg/${qb.player_name.replace(
".",
""
)}.png`}
Expand Down
14 changes: 13 additions & 1 deletion run_scripts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
from pathlib import Path
import subprocess
import sys

exit_code = 0

# Loop through all Python scripts in the top-level of the scripts folder
for script in sorted(Path("scripts").glob("*.py")):
subprocess.run(["python", script], check=True)
try:
print(f"Running {script}...")
subprocess.run(["python", str(script)], check=True)
except subprocess.CalledProcessError as e:
print(f"Script {script} failed: {e}")
exit_code = 1 # Mark failure but continue to next script

# Exit with 1 if any script failed, 0 otherwise
sys.exit(exit_code)