From ae0cc4e318e47c0be78adee932da268883473818 Mon Sep 17 00:00:00 2001 From: R Brook Date: Mon, 22 Dec 2025 23:39:53 +0100 Subject: [PATCH 1/6] [12] Update to fallback to last successful artifact. --- .github/workflows/nextjs.yml | 131 +++++------------------------------ 1 file changed, 19 insertions(+), 112 deletions(-) diff --git a/.github/workflows/nextjs.yml b/.github/workflows/nextjs.yml index 353a8c3..96ddbbb 100644 --- a/.github/workflows/nextjs.yml +++ b/.github/workflows/nextjs.yml @@ -1,31 +1,26 @@ -# 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"] - - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: contents: read pages: write id-token: write -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: group: "pages" 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 @@ -40,112 +35,24 @@ 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 - uses: actions/upload-artifact@v4 - with: - name: python-output - # File the script produces - path: | - scripts/generated-files/team-data.ts - scripts/generated-files/qb-data-weekly.ts - scripts/generated-files/qb-data-season.ts - scripts/generated-files/ngs-data-passing.ts - 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 - with: - name: python-output - path: ./python-output - - - name: Move Python output into project - run: | - cp -r ./python-output/* scripts/generated-files/ - - - name: Detect package manager - id: detect-package-manager - run: | - if [ -f "${{ github.workspace }}/package.json" ]; then - echo "manager=npm" >> $GITHUB_OUTPUT - echo "command=ci" >> $GITHUB_OUTPUT - echo "runner=npx --no-install" >> $GITHUB_OUTPUT - exit 0 - else - echo "Unable to determine package manager" - exit 1 + 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: Setup Node - uses: actions/setup-node@v4 + - name: Download previous successful Python artifact (if needed) + if: steps.run-python.outputs.script_status != '0' + uses: actions/github-script@v7 with: - node-version: "22.16.0" - cache: ${{ steps.detect-package-manager.outputs.manager }} - - - name: Setup Pages - uses: actions/configure-pages@v5 - with: - # Automatically inject basePath in your Next.js configuration file and disable - # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized). - # - # You may remove this line if you want to manage the configuration yourself. - static_site_generator: next - - - name: Restore cache - uses: actions/cache@v4 - with: - path: | - .next/cache - # Generate a new cache whenever packages or source files change. - 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') }}- - - - 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 - - - name: Build with Next.js - run: ${{ steps.detect-package-manager.outputs.runner }} next build - - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - path: ./out - - # Deployment job - deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: build - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const artifactName = 'python-output'; + const owner = context.repo.owner; + co From dfa885e26aad83d5c0969b954466162a147bf924 Mon Sep 17 00:00:00 2001 From: R Brook Date: Mon, 22 Dec 2025 23:41:28 +0100 Subject: [PATCH 2/6] [8] Re-add Next.js steps. --- .github/workflows/nextjs.yml | 123 ++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nextjs.yml b/.github/workflows/nextjs.yml index 96ddbbb..3aba810 100644 --- a/.github/workflows/nextjs.yml +++ b/.github/workflows/nextjs.yml @@ -55,4 +55,125 @@ jobs: script: | const artifactName = 'python-output'; const owner = context.repo.owner; - co + 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 + path: | + scripts/generated-files/team-data.ts + scripts/generated-files/qb-data-weekly.ts + scripts/generated-files/qb-data-season.ts + scripts/generated-files/ngs-data-passing.ts + scripts/generated-files/ngs-data-receiving.ts + scripts/generated-files/ngs-data-rushing.ts + + build: + needs: data_fetch + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Download Python artifact + uses: actions/download-artifact@v4 + with: + name: python-output + path: ./python-output + + - name: Move Python output into project + run: cp -r ./python-output/* scripts/generated-files/ + + - name: Detect package manager + id: detect-package-manager + run: | + if [ -f "${{ github.workspace }}/package.json" ]; then + echo "manager=npm" >> $GITHUB_OUTPUT + echo "command=ci" >> $GITHUB_OUTPUT + echo "runner=npx --no-install" >> $GITHUB_OUTPUT + exit 0 + else + echo "Unable to determine package manager" + exit 1 + fi + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "22.16.0" + cache: ${{ steps.detect-package-manager.outputs.manager }} + + - name: Setup Pages + uses: actions/configure-pages@v5 + with: + static_site_generator: next + + - name: Restore cache + uses: actions/cache@v4 + with: + path: .next/cache + key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} + 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 + + - name: Build with Next.js + run: ${{ steps.detect-package-manager.outputs.runner }} next build + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: ./out + + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 From adf82e4041c77d71a6a4914d88dcb4caecefa594 Mon Sep 17 00:00:00 2001 From: R Brook Date: Mon, 22 Dec 2025 23:50:03 +0100 Subject: [PATCH 3/6] [12] Add comments back in. --- .github/workflows/nextjs.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nextjs.yml b/.github/workflows/nextjs.yml index 3aba810..3985302 100644 --- a/.github/workflows/nextjs.yml +++ b/.github/workflows/nextjs.yml @@ -2,15 +2,20 @@ name: Deploy Next.js site to Pages on: + # Runs on pushes targeting the default branch push: branches: ["main"] + # Allows you to run this workflow manually from the Actions tab workflow_dispatch: +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: contents: read pages: write id-token: write +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: group: "pages" cancel-in-progress: false @@ -98,6 +103,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: python-output + # File the script produces path: | scripts/generated-files/team-data.ts scripts/generated-files/qb-data-weekly.ts @@ -112,7 +118,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - + # Download Python artifact before building - name: Download Python artifact uses: actions/download-artifact@v4 with: @@ -144,6 +150,10 @@ jobs: - name: Setup Pages uses: actions/configure-pages@v5 with: + # Automatically inject basePath in your Next.js configuration file and disable + # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized). + # + # You may remove this line if you want to manage the configuration yourself. static_site_generator: next - name: Restore cache @@ -151,6 +161,7 @@ jobs: with: 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') }}- - name: Install dependencies From 80f4dd69c688a89d8c9217c507d41b80d287ee23 Mon Sep 17 00:00:00 2001 From: R Brook Date: Mon, 22 Dec 2025 23:58:03 +0100 Subject: [PATCH 4/6] [12] Update run_scripts to fix pipeline. --- run_scripts.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/run_scripts.py b/run_scripts.py index 6236752..b02a62c 100644 --- a/run_scripts.py +++ b/run_scripts.py @@ -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) From 69c717f559d91cfe1a9c09ccdb0e0a2087977511 Mon Sep 17 00:00:00 2001 From: R Brook Date: Tue, 23 Dec 2025 00:00:35 +0100 Subject: [PATCH 5/6] [12] Run action on feature branch. --- .github/workflows/nextjs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nextjs.yml b/.github/workflows/nextjs.yml index 3985302..3d026b6 100644 --- a/.github/workflows/nextjs.yml +++ b/.github/workflows/nextjs.yml @@ -4,7 +4,7 @@ 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: From 663e2d0879a98fd2481f2b8357900cc8a4081b67 Mon Sep 17 00:00:00 2001 From: R Brook Date: Tue, 23 Dec 2025 00:11:45 +0100 Subject: [PATCH 6/6] [12] Fix broken local images on deployed instance. --- components/qb-touchdowns/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/qb-touchdowns/index.tsx b/components/qb-touchdowns/index.tsx index 4c154d7..28658f8 100644 --- a/components/qb-touchdowns/index.tsx +++ b/components/qb-touchdowns/index.tsx @@ -26,7 +26,7 @@ export const QBTouchdowns = () => {