Skip to content

Redeploy on policyengine-uk-compiled update #8

Redeploy on policyengine-uk-compiled update

Redeploy on policyengine-uk-compiled update #8

name: Redeploy on policyengine-uk-compiled update
on:
schedule:
- cron: '0 6 * * *' # daily at 6am UTC
workflow_dispatch:
jobs:
update-and-deploy:
name: Poll PyPI and redeploy if new version
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Poll PyPI and update modal_app.py
id: update
run: |
pip install requests packaging --quiet
python - <<'PYEOF'
import re, sys, time, os
import requests
from packaging.version import Version
content = open("modal_app.py").read()
m = re.search(r'policyengine-uk-compiled>=([0-9]+\.[0-9]+\.[0-9]+)', content)
current = Version(m.group(1)) if m else Version("0")
print(f"Current pinned: {current}")
# Poll PyPI for up to 10 minutes
latest = current
deadline = time.time() + 600
while time.time() < deadline:
r = requests.get("https://pypi.org/pypi/policyengine-uk-compiled/json", timeout=10)
latest = Version(r.json()["info"]["version"])
print(f"PyPI latest: {latest}")
if latest > current:
break
time.sleep(30)
if latest <= current:
print("No new version found within timeout.")
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write("should_deploy=false\n")
sys.exit(0)
new_content = re.sub(
r'policyengine-uk-compiled>=[0-9]+\.[0-9]+\.[0-9]+',
f'policyengine-uk-compiled>={latest}',
content,
)
open("modal_app.py", "w").write(new_content)
print(f"Updated modal_app.py to >={latest}")
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"new_version={latest}\n")
f.write("should_deploy=true\n")
PYEOF
- name: Commit updated modal_app.py
if: steps.update.outputs.should_deploy == 'true'
uses: EndBug/add-and-commit@v9
with:
add: modal_app.py
message: "chore: bump policyengine-uk-compiled to ${{ steps.update.outputs.new_version }}"
author_name: policyengine[bot]
author_email: policyengine[bot]@users.noreply.github.com
- name: Trigger Modal deploy
if: steps.update.outputs.should_deploy == 'true'
run: gh workflow run deploy.yml
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}