Skip to content

Lommedalen Aurora Borealis Bot #3687

Lommedalen Aurora Borealis Bot

Lommedalen Aurora Borealis Bot #3687

Workflow file for this run

name: "Lommedalen Aurora Borealis Bot"
on:
schedule:
# Schedule updated daily by update-sun-schedule workflow based on astronomical darkness
# Default fallback: evening/morning hours
- cron: "*/15 0-23 * * *"
workflow_dispatch: # Manual trigger for testing
jobs:
aurora-detector:
runs-on: ubuntu-latest
timeout-minutes: 25 # Hard limit slightly above our target
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Quick darkness check
id: darkness
run: bash src/check_darkness.sh
continue-on-error: true
# Uses bash + jq for faster execution vs Python (~10x faster on Linux)
# Run first to exit early if not dark, saving time on cache/install steps
- name: Check KP index for aurora activity
id: kp_check
if: steps.darkness.outcome == 'success'
run: |
# Read MIN_KP from config.json
MIN_KP=$(jq -r '.aurora.min_kp_index' config.json)
OUTPUT=$(bash src/check_kp_multi.sh "$MIN_KP")
echo "$OUTPUT"
# Extract VALIDATED_KP from output and save to GITHUB_OUTPUT
VALIDATED_KP=$(echo "$OUTPUT" | grep "VALIDATED_KP=" | cut -d'=' -f2)
echo "validated_kp=$VALIDATED_KP" >> $GITHUB_OUTPUT
continue-on-error: true
# Check aurora activity from YR.no API
# Exits early if no activity detected, saving processing time
- name: Persist KP log data
if: steps.darkness.outcome == 'success'
run: |
# Get KP data directory from config
KP_DATA_DIR=$(jq -r '.data.kp_log_dir' config.json)
# If kp_data changed (new line appended), commit & push it.
if git diff --quiet --exit-code "$KP_DATA_DIR"; then
echo "No new KP data to persist"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add "$KP_DATA_DIR"
COMMIT_MSG="chore: log KP reading $(date -u +%Y-%m-%dT%H:%M:%SZ)"
git commit -m "$COMMIT_MSG" || echo "Nothing to commit"
git push || echo "Push failed"
echo "✅ Persisted KP data"
- name: Set up Python 3.11
if: steps.darkness.outcome == 'success' && steps.kp_check.outcome == 'success'
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Cache Python dependencies
if: steps.darkness.outcome == 'success' && steps.kp_check.outcome == 'success'
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
if: steps.darkness.outcome == 'success' && steps.kp_check.outcome == 'success'
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Restore shuffle state
if: steps.darkness.outcome == 'success' && steps.kp_check.outcome == 'success'
uses: actions/cache/restore@v4
with:
path: |
shuffle_state.json
key: shuffle-state-v2-${{ github.run_number }}
restore-keys: |
shuffle-state-v2-
continue-on-error: true
- name: Run Aurora Detection
if: steps.darkness.outcome == 'success' && steps.kp_check.outcome == 'success'
run: python src/main.py
env:
BSKY_HANDLE: ${{ secrets.BSKY_HANDLE }}
BSKY_PASSWORD: ${{ secrets.BSKY_PASSWORD }}
KEY_GITHUB_TOKEN: ${{ secrets.KEY_GITHUB_TOKEN }}
VALIDATED_KP: ${{ steps.kp_check.outputs.validated_kp }}
- name: Save shuffle state
uses: actions/cache/save@v4
if: always() && hashFiles('shuffle_state.json') != ''
with:
path: |
shuffle_state.json
key: shuffle-state-v2-${{ github.run_number }}
- name: Cleanup temporary files
if: always()
run: |
rm -rf today/
- name: Upload session logs (on failure)
uses: actions/upload-artifact@v4
if: failure()
with:
name: aurora-logs-${{ github.run_number }}
path: |
*.log
retention-days: 3