|
| 1 | +name: CPython Patch PR (Guarded) |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '15 7 * * 1-5' # Weekdays at 07:15 UTC |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: python-version-patch |
| 10 | + cancel-in-progress: false |
| 11 | + |
| 12 | +env: |
| 13 | + TRACK: '3.13' |
| 14 | + SECURITY_KEYWORDS: 'security,CVE,critical' |
| 15 | + |
| 16 | +jobs: |
| 17 | + preview: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + outputs: |
| 22 | + new_version: ${{ steps.preview.outputs.new_version }} |
| 23 | + files_changed: ${{ steps.preview.outputs.files_changed }} |
| 24 | + skipped_reason: ${{ steps.preview.outputs.skipped_reason }} |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Preview CPython patch diff |
| 30 | + id: preview |
| 31 | + uses: casperkristiansson/python-version-patch-pr@v0 |
| 32 | + with: |
| 33 | + track: ${{ env.TRACK }} |
| 34 | + dry_run: true |
| 35 | + |
| 36 | + - name: Summarize planned changes |
| 37 | + if: steps.preview.outputs.skipped_reason == '' |
| 38 | + run: | |
| 39 | + echo "Found proposed bump to version: ${{ steps.preview.outputs.new_version }}" |
| 40 | + echo "Files changed JSON:" |
| 41 | + echo '${{ steps.preview.outputs.files_changed }}' |
| 42 | +
|
| 43 | + apply: |
| 44 | + needs: preview |
| 45 | + if: needs.preview.outputs.skipped_reason == '' |
| 46 | + runs-on: ubuntu-latest |
| 47 | + permissions: |
| 48 | + contents: write |
| 49 | + pull-requests: write |
| 50 | + environment: |
| 51 | + name: production |
| 52 | + steps: |
| 53 | + - name: Checkout repository |
| 54 | + uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + fetch-depth: 0 |
| 57 | + |
| 58 | + - name: Enforce release note guard |
| 59 | + env: |
| 60 | + NEW_VERSION: ${{ needs.preview.outputs.new_version }} |
| 61 | + SECURITY_KEYWORDS: ${{ env.SECURITY_KEYWORDS }} |
| 62 | + run: | |
| 63 | + if [[ -z "$NEW_VERSION" ]]; then |
| 64 | + echo "No new version detected; skipping guard." |
| 65 | + exit 0 |
| 66 | + fi |
| 67 | +
|
| 68 | + python - <<'PY' |
| 69 | +import os |
| 70 | +import sys |
| 71 | +import urllib.request |
| 72 | + |
| 73 | +version = os.environ['NEW_VERSION'] |
| 74 | +keywords = [kw.strip().lower() for kw in os.environ.get('SECURITY_KEYWORDS', '').split(',') if kw.strip()] |
| 75 | +if not keywords: |
| 76 | + sys.exit(0) |
| 77 | + |
| 78 | +slug = 'python-' + version.replace('.', '') |
| 79 | +url = f'https://www.python.org/downloads/release/{slug}/' |
| 80 | +print(f'Fetching release notes from {url}') |
| 81 | +try: |
| 82 | + with urllib.request.urlopen(url, timeout=30) as response: |
| 83 | + body = response.read().decode('utf-8', errors='replace').lower() |
| 84 | +except Exception as exc: # noqa: BLE001 |
| 85 | + print(f'Failed to fetch release notes: {exc}') |
| 86 | + sys.exit(1) |
| 87 | + |
| 88 | +if any(keyword in body for keyword in keywords): |
| 89 | + print('Security keyword detected in release notes.') |
| 90 | +else: |
| 91 | + print('No security keywords found; aborting update.') |
| 92 | + sys.exit(1) |
| 93 | +PY |
| 94 | + |
| 95 | + - name: Apply CPython patch update |
| 96 | + uses: casperkristiansson/python-version-patch-pr@v0 |
| 97 | + with: |
| 98 | + track: ${{ env.TRACK }} |
| 99 | + automerge: false |
| 100 | + env: |
| 101 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments