Skip to content

Commit 21f173b

Browse files
korikuzmareece
andauthored
ci: update python-package workflow to use trusted publishing (#50)
* ci: update python-package workflow to use trusted publishing close #39 Additional changes: * Only run workflow when a tag is created * Update action versions + python version used * use cache * add back running on PR, build requires tag to be created * trivial change, mostly to try to tickle GH Actions --------- Co-authored-by: Reece Hart <[email protected]>
1 parent b71c7ba commit 21f173b

File tree

2 files changed

+53
-42
lines changed

2 files changed

+53
-42
lines changed

.github/workflows/python-package.yml

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
12
name: Python package
23

34
on:
@@ -11,17 +12,17 @@ jobs:
1112
runs-on: ubuntu-latest
1213

1314
steps:
14-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1516

1617
- uses: awalsh128/cache-apt-pkgs-action@latest
1718
with:
1819
packages: zsh
1920
version: 1.0
2021

2122
- name: Set up Python
22-
uses: actions/setup-python@v4
23+
uses: actions/setup-python@v5
2324
with:
24-
python-version: "3.10"
25+
python-version: "3.12"
2526
cache: pip
2627
cache-dependency-path: '**/pyproject.yaml'
2728

@@ -47,15 +48,15 @@ jobs:
4748
python-version: ["3.10", "3.11", "3.12"]
4849

4950
steps:
50-
- uses: actions/checkout@v3
51+
- uses: actions/checkout@v4
5152

5253
- uses: awalsh128/cache-apt-pkgs-action@latest
5354
with:
5455
packages: zsh
5556
version: 1.0
5657

5758
- name: Set up Python ${{ matrix.python-version }}
58-
uses: actions/setup-python@v4
59+
uses: actions/setup-python@v5
5960
with:
6061
python-version: ${{ matrix.python-version }}
6162
cache: pip
@@ -83,45 +84,51 @@ jobs:
8384
chmod +x codecov
8485
./codecov
8586
86-
deploy:
87+
build:
88+
name: Build distribution
89+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
90+
runs-on: ubuntu-latest
8791
needs:
8892
- cqa
8993
- test
94+
steps:
95+
- uses: actions/checkout@v4
96+
- name: Set up Python
97+
uses: actions/setup-python@v5
98+
with:
99+
python-version: "3.12"
100+
cache: pip
101+
cache-dependency-path: '**/setup.cfg'
102+
- name: Install pypa/build
103+
run: >-
104+
python3 -m
105+
pip install
106+
build
107+
--user
108+
- name: Build a binary wheel and a source tarball
109+
run: python3 -m build
110+
- name: Store the distribution packages
111+
uses: actions/upload-artifact@v4
112+
with:
113+
name: python-package-distributions
114+
path: dist/
115+
116+
publish-to-pypi:
117+
name: >-
118+
Publish Python distribution to PyPI
119+
needs:
120+
- build
90121
runs-on: ubuntu-latest
91-
122+
environment:
123+
name: pypi
124+
url: https://pypi.org/p/biocommons.example
125+
permissions:
126+
id-token: write # IMPORTANT: mandatory for trusted publishing
92127
steps:
93-
- name: Environment
94-
run: |
95-
echo "::group::Environment info"
96-
echo github.event_name = ${{ github.event_name }}
97-
echo refs = ${{ github.ref }}
98-
echo tags = ${{ startsWith(github.ref, 'refs/tags') }}
99-
echo "::endgroup::"
100-
101-
- uses: actions/checkout@v3
102-
103-
- uses: awalsh128/cache-apt-pkgs-action@latest
104-
with:
105-
packages: zsh
106-
version: 1.0
107-
108-
- name: Set up Python
109-
uses: actions/setup-python@v4
110-
with:
111-
python-version: "3.10"
112-
cache: pip
113-
cache-dependency-path: '**/setup.cfg'
114-
115-
- name: Install dependencies
116-
run: |
117-
python -m pip install --upgrade pip
118-
pip install build twine
119-
120-
- name: Build package
121-
run: python -m build
122-
123-
- name: Publish package
124-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
125-
uses: pypa/gh-action-pypi-publish@release/v1
126-
with:
127-
password: ${{ secrets.PYPI_API_TOKEN }}
128+
- name: Download all the dists
129+
uses: actions/download-artifact@v4
130+
with:
131+
name: python-package-distributions
132+
path: dist/
133+
- name: Publish distribution to PyPI
134+
uses: pypa/gh-action-pypi-publish@release/v1

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,7 @@ Try it:
7777

7878
* Quality tools: Code linting and reformatting with Ruff
7979
* GitHub Actions for testing and packaging
80+
81+
## ToDo
82+
83+
* Add devcontainer support

0 commit comments

Comments
 (0)