Skip to content

Commit

Permalink
πŸ‘· ci: add workflow to auto sync latest version (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
SigureMo authored Jan 18, 2025
1 parent cd6357f commit 0ae5eee
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/mirror.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Mirror
on:
push:
branches: [main]
workflow_dispatch:
schedule:
- cron: "0 12 * * *"

jobs:
build:
name: Mirror
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Install python
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Setup git
run: |
git config --global user.name 'Github Actions'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
- name: Run mirror
run: |
uv run --script mirror.py
- name: Push changes
run: |
git remote set-url origin https://x-access-token:[email protected]/$GITHUB_REPOSITORY
git push origin HEAD:refs/heads/main --tags
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23 changes: 16 additions & 7 deletions mirror.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "tomli>=2.2.1",
# "tomli-w>=1.2.0",
# "urllib3>=2",
# "packaging>=21.0",
# ]
# ///

import subprocess
from pathlib import Path

Expand All @@ -9,7 +19,7 @@


def main():
# 读取 pyproject.toml ζ–‡δ»Ά
# Load pyproject.toml
with open(Path(__file__).parent / "pyproject.toml", "rb") as f:
pyproject = tomli.load(f)

Expand All @@ -23,7 +33,7 @@ def main():
assert typos_specs[0].operator == "=="
current_version = Version(typos_specs[0].version)

# 从 PyPI θŽ·ε– typos ηš„ζ‰€ζœ‰η‰ˆζœ¬
# Get typos versions from PyPI
http = urllib3.PoolManager()
resp = http.request("GET", "https://pypi.org/pypi/typos/json")
if resp.status != 200:
Expand All @@ -33,16 +43,15 @@ def main():
versions = [v for v in versions if v > current_version and not v.is_prerelease]
versions.sort()

# ε¦‚ζžœζœ‰ζ–°η‰ˆζœ¬οΌŒζ›΄ζ–° pyproject.toml 文仢幢提亀
# Update typos for each version
for version in versions:
# ζ›΄ζ–° dependencies ιƒ¨εˆ†
# Update pyproject.toml
pyproject["project"]["version"] = str(version)
pyproject["project"]["dependencies"] = [f"typos=={version}"]

# 写ε…₯ζ›΄ζ–°εŽηš„ pyproject.toml
with open(Path(__file__).parent / "pyproject.toml", "wb") as f:
tomli_w.dump(pyproject, f)

# ζ‰§θ‘Œ Git ζ“δ½œ
# Commit and tag
subprocess.run(["git", "add", "pyproject.toml"])
subprocess.run(["git", "commit", "-m", f"Update typos to {version}"])
subprocess.run(["git", "tag", f"v{version}"])
Expand Down

0 comments on commit 0ae5eee

Please sign in to comment.