Skip to content

Commit e1e19dc

Browse files
committed
Add trusted publisher release workfiow
1 parent cdba22f commit e1e19dc

File tree

4 files changed

+27
-98
lines changed

4 files changed

+27
-98
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ jobs:
7878
7979
- run: pip install nox
8080
- run: nox -s prepare-release -- 99.9
81-
- run: nox -s build-release -- 99.9
81+
- run: git checkout 99.9
82+
- run: pipx run build
83+
- run: pipx run twine check dist/*
8284
- run: pipx run check-manifest
8385

8486
vendoring:

.github/workflows/release.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
on:
2+
push:
3+
tags:
4+
- "*"
5+
6+
name: release
7+
8+
jobs:
9+
pypi:
10+
name: upload release to PyPI
11+
runs-on: ubuntu-latest
12+
environment: release
13+
permissions:
14+
# Used to authenticate to PyPI via OIDC.
15+
id-token: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-python@v5
19+
- name: build
20+
run: pipx run build
21+
- name: publish
22+
uses: pypa/gh-action-pypi-publish@release/v1

docs/html/development/release-process.rst

+2-5
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,8 @@ Creating a new release
146146
This will update the relevant files and tag the correct commit.
147147
#. Submit the ``release/YY.N`` branch as a pull request and ensure CI passes.
148148
Merge the changes back into ``main`` and pull them back locally.
149-
#. Build the release artifacts using ``nox -s build-release -- YY.N``.
150-
This will checkout the tag, generate the distribution files to be
151-
uploaded and checkout the main branch again.
152-
#. Upload the release to PyPI using ``nox -s upload-release -- YY.N``.
153-
#. Push the tag created by ``prepare-release``.
149+
#. Push the tag created by ``prepare-release``. This will trigger the release
150+
workflow on GitHub and publish to PyPI.
154151
#. Regenerate the ``get-pip.py`` script in the `get-pip repository`_ (as
155152
documented there) and commit the results.
156153
#. Submit a Pull Request to `CPython`_ adding the new version of pip

noxfile.py

-92
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""
33

44
import argparse
5-
import glob
65
import os
76
import shutil
87
import sys
@@ -315,94 +314,3 @@ def prepare_release(session: nox.Session) -> None:
315314
next_dev_version = release.get_next_development_version(version)
316315
release.update_version_file(next_dev_version, VERSION_FILE)
317316
release.commit_file(session, VERSION_FILE, message="Bump for development")
318-
319-
320-
@nox.session(name="build-release")
321-
def build_release(session: nox.Session) -> None:
322-
version = release.get_version_from_arguments(session)
323-
if not version:
324-
session.error("Usage: nox -s build-release -- YY.N[.P]")
325-
326-
session.log("# Ensure no files in dist/")
327-
if release.have_files_in_folder("dist"):
328-
session.error(
329-
"There are files in dist/. Remove them and try again. "
330-
"You can use `git clean -fxdi -- dist` command to do this"
331-
)
332-
333-
session.log("# Install dependencies")
334-
session.install("build", "twine")
335-
336-
with release.isolated_temporary_checkout(session, version) as build_dir:
337-
session.log(
338-
"# Start the build in an isolated, "
339-
f"temporary Git checkout at {build_dir!s}",
340-
)
341-
with release.workdir(session, build_dir):
342-
tmp_dists = build_dists(session)
343-
344-
tmp_dist_paths = (build_dir / p for p in tmp_dists)
345-
session.log(f"# Copying dists from {build_dir}")
346-
os.makedirs("dist", exist_ok=True)
347-
for dist, final in zip(tmp_dist_paths, tmp_dists):
348-
session.log(f"# Copying {dist} to {final}")
349-
shutil.copy(dist, final)
350-
351-
352-
def build_dists(session: nox.Session) -> List[str]:
353-
"""Return dists with valid metadata."""
354-
session.log(
355-
"# Check if there's any Git-untracked files before building the wheel",
356-
)
357-
358-
has_forbidden_git_untracked_files = any(
359-
# Don't report the environment this session is running in
360-
not untracked_file.startswith(".nox/build-release/")
361-
for untracked_file in release.get_git_untracked_files()
362-
)
363-
if has_forbidden_git_untracked_files:
364-
session.error(
365-
"There are untracked files in the working directory. "
366-
"Remove them and try again",
367-
)
368-
369-
session.log("# Build distributions")
370-
session.run("python", "-m", "build", silent=True)
371-
produced_dists = glob.glob("dist/*")
372-
373-
session.log(f"# Verify distributions: {', '.join(produced_dists)}")
374-
session.run("twine", "check", *produced_dists, silent=True)
375-
376-
return produced_dists
377-
378-
379-
@nox.session(name="upload-release")
380-
def upload_release(session: nox.Session) -> None:
381-
version = release.get_version_from_arguments(session)
382-
if not version:
383-
session.error("Usage: nox -s upload-release -- YY.N[.P]")
384-
385-
session.log("# Install dependencies")
386-
session.install("twine")
387-
388-
distribution_files = glob.glob("dist/*")
389-
session.log(f"# Distribution files: {distribution_files}")
390-
391-
# Sanity check: Make sure there's 2 distribution files.
392-
count = len(distribution_files)
393-
if count != 2:
394-
session.error(
395-
f"Expected 2 distribution files for upload, got {count}. "
396-
f"Remove dist/ and run 'nox -s build-release -- {version}'"
397-
)
398-
# Sanity check: Make sure the files are correctly named.
399-
distfile_names = (os.path.basename(fn) for fn in distribution_files)
400-
expected_distribution_files = [
401-
f"pip-{version}-py3-none-any.whl",
402-
f"pip-{version}.tar.gz",
403-
]
404-
if sorted(distfile_names) != sorted(expected_distribution_files):
405-
session.error(f"Distribution files do not seem to be for {version} release.")
406-
407-
session.log("# Upload distributions")
408-
session.run("twine", "upload", *distribution_files)

0 commit comments

Comments
 (0)