Skip to content

Commit ff7213f

Browse files
committed
CCL-467: fix CI coverage target and make publishing tag-driven
CI has never measured anything: python.yml ran `pytest --cov={{packageName}}`, an unrendered Mustache template, so coverage reported "No data to report" while the job still exited 0. Point it at the real package. Publishing was driven by `release: published`, which decouples the artifact from the release name: run 29043124220 fired from the release tagged v4.21.1 but ran against ref v4.20.0 and published 4.20.0, so 4.21.1 never reached PyPI. Trigger on tag push instead, and fail the job when the tag does not match the version of the distribution actually built. Also bump the deprecated checkout@v3/setup-python@v3 actions and drop .travis.yml, which has never reported a commit status on this repository.
1 parent aa110b1 commit ff7213f

3 files changed

Lines changed: 81 additions & 41 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,80 @@
1+
# NOTE: This file is HAND-MAINTAINED in this repository and has no upstream
2+
# counterpart in CentML/platform. Keep the file name `publish.yml`: PyPI trusted
3+
# publishing (OIDC) is bound to the workflow file name, so renaming it breaks
4+
# publishing. See CCL-467.
5+
16
name: publish
27

8+
# Trigger on tag push rather than on `release: published`, so the tag itself is
9+
# what selects the code being published.
10+
#
11+
# Under the old trigger the published artifact came from whatever tag the GitHub
12+
# Release happened to target, which is decoupled from the release's name and can
13+
# be edited afterwards. That is how 4.21.1 was lost: run 29043124220 fired from
14+
# the release now titled "v4.21.11"/tagged v4.21.1, but ran against ref v4.20.0
15+
# and published 4.20.0. Seven tags never reached PyPI in total.
16+
#
17+
# Both tag spellings are matched on purpose: 4 of the 31 existing tags (3.2.5 -
18+
# 3.2.8) carry no `v` prefix, and a tag that matches no pattern here would fail
19+
# silently, which is the exact failure mode this workflow exists to remove.
320
on:
4-
release:
5-
types: [published]
21+
push:
22+
tags:
23+
- "v*"
24+
- "[0-9]*"
625

726
jobs:
827
publish:
928
runs-on: ubuntu-latest
29+
# Scopes the OIDC token and allows a manual approval gate to be configured
30+
# via required reviewers in the repository's environment settings.
31+
environment:
32+
name: pypi
33+
url: https://pypi.org/project/platform-api-python-client/
1034
permissions:
1135
id-token: write
36+
contents: read
1237
steps:
13-
- uses: actions/checkout@v3
14-
- name: setup-python
15-
uses: actions/setup-python@v3
38+
- uses: actions/checkout@v4
39+
40+
- uses: actions/setup-python@v5
1641
with:
1742
python-version: "3.11"
18-
architecture: "x64"
19-
- name: install pypa/build
20-
run: >-
21-
python -m
22-
pip install
23-
build
24-
--user
25-
- name: build sdist(tarball) and bdist(wheel) to dist/
26-
run: >- # = python -m build . works the same way by default
27-
python -m
28-
build
29-
--sdist
30-
--wheel
31-
--outdir dist/
32-
- name: publish to PyPI
43+
44+
- name: Install build tooling
45+
run: |
46+
python -m pip install --upgrade pip
47+
python -m pip install build twine
48+
49+
- name: Build sdist and wheel
50+
run: python -m build --sdist --wheel --outdir dist/
51+
52+
- name: Verify tag matches package version
53+
# Read the version from the built distribution rather than from
54+
# pyproject.toml. The project currently declares its version under
55+
# [tool.poetry] while building with the setuptools backend (which reads
56+
# setup.py), and CCL-470 will move it to a PEP 621 [project] table. The
57+
# built artifact is the single source of truth in all of those layouts.
58+
run: |
59+
set -euo pipefail
60+
TAG="${GITHUB_REF_NAME#v}"
61+
VERSION="$(python -c '
62+
import pathlib
63+
sdists = sorted(pathlib.Path("dist").glob("*.tar.gz"))
64+
if len(sdists) != 1:
65+
raise SystemExit(f"expected exactly one sdist, found {[p.name for p in sdists]}")
66+
print(sdists[0].name.removesuffix(".tar.gz").rsplit("-", 1)[1])
67+
')"
68+
echo "tag=$TAG built version=$VERSION"
69+
if [ "$TAG" != "$VERSION" ]; then
70+
echo "::error::tag $TAG does not match built package version $VERSION"
71+
exit 1
72+
fi
73+
74+
- name: Check distribution metadata
75+
run: python -m twine check --strict dist/*
76+
77+
- name: Publish to PyPI
3378
uses: pypa/gh-action-pypi-publish@release/v1
3479
with:
3580
repository-url: https://upload.pypi.org/legacy/

‎.github/workflows/python.yml‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
# NOTE: This file is auto generated by OpenAPI Generator.
2-
# URL: https://openapi-generator.tech
1+
# NOTE: This file is HAND-MAINTAINED in this repository. Do not treat it as
2+
# generated output, even though it originated from OpenAPI Generator.
3+
#
4+
# It intentionally diverges from the upstream copy at
5+
# CentML/platform:client/python/platform_api_python_client/.github/workflows/python.yml,
6+
# which still contains the unrendered `--cov={{packageName}}` template and a
7+
# Python 3.8 matrix entry.
8+
#
9+
# It survives `sync_client.yml` today only because that workflow's `rm -rf *`
10+
# and `cp -r .../*` globs skip dot-paths. CCL-468 proposes switching the copy to
11+
# `cp -r .../.`, which DOES copy dotfiles and would silently revert this file.
12+
# Before that lands, the upstream copies of `.github/workflows/python.yml` and
13+
# `.travis.yml` must be deleted from the platform repo and added to its
14+
# `.openapi-generator-ignore` (see CCL-467, CCL-468, CCL-470).
315
#
416
# ref: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
517

@@ -18,7 +30,7 @@ jobs:
1830
steps:
1931
- uses: actions/checkout@v4
2032
- name: Set up Python ${{ matrix.python-version }}
21-
uses: actions/setup-python@v4
33+
uses: actions/setup-python@v5
2234
with:
2335
python-version: ${{ matrix.python-version }}
2436
- name: Install dependencies
@@ -28,4 +40,4 @@ jobs:
2840
pip install -r test-requirements.txt
2941
- name: Test with pytest
3042
run: |
31-
pytest --cov={{packageName}}
43+
pytest --cov=platform_api_python_client

‎.travis.yml‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)