2026-02-25 03:11:29 +00:00
|
|
|
import requests, os, sys, subprocess
|
2025-04-24 21:03:50 +00:00
|
|
|
|
|
|
|
|
def git(command):
|
2026-02-25 03:11:29 +00:00
|
|
|
return os.system(f"git {command}")
|
2021-01-07 10:19:11 +00:00
|
|
|
|
2026-02-25 03:11:29 +00:00
|
|
|
def git_output(command):
|
|
|
|
|
result = subprocess.run(f"git {command}", shell=True, capture_output=True, text=True)
|
|
|
|
|
return result.stdout.strip()
|
2021-01-07 10:19:11 +00:00
|
|
|
|
2026-02-25 03:11:29 +00:00
|
|
|
|
|
|
|
|
# Get latest upstream release
|
|
|
|
|
release = requests.get("https://api.github.com/repos/ProtonMail/proton-bridge/releases/latest").json()
|
2025-04-24 21:03:50 +00:00
|
|
|
version = release['tag_name']
|
2026-02-25 03:11:29 +00:00
|
|
|
print(f"Latest upstream release: {version}")
|
2021-01-07 10:19:11 +00:00
|
|
|
|
2026-02-25 03:11:29 +00:00
|
|
|
# Read current version
|
|
|
|
|
with open("VERSION", 'r') as f:
|
|
|
|
|
current_version = f.read().strip()
|
2021-01-07 10:19:11 +00:00
|
|
|
|
2026-02-25 03:11:29 +00:00
|
|
|
if version == current_version:
|
|
|
|
|
print("Already up to date.")
|
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
|
|
print(f"New version detected: {current_version} -> {version}")
|
2021-01-07 10:19:11 +00:00
|
|
|
|
2026-02-25 03:11:29 +00:00
|
|
|
# Don't push anything during pull_request runs (used for testing this script itself)
|
|
|
|
|
is_pull_request = len(sys.argv) > 1 and sys.argv[1] == "true"
|
|
|
|
|
if is_pull_request:
|
|
|
|
|
print("Pull request run — skipping push.")
|
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
|
|
# Write new version
|
|
|
|
|
with open("VERSION", 'w') as f:
|
|
|
|
|
f.write(version + "\n")
|
2021-01-07 10:19:11 +00:00
|
|
|
|
2026-02-25 03:11:29 +00:00
|
|
|
# Configure git identity
|
2025-04-24 21:03:50 +00:00
|
|
|
git("config --local user.name 'GitHub Actions'")
|
|
|
|
|
git("config --local user.email 'actions@github.com'")
|
2021-01-07 10:19:11 +00:00
|
|
|
|
2026-02-25 03:11:29 +00:00
|
|
|
# Create and push a branch for the version bump
|
|
|
|
|
branch = f"bump/{version}"
|
|
|
|
|
git(f"checkout -b {branch}")
|
|
|
|
|
git("add VERSION")
|
|
|
|
|
git(f'commit -m "Bump version to {version}"')
|
2021-01-07 10:19:11 +00:00
|
|
|
|
2026-02-25 03:11:29 +00:00
|
|
|
if git(f"push origin {branch}") != 0:
|
|
|
|
|
print("Git push failed!")
|
|
|
|
|
exit(1)
|
2021-01-07 10:19:11 +00:00
|
|
|
|
2026-02-25 03:11:29 +00:00
|
|
|
# Open a pull request via GitHub API
|
|
|
|
|
token = os.environ.get("GITHUB_TOKEN")
|
|
|
|
|
repo = os.environ.get("GITHUB_REPOSITORY")
|
2021-01-07 10:19:11 +00:00
|
|
|
|
2026-02-25 03:11:29 +00:00
|
|
|
upstream_url = f"https://github.com/ProtonMail/proton-bridge/releases/tag/{version}"
|
|
|
|
|
|
|
|
|
|
pr_body = f"""\
|
|
|
|
|
Automated version bump from `{current_version}` to `{version}`.
|
|
|
|
|
|
|
|
|
|
**Before merging:**
|
|
|
|
|
- Check the [upstream release notes]({upstream_url}) for any new system dependencies or breaking changes.
|
|
|
|
|
- Confirm the test build below passes. If it fails, a new dependency likely needs to be added to the Dockerfile.
|
|
|
|
|
|
|
|
|
|
This PR was opened automatically by the update-check workflow.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
response = requests.post(
|
|
|
|
|
f"https://api.github.com/repos/{repo}/pulls",
|
|
|
|
|
json={
|
|
|
|
|
"title": f"Bump version to {version}",
|
|
|
|
|
"body": pr_body,
|
|
|
|
|
"head": branch,
|
|
|
|
|
"base": "master",
|
|
|
|
|
},
|
|
|
|
|
headers={
|
|
|
|
|
"Authorization": f"token {token}",
|
|
|
|
|
"Accept": "application/vnd.github.v3+json",
|
|
|
|
|
},
|
|
|
|
|
)
|
2021-01-07 10:19:11 +00:00
|
|
|
|
2026-02-25 03:11:29 +00:00
|
|
|
if response.status_code == 201:
|
|
|
|
|
print(f"PR opened: {response.json()['html_url']}")
|
|
|
|
|
else:
|
|
|
|
|
print(f"Failed to create PR: {response.status_code} {response.text}")
|
|
|
|
|
exit(1)
|