Skip to content

Commit 325fafa

Browse files
committed
CI: Publish each master commit with a unique version on TestPyPI
This follows commit 7d52df7 "CI: Ignore version duplicates when publishing to TestPyPI" with a better design: - Only publish builds from `master` branch on TestPyPI. - Version every non-tag commit with a `.devN` suffix, e.g. `1.36.2.dev1`. This prevents duplicates on TestPyPI. - `twine check` built packages. See discussion at #721 (comment) for more details.
1 parent cd96692 commit 325fafa

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

.github/workflows/publish.yaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,29 @@ jobs:
88
build:
99
name: Build distribution package
1010
runs-on: ubuntu-latest
11-
1211
steps:
1312
- uses: actions/checkout@v4
1413
with:
1514
persist-credentials: false
15+
- name: Fetch tags
16+
if: github.ref_type != 'tag'
17+
run: git fetch --prune --unshallow --tags
1618
- name: Set up Python
1719
uses: actions/setup-python@v5
1820
with:
1921
python-version: "3.x"
2022
- name: Install pypa/build
21-
run: python -m pip install --user build
23+
run: python -m pip install build twine
24+
- name: Add '.devN' to version for non-tag builds
25+
if: github.ref_type != 'tag'
26+
run:
27+
sed -i
28+
"/^APP_VERSION = /s/'$/.dev$(git describe --tags | cut -d- -f2)'/"
29+
yamllint/__init__.py
2230
- name: Build a binary wheel and a source tarball
2331
run: python -m build
32+
- name: Twine check the distribution packages
33+
run: python -Im twine check --strict dist/yamllint-*
2434
- name: Store the distribution packages
2535
uses: actions/upload-artifact@v4
2636
with:
@@ -29,6 +39,7 @@ jobs:
2939

3040
publish-to-testpypi:
3141
name: Publish distribution package to TestPyPI
42+
if: github.ref_name == github.event.repository.default_branch
3243
needs: build
3344
runs-on: ubuntu-latest
3445
environment:
@@ -46,11 +57,10 @@ jobs:
4657
uses: pypa/gh-action-pypi-publish@release/v1
4758
with:
4859
repository-url: https://test.pypi.org/legacy/
49-
skip-existing: true
5060

5161
publish-to-pypi:
5262
name: Publish distribution package to PyPI
53-
if: startsWith(github.ref, 'refs/tags/') # only for tags
63+
if: github.ref_type == 'tag'
5464
needs: build
5565
runs-on: ubuntu-latest
5666
environment:

0 commit comments

Comments
 (0)