Skip to content

Commit eade96a

Browse files
committed
Publish package via PyPI trusted publisher in CI
1 parent 09dd99c commit eade96a

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

.github/workflows/main.yml

+34-24
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,33 @@ on: [push, pull_request]
55
env:
66
PYTEST_ADDOPTS: "--color=yes"
77

8+
permissions:
9+
contents: read
10+
811
jobs:
912
test:
10-
name: Test - ${{ matrix.python-version }}
13+
name: Test - Python ${{ matrix.python-version }}
1114
runs-on: ubuntu-latest
1215
strategy:
1316
matrix:
14-
python-version: ["3.8", "3.9", "3.10", "3.11"]
17+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1518

1619
steps:
17-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
1821
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v4
22+
uses: actions/setup-python@v5
2023
with:
2124
python-version: ${{ matrix.python-version }}
2225
- name: Set up Pip cache
23-
uses: actions/cache@v3
26+
uses: actions/cache@v4
2427
id: pip-cache
2528
with:
2629
path: ~/.cache/pip
2730
key: pip-${{ hashFiles('**/pyproject.toml') }}
2831
- name: Install Poetry
2932
run: python -m pip install poetry
3033
- name: Set up Poetry cache
31-
uses: actions/cache@v3
34+
uses: actions/cache@v4
3235
id: poetry-cache
3336
with:
3437
path: ~/.cache/pypoetry/virtualenvs
@@ -44,17 +47,17 @@ jobs:
4447
runs-on: ubuntu-latest
4548

4649
steps:
47-
- uses: actions/checkout@v3
50+
- uses: actions/checkout@v4
4851
- name: Validate links in Markdown files
4952
uses: JustinBeckwith/linkinator-action@v1
5053
with:
5154
retry: true
5255
- name: Set up Python
53-
uses: actions/setup-python@v4
56+
uses: actions/setup-python@v5
5457
with:
55-
python-version: "3.9"
58+
python-version: "3.10"
5659
- name: Set Poetry cache
57-
uses: actions/cache@v3
60+
uses: actions/cache@v4
5861
id: poetry-cache
5962
with:
6063
path: ~/.cache/pypoetry/virtualenvs
@@ -72,29 +75,36 @@ jobs:
7275
environment: Deployment
7376
needs: [test, lint]
7477
runs-on: ubuntu-latest
75-
if: ${{ github.ref=='refs/heads/main' && github.event_name!='pull_request' }}
78+
if: github.ref=='refs/heads/main' && github.event_name!='pull_request'
79+
80+
permissions:
81+
contents: write
82+
id-token: write
7683

7784
steps:
78-
- uses: actions/checkout@v3
79-
- name: Setup Python
80-
uses: actions/setup-python@v4
85+
- uses: actions/checkout@v4
86+
87+
- name: Set up Python
88+
uses: actions/setup-python@v5
8189
with:
82-
python-version: "3.9"
90+
python-version: "3.10"
91+
8392
- name: Check release
8493
id: check_release
8594
run: |
86-
python -m pip install --upgrade pip
87-
python -m pip install poetry githubrelease httpx==0.16.1 autopub
88-
echo "##[set-output name=release;]$(autopub check)"
95+
python -m pip install autopub[github]
96+
autopub check
97+
8998
- name: Publish
90-
if: ${{ steps.check_release.outputs.release=='' }}
99+
if: ${{ steps.check_release.outputs.autopub_release=='true' }}
91100
env:
92-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
93-
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
101+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94102
run: |
95-
git remote set-url origin https://[email protected]/${{ github.repository }}
96103
autopub prepare
97-
poetry build
98104
autopub commit
105+
autopub build
99106
autopub githubrelease
100-
poetry publish -u __token__ -p $PYPI_PASSWORD
107+
108+
- name: Upload package to PyPI
109+
if: ${{ steps.check_release.outputs.autopub_release=='true' }}
110+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)