Release #44
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Release | |
on: workflow_dispatch | |
jobs: | |
build: | |
name: Publish a release | |
runs-on: ubuntu-latest | |
# Specifying an environment is strongly recommended by PyPI. | |
# See https://github.com/pypa/gh-action-pypi-publish/tree/release/v1/?tab=readme-ov-file#trusted-publishing. | |
environment: release | |
permissions: | |
# This is needed for PyPI publishing. | |
# See https://github.com/pypa/gh-action-pypi-publish/tree/release/v1/?tab=readme-ov-file#trusted-publishing. | |
id-token: write | |
# This is needed for https://github.com/stefanzweifel/git-auto-commit-action. | |
contents: write | |
strategy: | |
matrix: | |
python-version: ["3.12"] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# See | |
# https://github.com/stefanzweifel/git-auto-commit-action?tab=readme-ov-file#push-to-protected-branches | |
token: ${{ secrets.RELEASE_PAT }} | |
# Fetch all history including tags. | |
# Needed to find the latest tag. | |
fetch-depth: 0 | |
- name: Install uv | |
uses: astral-sh/setup-uv@v3 | |
- name: Get current version | |
id: get_current_version | |
run: | | |
version="$(git describe --tags --abbrev=0)" | |
echo "version=${version}" >> "$GITHUB_OUTPUT" | |
- name: "Calver calculate version" | |
uses: StephaneBour/actions-calver@master | |
id: calver | |
with: | |
date_format: "%Y.%m.%d" | |
release: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Update changelog" | |
uses: jacobtomlinson/gha-find-replace@v3 | |
with: | |
find: "Next\n----" | |
replace: "Next\n----\n\n${{ steps.calver.outputs.release }}\n------------" | |
include: "CHANGELOG.rst" | |
regex: false | |
- uses: stefanzweifel/git-auto-commit-action@v5 | |
id: commit | |
with: | |
commit_message: Bump CHANGELOG | |
file_pattern: CHANGELOG.rst | |
- name: Bump version and push tag | |
id: tag_version | |
uses: mathieudutour/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
custom_tag: ${{ steps.calver.outputs.release }} | |
tag_prefix: "" | |
commit_sha: ${{ steps.commit.outputs.commit_hash }} | |
- name: Create Linux binaries | |
run: | | |
PYTHONPATH=. uv run --extra=dev admin/release.py | |
- name: Create a GitHub release | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "dist/*" | |
tag: ${{ steps.tag_version.outputs.new_tag }} | |
name: Release ${{ steps.tag_version.outputs.new_tag }} | |
body: ${{ steps.tag_version.outputs.changelog }} | |
- name: Build a binary wheel and a source tarball | |
run: | | |
sudo rm -rf dist/ build/ | |
git fetch --tags | |
git checkout ${{ steps.tag_version.outputs.new_tag }} | |
uv build --sdist --wheel --out-dir dist/ | |
uv run --extra=release check-wheel-contents dist/*.whl | |
# We use PyPI trusted publishing rather than a PyPI API token. | |
# See https://github.com/pypa/gh-action-pypi-publish/tree/release/v1/?tab=readme-ov-file#trusted-publishing. | |
- name: Publish distribution 📦 to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
verbose: true | |
# We have a race condition. | |
# In particular, we push to PyPI and then immediately try to install | |
# the pushed version. | |
# Here, we give PyPI time to propagate the package. | |
- name: Install doccmd from PyPI | |
uses: nick-fields/retry@v3 | |
with: | |
timeout_seconds: 20 | |
max_attempts: 20 | |
command: uv pip install --no-cache doccmd==${{ steps.calver.outputs.release }} | |
- name: Create a Homebrew recipe | |
id: homebrew-create | |
env: | |
FILENAME: doccmd.rb | |
run: | | |
uv run --extra=release --with="doccmd==${{ steps.calver.outputs.release }}" poet --formula doccmd > ${{ env.FILENAME }} | |
echo "HOMEBREW_RECIPE_FILE=${{ env.FILENAME }}" >> "$GITHUB_OUTPUT" | |
- name: "Update Homebrew description" | |
uses: jacobtomlinson/gha-find-replace@v3 | |
with: | |
find: "desc \"Shiny new formula\"" | |
replace: "desc \"Run tools against code blocks in documentation\"" | |
include: ${{ steps.homebrew-create.outputs.HOMEBREW_RECIPE_FILE }} | |
regex: false | |
- name: Push Homebrew Recipe | |
uses: dmnemec/copy_file_to_another_repo_action@main | |
env: | |
# See https://github.com/marketplace/actions/github-action-to-push-subdirectories-to-another-repo#usage | |
# for how to get this token. | |
# I do not yet know how to set this up to work with a | |
# "Fine-grained personal access token", only a "Token (classic)" with "repo" settings. | |
API_TOKEN_GITHUB: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} | |
with: | |
destination_branch: main | |
source_file: ${{ steps.homebrew-create.outputs.HOMEBREW_RECIPE_FILE }} | |
destination_repo: 'adamtheturtle/homebrew-doccmd' | |
user_email: '[email protected]' | |
user_name: 'adamtheturtle' | |
commit_message: 'Bump CLI Homebrew recipe' | |
- name: "Update README versions" | |
uses: jacobtomlinson/gha-find-replace@v3 | |
with: | |
find: ${{ steps.get_current_version.outputs.version }} | |
replace: ${{ steps.calver.outputs.release }} | |
include: "README.rst" | |
regex: false | |
- uses: stefanzweifel/git-auto-commit-action@v5 | |
id: commit-readme | |
with: | |
commit_message: Replace version in README | |
branch: main | |
file_pattern: README.rst |