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 161 162 163 164 165 166
|
name: CI
on:
push:
branches:
- master
tags:
- v*
pull_request:
workflow_dispatch:
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: pip install -U hatch
- name: Lint
run: hatch run style:lint
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
lychee:
name: Check URLs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Restore lychee cache
uses: actions/cache@v4
with:
path: .lycheecache
key: cache-lychee-${{ github.sha }}
restore-keys: cache-lychee-
- name: Run Lychee
uses: lycheeverse/lychee-action@v2
with:
args: --cache --max-cache-age 1d .
test:
name: Test
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
py:
- 3.9
- "3.10"
- "3.11"
- "3.12"
- "3.13"
platform:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python v${{ matrix.py }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.py }}
- name: Pick environment to run
id: env
shell: python
run: |
import codecs, os, sys
env = f"py=py3{sys.version_info[1]}\n"
sys.stdout.write(f"Picked {env.split('=')[1].strip()} for {sys.version}\n")
with codecs.open(os.environ["GITHUB_OUTPUT"], "a", "utf-8") as file_handler:
file_handler.write(env)
- name: Install dependencies
run: pip install -U hatch
- name: Run tests
run: |
hatch run +py=${{ steps.env.outputs.py }} tests:all
- name: Convert coverage to XML
run: |
pip install coverage covdefaults
coverage combine
coverage xml
- name: Upload coverage
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
build-dist:
if: startsWith(github.ref, 'refs/tags/')
needs:
- lint
- test
name: Build package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: "3.11"
- name: Install build dependencies
run: pip install -U hatch
- name: Build package
run: hatch build
- uses: actions/upload-artifact@v4
with:
path: dist/*
name: distribution
pypi-upload:
name: Upload to PyPI
needs: build-dist
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: distribution
path: dist
- uses: pypa/gh-action-pypi-publish@v1.13.0
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
# repository_url: https://test.pypi.org/legacy/
skip-existing: true
release:
name: Release
needs: build-dist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get tag metadata
id: tag
run: |
TAG_TITLE=${GITHUB_REF#refs/*/}
echo "title=$TAG_TITLE" >> $GITHUB_OUTPUT
git -c protocol.version=2 fetch --prune --progress \
--no-recurse-submodules origin \
+refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
TAG_BODY="$(git tag -l --format='%(contents)' $TAG_TITLE)"
TAG_BODY="${TAG_BODY//'%'/'%25'}"
TAG_BODY="${TAG_BODY//$'\n'/'%0A'}"
TAG_BODY="${TAG_BODY//$'\r'/'%0D'}"
echo "body=$TAG_BODY" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v2
id: create-release
with:
name: ${{ steps.tag.outputs.title }}
tag_name: ${{ steps.tag.outputs.title }}
body: ${{ steps.tag.outputs.body }}
draft: false
prerelease: false
- uses: actions/download-artifact@v4
name: Download builds
with:
name: distribution
path: dist
- uses: shogo82148/actions-upload-release-asset@v1
name: Upload release assets
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: dist/*
|