Skip to content

Commit 1c2a6b2

Browse files
committed
Add gh-action for testing and publishing
1 parent b2c4b19 commit 1c2a6b2

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed

.github/workflows/ci.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: ${{ github.head_ref || github.run_id }}
14+
cancel-in-progress: true
15+
16+
env:
17+
FORCE_COLOR: "1" # Make tool output pretty.
18+
PIP_DISABLE_PIP_VERSION_CHECK: "1"
19+
PIP_PROGRESS_BAR: "off"
20+
21+
jobs:
22+
tests:
23+
name: Python ${{ matrix.python-version }}
24+
runs-on: ubuntu-latest
25+
26+
strategy:
27+
matrix:
28+
python-version:
29+
- '3.8'
30+
- '3.12'
31+
32+
steps:
33+
- uses: actions/checkout@v3
34+
35+
- uses: actions/setup-python@v4
36+
with:
37+
python-version: ${{ matrix.python-version }}
38+
39+
- name: Install dependencies
40+
run: |
41+
python -VV
42+
python -m pip install --upgrade pip wheel
43+
python -m pip install --upgrade .[tests]
44+
45+
- name: Run tests & collect coverage
46+
run: |
47+
python -m coverage run -p -m pytest
48+
49+
- name: Upload coverage data
50+
uses: actions/upload-artifact@v3
51+
with:
52+
name: coverage-data
53+
path: .coverage.*
54+
55+
coverage:
56+
name: Combine & check coverage
57+
needs: tests
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v3
61+
62+
- uses: actions/setup-python@v4
63+
with:
64+
python-version: '3.12'
65+
66+
- name: Install dependencies
67+
run: python -m pip install --upgrade coverage[toml]
68+
69+
- name: Download data
70+
uses: actions/download-artifact@v3
71+
with:
72+
name: coverage-data
73+
74+
- name: Combine coverage and fail if less than 100%
75+
run: |
76+
python -m coverage combine
77+
python -m coverage html --skip-empty --skip-covered
78+
# python -m coverage report --fail-under=100 # enable later
79+
80+
- name: Upload HTML report
81+
if: ${{ failure() }}
82+
uses: actions/upload-artifact@v3
83+
with:
84+
name: html-report
85+
path: .htmlcov

.github/workflows/pypi-publish.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Publish Python Package
2+
# Publishes to
3+
# - PyPI on releases created in GitHub UI
4+
# - TestPyPI on new tags "v1.2.3" or "v1.2.3.something" on main branch
5+
6+
on:
7+
push:
8+
tags:
9+
# GitHub glob matching is limited [1]. So we can't define a pattern matching
10+
# pep 440 version definition [N!]N(.N)*[{a|b|rc}N][.postN][.devN]
11+
- 'v[0-9]+.[0-9]+.[0-9]+.?*'
12+
release:
13+
types: [published]
14+
15+
jobs:
16+
build:
17+
name: Build Python 🐍 distributions 📦 for publishing
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3.1.0
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: 3.12
26+
27+
- name: Install hatch
28+
run: pipx install hatch
29+
30+
- name: Build source and wheel archives
31+
run: hatch build
32+
33+
- name: Store built distribution
34+
uses: actions/upload-artifact@v3
35+
with:
36+
name: distribution-files
37+
path: dist/
38+
39+
pypi-publish:
40+
name: Build and publish Python 🐍 package 📦 to PyPI and TestPyPI
41+
needs: build
42+
runs-on: ubuntu-latest
43+
environment:
44+
name: pypi-release
45+
url: https://pypi.org/p/ucumvert
46+
permissions:
47+
id-token: write # this permission is mandatory for trusted publishing
48+
steps:
49+
- name: Download built distribution
50+
uses: actions/download-artifact@v3
51+
with:
52+
name: distribution-files
53+
path: dist
54+
55+
# pinned version 1.8.10 [2]
56+
- name: Publish package 📦 to Test PyPI
57+
if: github.event_name == 'push'
58+
uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e
59+
with:
60+
repository-url: https://test.pypi.org/legacy/
61+
62+
- name: Publish package 📦 to PyPI
63+
if: github.event_name == 'release'
64+
uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e
65+
66+
# [1] https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
67+
# [2] https://github.com/pypa/gh-action-pypi-publish/

0 commit comments

Comments
 (0)