-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac0ed6d
commit 4a8babc
Showing
2 changed files
with
76 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
import shutil | ||
from pathlib import Path | ||
from typing import Mapping | ||
|
@@ -57,6 +59,34 @@ def pdoc(session: nox.Session): | |
) | ||
|
||
|
||
@nox.session | ||
def tag(session: nox.Session): | ||
session.install("hatch", "packaging") | ||
|
||
from packaging.version import Version | ||
|
||
message = "Automatic PEP 440 release tag" | ||
|
||
# validate some assumptions to make this simpler | ||
version = Version(run_silent(session, "hatch", "version")) | ||
assert version.epoch != 0 | ||
assert len(version.release) == 3 | ||
|
||
major, minor, _ = version.release | ||
tag = f"v{version.epoch}!{major}" | ||
|
||
# always update the prerelease tag, and also update the release tag if needed | ||
update_git_tag(session, tag=tag + ".dev", message=message) | ||
if version.dev is None: | ||
update_git_tag(session, tag=tag, message=message) | ||
|
||
tag += f".{minor}" | ||
|
||
update_git_tag(session, tag=tag + ".dev", message=message) | ||
if version.dev is None: | ||
update_git_tag(session, tag=tag, message=message) | ||
|
||
|
||
@nox.session | ||
def hexdoc(session: nox.Session): | ||
session.install(".") | ||
|
@@ -129,3 +159,18 @@ def run_silent( | |
) | ||
assert output | ||
return output.strip() | ||
|
||
|
||
def update_git_tag(session: nox.Session, *, tag: str, message: str): | ||
return session.run( | ||
"git", | ||
"tag", | ||
"-fam", | ||
message, | ||
tag, | ||
external=True, | ||
env=dict( | ||
GIT_COMMITTER_NAME="github-actions", | ||
GIT_COMMITTER_EMAIL="[email protected]", | ||
), | ||
) |