Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ name: Publish
on:
push:
tags: [ '[0-9]+.[0-9]+.[0-9]+*' ]
# Used by release.yml: a tag pushed with GITHUB_TOKEN does not trigger the
# push event above, but a workflow_dispatch does. Run it on a tag ref.
workflow_dispatch:

permissions: {}

jobs:
# Lint, tests, the tag/__version__ check and the build, from test.yml.
ci:
if: ${{ startsWith(github.ref, 'refs/tags/') }}
# A job-level call resolves from this commit, not the runner's files, so
# the newer "$/" self-repository syntax buys nothing here.
uses: ./.github/workflows/test.yml # zizmor: ignore[self-repository]
Expand All @@ -23,6 +27,7 @@ jobs:
# Must stay a job of this workflow: PyPI trusted publishing does not
# accept uploads from inside a reusable (called) workflow.
needs: ci
if: ${{ startsWith(github.ref, 'refs/tags/') }}
runs-on: ubuntu-latest
environment:
name: pypi
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Release

# Manually started from the Actions tab (or `gh workflow run release.yml -f
# version=X.Y.Z`). Sets __version__, commits "Version number -> X.Y.Z" on
# main, tags it X.Y.Z, pushes both, then starts publish.yml on the new tag.
on:
workflow_dispatch:
inputs:
version:
description: "Version to release, e.g. 1.2.0 or 1.2.0rc1 (no 'v' prefix)"
required: true
type: string

permissions: {}

concurrency:
group: release
cancel-in-progress: false

jobs:
release:
name: Bump, tag and trigger publish
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
permissions:
contents: write # push the version commit and tag
actions: write # start publish.yml
env:
VERSION: ${{ inputs.version }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Validate version
env:
GH_TOKEN: ${{ github.token }}
run: |
if ! [[ "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?$ ]]; then
echo "::error::'${VERSION}' is not a version like 1.2.0 or 1.2.0rc1"
exit 1
fi
if gh api "repos/${GITHUB_REPOSITORY}/git/ref/tags/${VERSION}" --silent 2>/dev/null; then
echo "::error::Tag ${VERSION} already exists"
exit 1
fi

- name: Set __version__
run: |
sed -i -E "s/^__version__ = \".*\"$/__version__ = \"${VERSION}\"/" ipython_pygments_lexers/__init__.py
grep -qx "__version__ = \"${VERSION}\"" ipython_pygments_lexers/__init__.py
if git diff --quiet; then
echo "::error::__version__ is already ${VERSION}"
exit 1
fi

- name: Commit, tag and push
env:
GH_TOKEN: ${{ github.token }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -am "Version number -> ${VERSION}"
git tag -a "${VERSION}" -m "Release ${VERSION}"
git push --atomic "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" \
HEAD:refs/heads/main "refs/tags/${VERSION}"

- name: Start publish workflow
env:
GH_TOKEN: ${{ github.token }}
run: |
gh workflow run publish.yml --repo "${GITHUB_REPOSITORY}" --ref "${VERSION}"
echo "Publishing ${VERSION}: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/workflows/publish.yml" >> "${GITHUB_STEP_SUMMARY}"