Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
- A new link at the bottom of the CHANGELOG for that header
5. `git push -u origin`
6. Once approved, merge the PR
7. `git checkout main && git pull && git tag {package}/v{version} && git push {package}/v{version}`
8. Github actions will automatically publish the release on tag push
9. Create a new [release](https://github.com/stapi-spec/pystapi/releases) pointing to the new tag
7. `git checkout main && git pull && scripts/release {package}`
8. Go to the draft release href provided by the script, update that Github release with information from the CHANGELOG, and publish it
9. Github actions will automatically publish a new PyPI release

> [!NOTE]
> The tag format (`{package}/v{version}`) is very important, because that's how we discover which package to build and publish.
> [!IMPORTANT]
> You'll need to set up [.netrc authentication](https://pygithub.readthedocs.io/en/stable/examples/Authentication.html#netrc-authentication) to use `scripts/release`.
> The tag format created by the script (`{package}/v{version}`) is very important, because that's how we discover which package to build and publish in Github Actions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dev = [
"pre-commit>=4.2.0",
"pre-commit-hooks>=5.0.0",
"fastapi[standard]>=0.115.12",
"pygithub>=2.6.1",
]
docs = [
"mkdocs-material>=9.6.11",
Expand Down
56 changes: 56 additions & 0 deletions scripts/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3

"""Create a new DRAFT release.

Usage:

scripts/release pystapi-client # or another package name

You'll need to set up netrc authentication as described in
https://pygithub.readthedocs.io/en/stable/examples/Authentication.html#netrc-authentication.
"""

import sys
from pathlib import Path

import tomllib
from github import Auth, Github

ALLOWED_PACKAGE_NAMES = ["pystapi-client", "pystapi-validator", "stapi-fastapi", "stapi-pydantic"]

if len(sys.argv) != 2:
print("ERROR: invalid usage", file=sys.stderr)
print(f"USAGE: {sys.argv[0]}", "{package_name}", file=sys.stderr)
sys.exit(1)

if sys.argv[1] not in ALLOWED_PACKAGE_NAMES:
print(f"ERROR: invalid package name: {sys.argv[1]}")
print(f"Allowed package names: {','.join(ALLOWED_PACKAGE_NAMES)}")
sys.exit(2)

package_name = sys.argv[1]

with open(Path(__file__).parents[1] / package_name / "pyproject.toml", "rb") as f:
pyproject_toml = tomllib.load(f)

version = pyproject_toml["project"]["version"]
tag = f"{package_name}/v{version}"

github = Github(auth=Auth.NetrcAuth())
print("Logged in as", github.get_user().login)
repo = github.get_repo("stapi-spec/pystapi")
print("Next release:", tag)
# TODO allow for releasing from not the main branch
target = repo.get_branch("main").commit.sha
print(f"Target sha (main): {target}")
git_release = repo.create_git_tag_and_release(
tag=tag,
tag_message=tag,
draft=True,
generate_release_notes=False,
release_name=tag,
release_message=(f"Release created via `scripts/release` by {github.get_user().login}."),
object=target,
type="commit",
)
print(f"Draft release created: {git_release.html_url}")
Loading