|
| 1 | +name: Create release PR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Version to release (e.g., 0.6.6)" |
| 8 | + required: true |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + release-pr: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v6 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + ref: main |
| 23 | + - name: Setup uv |
| 24 | + uses: astral-sh/setup-uv@v5 |
| 25 | + with: |
| 26 | + enable-cache: true |
| 27 | + - name: Fetch tags |
| 28 | + run: git fetch origin --tags --prune |
| 29 | + - name: Ensure release branch does not exist |
| 30 | + env: |
| 31 | + RELEASE_VERSION: ${{ inputs.version }} |
| 32 | + run: | |
| 33 | + branch="release/v${RELEASE_VERSION}" |
| 34 | + if git ls-remote --exit-code --heads origin "$branch" >/dev/null 2>&1; then |
| 35 | + echo "Branch $branch already exists on origin." >&2 |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | + - name: Update version |
| 39 | + env: |
| 40 | + RELEASE_VERSION: ${{ inputs.version }} |
| 41 | + run: | |
| 42 | + python - <<'PY' |
| 43 | + import os |
| 44 | + import pathlib |
| 45 | + import re |
| 46 | + import sys |
| 47 | +
|
| 48 | + version = os.environ["RELEASE_VERSION"] |
| 49 | + if version.startswith("v"): |
| 50 | + print("Version must not start with 'v' (use x.y.z...).", file=sys.stderr) |
| 51 | + sys.exit(1) |
| 52 | + if ".." in version: |
| 53 | + print("Version contains consecutive dots (use x.y.z...).", file=sys.stderr) |
| 54 | + sys.exit(1) |
| 55 | + if not re.match(r"^\d+\.\d+(\.\d+)*([a-zA-Z0-9\.-]+)?$", version): |
| 56 | + print( |
| 57 | + "Version must be semver-like (e.g., 0.6.6, 0.6.6-rc1, 0.6.6.dev1).", |
| 58 | + file=sys.stderr, |
| 59 | + ) |
| 60 | + sys.exit(1) |
| 61 | + path = pathlib.Path("pyproject.toml") |
| 62 | + text = path.read_text() |
| 63 | + updated, count = re.subn( |
| 64 | + r'(?m)^version\s*=\s*"[^\"]+"', |
| 65 | + f'version = "{version}"', |
| 66 | + text, |
| 67 | + ) |
| 68 | + if count != 1: |
| 69 | + print("Expected to update exactly one version line.", file=sys.stderr) |
| 70 | + sys.exit(1) |
| 71 | + if updated == text: |
| 72 | + print("Version already set; no changes made.", file=sys.stderr) |
| 73 | + sys.exit(1) |
| 74 | + path.write_text(updated) |
| 75 | + PY |
| 76 | + - name: Sync dependencies |
| 77 | + run: make sync |
| 78 | + - name: Configure git |
| 79 | + run: | |
| 80 | + git config user.name "github-actions[bot]" |
| 81 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 82 | + - name: Create release branch and commit |
| 83 | + env: |
| 84 | + RELEASE_VERSION: ${{ inputs.version }} |
| 85 | + run: | |
| 86 | + branch="release/v${RELEASE_VERSION}" |
| 87 | + git checkout -b "$branch" |
| 88 | + git add pyproject.toml uv.lock |
| 89 | + if git diff --cached --quiet; then |
| 90 | + echo "No changes to commit." >&2 |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + git commit -m "Bump version to ${RELEASE_VERSION}" |
| 94 | + git push --set-upstream origin "$branch" |
| 95 | + - name: Run Codex release review |
| 96 | + uses: openai/codex-action@v1 |
| 97 | + with: |
| 98 | + openai-api-key: ${{ secrets.PROD_OPENAI_API_KEY }} |
| 99 | + prompt-file: .github/codex/prompts/release-review.md |
| 100 | + output-file: release-review.md |
| 101 | + safety-strategy: drop-sudo |
| 102 | + sandbox: read-only |
| 103 | + - name: Build PR body |
| 104 | + run: | |
| 105 | + python - <<'PY' |
| 106 | + import pathlib |
| 107 | +
|
| 108 | + report = pathlib.Path("release-review.md").read_text() |
| 109 | + pathlib.Path("pr-body.md").write_text(report) |
| 110 | + PY |
| 111 | + - name: Create or update PR |
| 112 | + env: |
| 113 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 114 | + RELEASE_VERSION: ${{ inputs.version }} |
| 115 | + run: | |
| 116 | + head_branch="release/v${RELEASE_VERSION}" |
| 117 | + pr_number="$(gh pr list --head "$head_branch" --base "main" --json number --jq '.[0].number // empty')" |
| 118 | + if [ -z "$pr_number" ]; then |
| 119 | + gh pr create \ |
| 120 | + --title "Release ${RELEASE_VERSION}" \ |
| 121 | + --body-file pr-body.md \ |
| 122 | + --base "main" \ |
| 123 | + --head "$head_branch" |
| 124 | + else |
| 125 | + gh pr edit "$pr_number" --title "Release ${RELEASE_VERSION}" --body-file pr-body.md |
| 126 | + fi |
0 commit comments