1212import tempfile
1313import textwrap
1414import time
15- import webbrowser
1615from pathlib import Path
1716
1817import nox
@@ -141,8 +140,40 @@ def release(session):
141140 next_version = f"{ major } .{ minor + 1 } .dev0"
142141 _bump (session , version = next_version , file = version_file , kind = "development" )
143142
144- # Checkout the git tag.
145- session .run ("git" , "checkout" , "-q" , release_version , external = True )
143+ # Push the commits and tag.
144+ # NOTE: The following fails if pushing to the branch is not allowed. This can
145+ # happen on GitHub, if the main branch is protected, there are required
146+ # CI checks and "Include administrators" is enabled on the protection.
147+ session .run ("git" , "push" , "upstream" , "main" , release_version , external = True )
148+
149+
150+ @nox .session
151+ def release_build (session ):
152+ package_name = "packaging"
153+
154+ # Parse version from command-line arguments, if provided, otherwise get
155+ # from Git tag.
156+ try :
157+ release_version = _get_version_from_arguments (session .posargs )
158+ except ValueError as e :
159+ if session .posargs :
160+ session .error (f"Invalid arguments: { e } " )
161+
162+ release_version = session .run (
163+ "git" , "describe" , "--exact-match" , silent = True , external = True
164+ )
165+ release_version = release_version .strip ()
166+ session .debug (f"version: { release_version } " )
167+ checkout = False
168+ else :
169+ checkout = True
170+
171+ # Check state of working directory and git.
172+ _check_working_directory_state (session )
173+
174+ # Checkout the git tag, if provided.
175+ if checkout :
176+ session .run ("git" , "checkout" , "-q" , release_version , external = True )
146177
147178 session .install ("build" , "twine" )
148179
@@ -162,24 +193,13 @@ def release(session):
162193 diff = "\n " .join (diff_generator )
163194 session .error (f"Got the wrong files:\n { diff } " )
164195
165- # Get back out into main.
166- session .run ("git" , "checkout" , "-q" , "main" , external = True )
196+ # Get back out into main, if we checked out before.
197+ if checkout :
198+ session .run ("git" , "checkout" , "-q" , "main" , external = True )
167199
168- # Check and upload distribution files.
200+ # Check distribution files.
169201 session .run ("twine" , "check" , * files )
170202
171- # Push the commits and tag.
172- # NOTE: The following fails if pushing to the branch is not allowed. This can
173- # happen on GitHub, if the main branch is protected, there are required
174- # CI checks and "Include administrators" is enabled on the protection.
175- session .run ("git" , "push" , "upstream" , "main" , release_version , external = True )
176-
177- # Upload the distribution.
178- session .run ("twine" , "upload" , * files )
179-
180- # Open up the GitHub release page.
181- webbrowser .open ("https://github.com/pypa/packaging/releases" )
182-
183203
184204@nox .session
185205def update_licenses (session : nox .Session ) -> None :
0 commit comments