diff --git a/.github/workflows/auto-push-main.yml b/.github/workflows/auto-push-main.yml new file mode 100644 index 0000000..fc3f2d5 --- /dev/null +++ b/.github/workflows/auto-push-main.yml @@ -0,0 +1,60 @@ +name: Auto Push to Main + +on: + push: + branches: [testing] + +permissions: + contents: write + pull-requests: write + +jobs: + lint-test-merge: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # needed for ahead/behind check + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + pip install ruff + pip install -r tests/requirements.txt + + - name: Lint (ruff) + run: ruff check . + + - name: Tests (pytest) + run: pytest tests/ -v + + - name: Check if testing is ahead of main + id: ahead_check + run: | + git fetch origin main + AHEAD=$(git rev-list origin/main..HEAD --count) + echo "ahead=$AHEAD" >> "$GITHUB_OUTPUT" + + - name: Create PR (testing → main) + if: steps.ahead_check.outputs.ahead != '0' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr create \ + --base main \ + --head testing \ + --title "Auto-merge: testing → main (run #${{ github.run_number }})" \ + --body "Automatically created by **Auto Push to Main** workflow after lint and tests passed on the \`testing\` branch." \ + || echo "PR already exists — will merge existing PR" + + - name: Merge PR into main + if: steps.ahead_check.outputs.ahead != '0' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh pr merge testing --merge --delete-branch=false diff --git a/tests/requirements.txt b/tests/requirements.txt index ff4c6b5..c40fa15 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,4 +1,5 @@ pytest>=7.0,<9 pytest-mock>=3.0,<4 flask>=2.3,<4 +flask-wtf>=1.1,<2 praw>=7.6,<8 diff --git a/tests/test_web_app.py b/tests/test_web_app.py index 753615d..2fbdaad 100644 --- a/tests/test_web_app.py +++ b/tests/test_web_app.py @@ -19,6 +19,7 @@ def client(): flask_app.config["TESTING"] = True flask_app.config["SECRET_KEY"] = "test-secret" + flask_app.config["WTF_CSRF_ENABLED"] = False with flask_app.test_client() as c: yield c diff --git a/web/app.py b/web/app.py index b0a7ecb..0472405 100644 --- a/web/app.py +++ b/web/app.py @@ -1,7 +1,6 @@ import json import os import sys -import time from datetime import datetime, timezone import praw