1212import tempfile
1313import textwrap
1414import time
15- import webbrowser
1615from pathlib import Path
1716
1817import nox
@@ -141,8 +140,48 @@ 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.
172+ _check_working_directory_state (session )
173+
174+ # Ensure there are no uncommitted changes.
175+ result = subprocess .run (
176+ ["git" , "status" , "--porcelain" ], capture_output = True , encoding = "utf-8"
177+ )
178+ if result .stdout :
179+ print (result .stdout , end = "" , file = sys .stderr )
180+ session .error ("The working tree has uncommitted changes" )
181+
182+ # Checkout the git tag, if provided.
183+ if checkout :
184+ session .run ("git" , "checkout" , "-q" , release_version , external = True )
146185
147186 session .install ("build" , "twine" )
148187
@@ -162,24 +201,13 @@ def release(session):
162201 diff = "\n " .join (diff_generator )
163202 session .error (f"Got the wrong files:\n { diff } " )
164203
165- # Get back out into main.
166- session .run ("git" , "checkout" , "-q" , "main" , external = True )
204+ # Get back out into main, if we checked out before.
205+ if checkout :
206+ session .run ("git" , "checkout" , "-q" , "main" , external = True )
167207
168- # Check and upload distribution files.
208+ # Check distribution files.
169209 session .run ("twine" , "check" , * files )
170210
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-
183211
184212@nox .session
185213def update_licenses (session : nox .Session ) -> None :
0 commit comments