1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
name: python tests+artifacts+release
on:
pull_request:
push:
branches:
- "*"
tags:
- "v*"
release:
types: [published]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
env:
FORCE_COLOR: 1
jobs:
package:
name: Build & inspect our package.
runs-on: ubuntu-latest
env:
# Use no-local-version for package builds to ensure clean versions for PyPI uploads
SETUPTOOLS_SCM_NO_LOCAL: "1"
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: hynek/build-and-inspect-python-package@v2
test:
needs: [package]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python_version: [ '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', 'pypy-3.10' ]
os: [windows-latest, ubuntu-latest] #, macos-latest]
include:
- os: windows-latest
python_version: 'msys2'
env:
# Enable tracemalloc to debug gc errors with popen objects (especially on Windows)
PYTHONTRACEMALLOC: "1"
name: ${{ matrix.os }} - Python ${{ matrix.python_version }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v6
if: matrix.python_version != 'msys2'
with:
python-version: ${{ matrix.python_version }}
architecture: x64
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v6
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
if: matrix.python_version == 'msys2'
with:
msystem: MINGW64
install: git mingw-w64-x86_64-python mingw-w64-x86_64-python-setuptools
update: true
- name: Setup GnuPG and Mercurial on Windows
# At present, the Windows VMs only come with the copy of GnuPG that's bundled
# with Git for Windows. If we want to use this version _and_ be able to set
# arbitrary GnuPG home directories, then the test would need to figure out when
# to convert Windows-style paths into Unix-style paths with cygpath, which is
# unreasonable.
#
# Instead, we'll install a version of GnuPG that can handle Windows-style paths.
# However, due to <https://dev.gnupg.org/T5593>, installation fails if the PATH
# environment variable is too long. Consequently, we need to shorten PATH to
# something minimal before we can install GnuPG. For further details, see
# <https://github.com/actions/virtual-environments/issues/2876>.
#
# Additionally, we'll explicitly set `gpg.program` to ensure Git for Windows
# doesn't invoke the bundled GnuPG, otherwise we'll run into
# <https://dev.gnupg.org/T5504>. See also: <https://dev.gnupg.org/T3020>.
#
# Windows runners no longer ship with Mercurial pre-installed, so we install
# it via Chocolatey using the 'hg' package.
run: |
$env:PATH = "C:\Program Files\Git\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\Chocolatey\bin"
[Environment]::SetEnvironmentVariable("Path", $env:PATH, "Machine")
choco install gnupg hg -y --no-progress
echo "C:\Program Files (x86)\gnupg\bin" >> $env:GITHUB_PATH
echo "C:\Program Files\Mercurial\" >> $env:GITHUB_PATH
git config --system gpg.program "C:\Program Files (x86)\gnupg\bin\gpg.exe"
if: runner.os == 'Windows'
- run: uv sync --group test --group docs --extra rich
- uses: actions/download-artifact@v5
with:
name: Packages
path: dist
- shell: bash
run: uv pip install "$(echo -n dist/*whl)"
- run: |
$(hg debuginstall --template "{pythonexe}") -m pip install hg-git --user
if: matrix.os == 'ubuntu-latest'
# this hopefully helps with os caches, hg init sometimes gets 20s timeouts
- run: hg version
- run: uv run pytest
timeout-minutes: 25
dist_upload:
runs-on: ubuntu-latest
if: (github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')) || (github.event_name == 'release' && github.event.action == 'published')
permissions:
id-token: write
needs: [test]
steps:
- uses: actions/download-artifact@v5
with:
name: Packages
path: dist
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
upload-release-assets:
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
needs: [test]
permissions:
contents: write
steps:
- uses: actions/download-artifact@v5
with:
name: Packages
path: dist
- name: Upload release assets
uses: softprops/action-gh-release@v2
with:
files: dist/*
fail_on_unmatched_files: true
test-pypi-upload:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [test]
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v5
with:
name: Packages
path: dist
- name: Publish package to PyPI
continue-on-error: true
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
|