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
41 changes: 41 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish

# Releases are published only from this workflow, and only for version tags
# (e.g. 1.2.0, 1.2.0rc1). The PyPI trusted publisher is bound to this file
# name and to the "pypi" environment: do not rename it.
on:
push:
tags: [ '[0-9]+.[0-9]+.[0-9]+*' ]

permissions: {}

jobs:
# Lint, tests, the tag/__version__ check and the build, from test.yml.
ci:
# 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]
permissions:
contents: read

publish:
name: Publish to PyPI
# Must stay a job of this workflow: PyPI trusted publishing does not
# accept uploads from inside a reusable (called) workflow.
needs: ci
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/ipython-pygments-lexers/
permissions:
id-token: write # OIDC for uploading to PyPI

steps:
- name: Download packages
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dist
path: dist/

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
47 changes: 36 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ name: Tests
on:
push:
branches: [ main ]
tags: [ '*' ]
pull_request:
branches: [ main ]
workflow_dispatch:
# Called by publish.yml so a release runs the same checks and build.
workflow_call:

permissions:
contents: read
Expand Down Expand Up @@ -44,11 +45,18 @@ jobs:
run: python3 -m mypy

tests:
name: tests (Python ${{ matrix.python-version }}${{ matrix.pygments && format(', pygments{0}', matrix.pygments) || '' }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]
pygments: [""] # latest
include:
# Oldest supported Pygments, to keep the lower bound honest. This is
# a separate job because it differs from the [""] axis value.
- python-version: "3.11"
pygments: "==2.14.0"

steps:
- name: Checkout
Expand All @@ -62,21 +70,18 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
env:
PYGMENTS_SPEC: ${{ matrix.pygments }}
run: |
python3 -m pip install --upgrade pip
python3 -m pip install . --group test
python3 -m pip install . --group test "pygments${PYGMENTS_SPEC}"

- name: Test with pytest
run: |
python3 -m pytest -v

publish:
build:
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') }}
needs: [lint, tests]
permissions:
id-token: write # OIDC for uploading to PyPI

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand All @@ -86,12 +91,32 @@ jobs:
- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.11"
python-version: "3.x"

- name: Check tag matches __version__
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
version=$(python3 -c 'import re, pathlib; print(re.search(r"^__version__ = \"(.+)\"", pathlib.Path("ipython_pygments_lexers/__init__.py").read_text(), re.M).group(1))')
if [ "${GITHUB_REF_NAME}" != "${version}" ]; then
echo "::error::Tag ${GITHUB_REF_NAME} does not match __version__ ${version}"
exit 1
fi

- name: Build packages
run: |
python3 -m pip install --upgrade pip
python3 -m pip install build
python3 -m build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
- name: Test the built wheel
run: |
python3 -m pip install dist/*.whl --group test
cd "${RUNNER_TEMP}"
python3 -m pytest --import-mode=importlib "${GITHUB_WORKSPACE}/test_ipython_pygments_lexers.py"

- name: Upload packages
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: dist
path: dist/
if-no-files-found: error
Loading