Repository navigation
WARN Monitor & Dashboard Update #290
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: WARN Monitor & Dashboard Update | |
| on: | |
| schedule: | |
| # Runs at 00:00 and 12:00 UTC every day | |
| - cron: '0 0,12 * * *' | |
| workflow_dispatch: | |
| # Allows manual triggering from the Actions tab | |
| permissions: | |
| contents: write | |
| jobs: | |
| update-dashboard: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GH_REPO_TOKEN }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| # Core testing and formatting tools | |
| pip install black pytest-mock pytest-cov python-dotenv | |
| - name: Run logic tests | |
| env: | |
| PYTHONPATH: . | |
| GMAIL_USER: ${{ secrets.GMAIL_USER }} | |
| GMAIL_APP_PASSWORD: ${{ secrets.GMAIL_APP_PASSWORD }} | |
| NOTIFY_EMAIL: ${{ secrets.NOTIFY_EMAIL }} | |
| run: | | |
| # Ensure directories exist for the structure tests | |
| mkdir -p data/historical/pdfs docs/charts | |
| pytest -v --cov=. | |
| - name: Run WARN Update Pipeline | |
| id: pipeline | |
| env: | |
| GMAIL_USER: ${{ secrets.GMAIL_USER }} | |
| GMAIL_APP_PASSWORD: ${{ secrets.GMAIL_APP_PASSWORD }} | |
| NOTIFY_EMAIL: ${{ secrets.NOTIFY_EMAIL }} | |
| GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} | |
| # Signup form endpoint (public Apps Script URL) — repo variable, not secret | |
| SIGNUP_ENDPOINT: ${{ vars.SIGNUP_ENDPOINT }} | |
| # Shared token to read the subscriber list (matches Apps Script LIST_TOKEN) | |
| SUBSCRIBERS_TOKEN: ${{ secrets.SUBSCRIBERS_TOKEN }} | |
| run: | | |
| # We run the consolidated publish script | |
| # --no-push allows the Action to handle Git operations safely | |
| python3 warn_publish.py --no-push | |
| - name: Commit and push changes | |
| # Runs on pipeline success AND pipeline failure — but only when the | |
| # pipeline step actually ran. A failed run has already sent its alert | |
| # emails (warn_publish raises on a root-site build failure only AFTER | |
| # the notifications go out), and the ledgers recording those sends | |
| # (data/notified_keys.json, amended_keys.json, digest_sent.json, and | |
| # data/states/*) exist only in this throwaway workspace. Discarding | |
| # them re-emails every subscriber the same notices next run. The | |
| # outcome gate keeps a totally-failed run (dependency install or test | |
| # failure — pipeline outcome 'skipped') from committing garbage. | |
| if: ${{ !cancelled() && (steps.pipeline.outcome == 'success' || steps.pipeline.outcome == 'failure') }} | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| if [ "${{ steps.pipeline.outcome }}" = "success" ]; then | |
| # Full publish: data and the rebuilt site. | |
| git add data/ docs/ | |
| MSG="auto: WARN data update [skip ci]" | |
| else | |
| # Root site build failed: persist ONLY the alert ledgers so | |
| # already-sent alerts are never re-emailed. docs/ stays | |
| # uncommitted — the last good page remains published. | |
| git add data/ | |
| MSG="auto: alert ledgers (pipeline failed) [skip ci]" | |
| fi | |
| # Only commit/push if there are actual changes staged | |
| if ! git diff --cached --quiet; then | |
| git commit -m "$MSG" | |
| git push | |
| else | |
| echo "No changes to commit" | |
| fi |