Skip to content

Commit

Permalink
Add a workflow to sync Python releases automatically (astral-sh#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 authored Feb 20, 2024
1 parent bd2bfa5 commit 02a5e09
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

jobs:
build:
if: github.repository == 'mitsuhiko/rye'
name: Deploy docs
runs-on: ubuntu-latest
steps:
Expand All @@ -18,7 +19,6 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Deploy docs
uses: mhausenblas/mkdocs-deploy-gh-pages@master
if: github.repository == 'mitsuhiko/rye'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CONFIG_FILE: mkdocs.yml
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/sync-python-releases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# For this action to work you must explicitly allow GitHub Actions to create pull requests.
# This setting can be found in a repository's settings under Actions > General > Workflow permissions.
# For repositories belonging to an organization, this setting can be managed by
# admins in organization settings under Actions > General > Workflow permissions.
name: Sync Python Releases
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

jobs:
sync:
if: github.repository == 'mitsuhiko/rye'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rye
uses: eifinger/setup-rye@v1
with:
enable-cache: true
- name: Sync Python Releases
run: make sync-python-releases
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create PR
uses: peter-evans/create-pull-request@v6
with:
commit-message: "Sync latest Python releases"
add-paths: "src/rye/downloads.inc"
branch: "sync-python-releases"
title: "Sync Python Releases"
body: |
- Synced latest Python releases
<sup>Auto-generated by [sync-python-releases.yml](.github/workflows/sync-python-releases.yml)</sup>
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ lint:

.venv:
@rye sync

.PHONY: sync-python-releases
sync-python-releases: .venv
@rye run find-downloads > rye/src/downloads.inc
13 changes: 12 additions & 1 deletion rye-devtools/src/rye_devtools/find_downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import abc
import asyncio
import itertools
import os
import re
import sys
import time
Expand Down Expand Up @@ -447,7 +448,17 @@ def sort_key(download: PythonDownload) -> tuple[int, PythonVersion, PlatformTrip


async def async_main():
token = open("token.txt").read().strip()
token = os.environ.get("GITHUB_TOKEN")
if not token:
try:
token = open("token.txt").read().strip()
except Exception:
pass

if not token:
log("Please set GITHUB_TOKEN environment variable or create a token.txt file.")
sys.exit(1)

headers = {
"X-GitHub-Api-Version": "2022-11-28",
"Authorization": "Bearer " + token,
Expand Down

0 comments on commit 02a5e09

Please sign in to comment.