1- name : Publish to PyPI.org
1+ name : Build, Test & Publish
2+
23on :
3- release :
4- types : [published]
4+ workflow_dispatch :
55 push :
6- branches : ["master"]
7- pull_request :
8- branches : ["master"]
6+ branches :
7+ - master
98
109jobs :
11- build_sdist :
12- name : Build source distribution
13- runs-on : ubuntu-latest
10+
11+ # Job 1: Build & Test with Pip
12+ build_and_test :
13+ runs-on : ${{ matrix.platform }}
14+ strategy :
15+ fail-fast : false
16+ matrix :
17+ platform : [windows-latest, macos-latest, ubuntu-latest, ubuntu-18.04, ubuntu-20.04]
18+ python-version : ["3.6", "3.8", "3.9", "3.10", "3.11" , "3.x"]
19+
1420 steps :
15- - uses : actions/checkout@v3
21+ - uses : actions/checkout@v4
22+
23+ - uses : actions/setup-python@v4
24+ with :
25+ python-version : ${{ matrix.python-version }}
1626
17- - name : Build sdist
18- run : pipx run build --sdist ${{github.workspace}}/
19- - name : Move sdist to dist
20- run : mkdir -p dist && mv ${{github.workspace}}/dist/*.tar.gz dist/
27+ - name : Install dependencies and package
28+ run : |
29+ python -m pip install pytest
30+ pip install --verbose .
2131
22- - uses : actions/upload-artifact@v3
23- with :
24- path : dist/*.tar.gz
32+ - name : Run tests
33+ run : python -m pytest
2534
26- cibuildwheel :
27- name : Build wheels on ${{ matrix.os }}
35+ # Job 2: Build SDist & Wheels and Publish to TestPyPI
36+ publish :
37+ needs : build_and_test
2838 runs-on : ${{ matrix.os }}
2939 strategy :
3040 matrix :
31- os : [ubuntu-20.04 , ubuntu-22 .04, windows-2022, macos-11 ]
41+ os : [windows-latest, macos-latest, ubuntu-latest , ubuntu-18 .04, ubuntu-20.04 ]
3242
3343 steps :
34- - uses : actions/checkout@v3
44+ - uses : actions/checkout@v4
3545
36- - name : Build test wheels (only PRs)
37- # if: github.event_name != 'release'
38- uses : pypa/cibuildwheel@v2.12.0
39- env : # build 1 build per platform just to make sure we can do it later when releasing
40- CIBW_BUILD : " cp312-*"
41- with :
42- package-dir : ${{github.workspace}}/
46+ - name : Set up Python
47+ uses : actions/setup-python@v4
4348
44- - name : Build all wheels
45- if : github.event_name == 'release'
46- uses : pypa/cibuildwheel@v2.12.0
47- with :
48- package-dir : ${{github.workspace}}/
49+ - name : Build SDist & Wheels
50+ run : |
51+ pip install build
52+ python -m build
4953
50- - uses : actions/upload-artifact@v3
51- with :
52- path : ./wheelhouse/*.whl
54+ - name : Check metadata
55+ run : |
56+ pip install twine
57+ twine check dist/*
5358
54- pypi-publish :
55- # if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
56- # if: github.event_name == 'release'
57- # needs: [cibuildwheel, build_sdist]
58- # runs-on: ubuntu-latest
59- # steps:
60- # - uses: actions/download-artifact@v3
61- # with:
62- # name: artifact
63- # path: dist
64-
65- # - uses: pypa/gh-action-pypi-publish@release/v1
66- # with:
67- # password: ${{ secrets.TEST_PYPI_API_TOKEN }}
68- name : Upload release to PyPI
69- runs-on : ubuntu-latest
70- environment :
71- name : pypi
72- url : https://test.pypi.org/p/dztimer
73- permissions :
74- id-token : write # IMPORTANT: this permission is mandatory for trusted publishing
75- steps :
76- - name : Publish package distributions to TestPyPI
77- uses : pypa/gh-action-pypi-publish@release/v1
78- with :
79- repository-url : https://test.pypi.org/legacy
59+ # - name: Publish to TestPyPI
60+ # if: github.ref == 'refs/heads/master' # Only if on master branch
61+ # run: |
62+ # pip install twine
63+ # twine upload --repository testpypi dist/* --skip-existing
64+ # env:
65+ # TWINE_USERNAME: __token__
66+ # TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
0 commit comments