diff --git a/.github/workflows/run-script.yml b/.github/workflows/run-script.yml index 3868971..d2c71f9 100644 --- a/.github/workflows/run-script.yml +++ b/.github/workflows/run-script.yml @@ -1,13 +1,13 @@ name: Run Script on: - push: - branches: - - main schedule: - cron: "30 */3 * * *" workflow_dispatch: +permissions: + contents: write + jobs: run-script: runs-on: ubuntu-latest @@ -32,7 +32,18 @@ jobs: env: BARGHEMAN_TOKEN: ${{ secrets.BARGHEMAN_TOKEN }} EITAAYAR_TOKEN: ${{ secrets.EITAAYAR_TOKEN }} + BLACKOUTS_FILE: "blackouts.json" BILL_IDS: ${{ secrets.BILL_IDS }} CHAT_ID: ${{ secrets.CHAT_ID }} run: | python main.py + + - name: Commit & Push updated data + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config --global user.name "github-actions" + git config --global user.email "github-actions@github.com" + git add blackouts.json + git commit -m "Update outage data" || echo "Nothing to commit" + git push diff --git a/main.py b/main.py index c31a972..435f946 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ BARGHEMAN_TOKEN = os.getenv("BARGHEMAN_TOKEN") EITAAYAR_TOKEN = os.getenv("EITAAYAR_TOKEN") CHAT_ID = os.getenv("CHAT_ID") BILL_IDS = os.getenv("BILL_IDS", "").split(",") -BLACKOUTS_FILE = "blackouts.json" +BLACKOUTS_FILE = os.getenv("BLACKOUTS_FILE") if not BARGHEMAN_TOKEN or not EITAAYAR_TOKEN or not CHAT_ID or len(BILL_IDS) == 0: raise EnvironmentError("Environment is not ready!") @@ -91,13 +91,7 @@ def main() -> None: if new_entries: updated_data[bill_id] = old_blackouts + new_entries - if updated_data != previous_data: - save_blackouts(updated_data) - os.system("git config --global user.name 'github-actions'") - os.system("git config --global user.email 'github-actions@github.com'") - os.system("git add " + BLACKOUTS_FILE) - os.system("git commit -m 'Update outage data'") - os.system("git push") + save_blackouts(updated_data) if __name__ == '__main__':