Skip to content

Commit d84b4e2

Browse files
committed
ci: simplify pypi publish workflow
1 parent 608a011 commit d84b4e2

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

.github/workflows/publish.yml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ jobs:
1414
publish:
1515
runs-on: ubuntu-latest
1616
environment: release
17-
env:
18-
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
1917
steps:
2018
- uses: actions/checkout@v4
2119

@@ -24,36 +22,25 @@ jobs:
2422
python-version: "3.11"
2523

2624
- name: Verify tag matches package version
25+
if: startsWith(github.ref, 'refs/tags/v')
2726
run: |
27+
TAG_VERSION="${GITHUB_REF_NAME#v}"
2828
PACKAGE_VERSION="$(python - <<'PY'
2929
import tomllib
30-
with open("pyproject.toml", "rb") as f:
30+
with open('pyproject.toml', 'rb') as f:
3131
data = tomllib.load(f)
32-
print(data["project"]["version"])
32+
print(data['project']['version'])
3333
PY
3434
)"
35-
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
36-
TAG_VERSION="${GITHUB_REF_NAME#v}"
37-
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
38-
echo "Tag version ($TAG_VERSION) does not match package version ($PACKAGE_VERSION)."
39-
exit 1
40-
fi
41-
else
42-
echo "Non-tag ref '${GITHUB_REF_NAME}', publishing package version ${PACKAGE_VERSION}."
35+
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
36+
echo "Tag version ($TAG_VERSION) does not match package version ($PACKAGE_VERSION)."
37+
exit 1
4338
fi
4439

4540
- name: Build distributions
4641
run: |
4742
python -m pip install -U pip build
4843
python -m build
4944
50-
- name: Publish to PyPI (API token)
51-
if: ${{ env.PYPI_API_TOKEN != '' }}
52-
uses: pypa/gh-action-pypi-publish@release/v1
53-
with:
54-
user: __token__
55-
password: ${{ env.PYPI_API_TOKEN }}
56-
57-
- name: Publish to PyPI (trusted publisher)
58-
if: ${{ env.PYPI_API_TOKEN == '' }}
45+
- name: Publish to PyPI
5946
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)