name: Prepare release
on:
workflow_dispatch:
inputs:
version:
description: Exact Cargo version to release, without a leading v
required: true
type: string
permissions: {}
jobs:
prepare:
name: Prepare release
if: github.repository == 'astral-sh/char_str' && github.ref_name == github.event.repository.default_branch
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 with:
fetch-depth: 0
persist-credentials: false
- uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Bump version
run: uv run scripts/release.py "$VERSION"
env:
VERSION: ${{ inputs.version }}
- name: Create or update pull request
run: |
branch="release/${VERSION}"
git switch -c "$branch"
git add Cargo.toml Cargo.lock
git commit -m "Bump version to ${VERSION}"
git push --force "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "HEAD:refs/heads/${branch}"
pull_request="$(
gh pr list \
--base "$DEFAULT_BRANCH" \
--head "$branch" \
--state open \
--json url \
--jq '.[0].url'
)"
if [ -n "$pull_request" ]; then
printf '%s\n' "$pull_request"
else
gh pr create \
--base "$DEFAULT_BRANCH" \
--head "$branch" \
--fill-first
fi
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ inputs.version }}