Skip to content

Commit 3e0ebac

Browse files
authored
setup trusted publisher workflow (#12)
* setup trusted publisher workflow * skip windows and 3.13
1 parent f10cb0e commit 3e0ebac

File tree

2 files changed

+70
-29
lines changed

2 files changed

+70
-29
lines changed

.github/workflows/publish-pypi.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3-
41
name: Publish to PyPI
52

63
on:
@@ -10,14 +7,19 @@ on:
107
jobs:
118
build:
129
runs-on: ubuntu-latest
10+
permissions:
11+
id-token: write
12+
repository-projects: write
13+
contents: write
14+
pages: write
1315

1416
steps:
1517
- uses: actions/checkout@v4
1618

17-
- name: Set up Python 3.11
19+
- name: Set up Python 3.12
1820
uses: actions/setup-python@v5
1921
with:
20-
python-version: 3.11
22+
python-version: 3.12
2123

2224
- name: Install dependencies
2325
run: |
@@ -28,6 +30,14 @@ jobs:
2830
run: |
2931
tox
3032
33+
- name: Build Project and Publish
34+
run: |
35+
python -m tox -e clean,build
36+
37+
# This uses the trusted publisher workflow so no token is required.
38+
- name: Publish to PyPI
39+
uses: pypa/gh-action-pypi-publish@release/v1
40+
3141
- name: Build docs
3242
run: |
3343
tox -e docs
@@ -40,13 +50,3 @@ jobs:
4050
branch: gh-pages # The branch the action should deploy to.
4151
folder: ./docs/_build/html
4252
clean: true # Automatically remove deleted files from the deploy branch
43-
44-
- name: Build Project and Publish
45-
run: |
46-
python -m tox -e clean,build
47-
48-
- name: Publish package
49-
uses: pypa/gh-action-pypi-publish@v1.12.2
50-
with:
51-
user: __token__
52-
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/run-tests.yml

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,73 @@
1-
name: Run tests
1+
name: Test the library
22

33
on:
44
push:
5-
branches: [main]
5+
branches:
6+
- master # for legacy repos
7+
- main
68
pull_request:
9+
branches:
10+
- master # for legacy repos
11+
- main
12+
workflow_dispatch: # Allow manually triggering the workflow
13+
schedule:
14+
# Run roughly every 15 days at 00:00 UTC
15+
# (useful to check if updates on dependencies break the package)
16+
- cron: "0 0 1,16 * *"
17+
18+
permissions:
19+
contents: read
20+
21+
concurrency:
22+
group: >-
23+
${{ github.workflow }}-${{ github.ref_type }}-
24+
${{ github.event.pull_request.number || github.sha }}
25+
cancel-in-progress: true
726

827
jobs:
9-
build:
10-
runs-on: ubuntu-latest
28+
test:
1129
strategy:
1230
matrix:
13-
python-version: ["3.9", "3.10", "3.11", "3.12"]
14-
15-
name: Python ${{ matrix.python-version }}
31+
python: ["3.9", "3.10", "3.11", "3.12"]
32+
platform:
33+
- ubuntu-latest
34+
- macos-latest
35+
# - windows-latest
36+
runs-on: ${{ matrix.platform }}
37+
name: Python ${{ matrix.python }}, ${{ matrix.platform }}
1638
steps:
1739
- uses: actions/checkout@v4
1840

19-
- name: Setup Python
20-
uses: actions/setup-python@v5
41+
- uses: actions/setup-python@v5
42+
id: setup-python
2143
with:
22-
python-version: ${{ matrix.python-version }}
23-
cache: "pip"
44+
python-version: ${{ matrix.python }}
2445

2546
- name: Install dependencies
2647
run: |
2748
python -m pip install --upgrade pip
28-
pip install tox
49+
pip install tox coverage
2950
30-
- name: Test with tox
31-
run: |
51+
- name: Run tests
52+
run: >-
53+
pipx run --python '${{ steps.setup-python.outputs.python-path }}'
3254
tox
55+
-- -rFEx --durations 10 --color yes --cov --cov-branch --cov-report=xml # pytest args
56+
57+
- name: Check for codecov token availability
58+
id: codecov-check
59+
shell: bash
60+
run: |
61+
if [ ${{ secrets.CODECOV_TOKEN }} != '' ]; then
62+
echo "codecov=true" >> $GITHUB_OUTPUT;
63+
else
64+
echo "codecov=false" >> $GITHUB_OUTPUT;
65+
fi
66+
67+
- name: Upload coverage reports to Codecov with GitHub Action
68+
uses: codecov/codecov-action@v5
69+
if: ${{ steps.codecov-check.outputs.codecov == 'true' }}
70+
env:
71+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
72+
slug: ${{ github.repository }}
73+
flags: ${{ matrix.platform }} - py${{ matrix.python }}

0 commit comments

Comments
 (0)