Skip to content

Commit

Permalink
Implement github action to automatically generate reports and commit …
Browse files Browse the repository at this point in the history
…them
  • Loading branch information
bolny committed Jan 16, 2025
1 parent ce710cf commit 8bc032e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/run_application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run Application

on:
schedule:
- cron: '0 4 * * *'

jobs:
run_application:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v3

- name: Install Python
run: uv python install

- name: Install dependencies
run: uv sync --all-extras

- name: Run application
run: uv run main.py

- name: Commit and push report
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add reports/.
git commit -m "Automated commit of application output"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 6 additions & 2 deletions utils/output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from datetime import datetime
from os import makedirs
import pytz

REPORTS_DIR = "./reports/"

# Mapping the zone names used by BC to the zone names from the legacy report
# produced by Environment Canada.
ZONE_NAME_MAP = {
Expand Down Expand Up @@ -128,9 +131,10 @@ def _generate_report_text(forecast_data: dict[str, dict[str, float]]) -> tuple[s

def generate_forecast_text_file(forecast_data: dict[str, dict[str, float]]) -> None:
filename, output = _generate_report_text(forecast_data)
makedirs(REPORTS_DIR, exist_ok=True)

print(f"outputting to file {filename}")
print(f"outputting to file {REPORTS_DIR}{filename}")
print("==============")
print(output)

_write_file(filename, output)
_write_file(f"{REPORTS_DIR}{filename}", output)

0 comments on commit 8bc032e

Please sign in to comment.