summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2023-08-16 11:59:46 +0200
committerFlorian Bruhin <me@the-compiler.org>2023-08-17 12:35:53 +0200
commit950d06ad5b54abfc3f0d4dffb6b4b890b029e9e8 (patch)
treec2ecd154b61fbbd89a2210c5de25c357070efe45 /scripts
parentd7b33759e537a759fb4cf90adfcc98f1a3ec7626 (diff)
downloadqutebrowser-950d06ad5b54abfc3f0d4dffb6b4b890b029e9e8.tar.gz
qutebrowser-950d06ad5b54abfc3f0d4dffb6b4b890b029e9e8.zip
ci: Initial automatic release support
See #3725
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/dev/build_release.py29
-rw-r--r--scripts/dev/update_version.py64
2 files changed, 69 insertions, 24 deletions
diff --git a/scripts/dev/build_release.py b/scripts/dev/build_release.py
index 55b3f5f1c..2038a7f67 100755
--- a/scripts/dev/build_release.py
+++ b/scripts/dev/build_release.py
@@ -544,13 +544,19 @@ def read_github_token(
return token
-def github_upload(artifacts: List[Artifact], tag: str, gh_token: str) -> None:
+def github_upload(
+ artifacts: List[Artifact],
+ tag: str,
+ gh_token: str,
+ experimental: bool,
+) -> None:
"""Upload the given artifacts to GitHub.
Args:
artifacts: A list of Artifacts to upload.
tag: The name of the release tag
gh_token: The GitHub token to use
+ experimental: Upload to the experiments repo
"""
# pylint: disable=broad-exception-raised
import github3
@@ -558,7 +564,11 @@ def github_upload(artifacts: List[Artifact], tag: str, gh_token: str) -> None:
utils.print_title("Uploading to github...")
gh = github3.login(token=gh_token)
- repo = gh.repository('qutebrowser', 'qutebrowser')
+
+ if experimental:
+ repo = gh.repository('qutebrowser', 'experiments')
+ else:
+ repo = gh.repository('qutebrowser', 'qutebrowser')
release = None # to satisfy pylint
for release in repo.releases():
@@ -602,10 +612,13 @@ def github_upload(artifacts: List[Artifact], tag: str, gh_token: str) -> None:
break
-def pypi_upload(artifacts: List[Artifact]) -> None:
+def pypi_upload(artifacts: List[Artifact], experimental: bool) -> None:
"""Upload the given artifacts to PyPI using twine."""
utils.print_title("Uploading to PyPI...")
- run_twine('upload', artifacts)
+ if experimental:
+ run_twine('upload', artifacts, "-r", "testpypi")
+ else:
+ run_twine('upload', artifacts)
def twine_check(artifacts: List[Artifact]) -> None:
@@ -635,6 +648,8 @@ def main() -> None:
help="Build a debug build.")
parser.add_argument('--qt5', action='store_true', required=False,
help="Build against PyQt5")
+ parser.add_argument('--experimental', action='store_true', required=False,
+ help="Upload to experiments repo and test PyPI")
args = parser.parse_args()
utils.change_cwd()
@@ -647,6 +662,7 @@ def main() -> None:
gh_token = read_github_token(args.gh_token)
else:
gh_token = read_github_token(args.gh_token, optional=True)
+ assert not args.experimental # makes no sense without upload
if not misc_checks.check_git():
utils.print_error("Refusing to do a release with a dirty git tree")
@@ -685,9 +701,10 @@ def main() -> None:
input()
assert gh_token is not None
- github_upload(artifacts, version_tag, gh_token=gh_token)
+ github_upload(
+ artifacts, version_tag, gh_token=gh_token, experimental=args.experimental)
if upload_to_pypi:
- pypi_upload(artifacts)
+ pypi_upload(artifacts, experimental=args.experimental)
else:
print()
utils.print_title("Artifacts")
diff --git a/scripts/dev/update_version.py b/scripts/dev/update_version.py
index ec1550414..c67873496 100644
--- a/scripts/dev/update_version.py
+++ b/scripts/dev/update_version.py
@@ -8,6 +8,7 @@
"""Update version numbers using bump2version."""
+import re
import sys
import argparse
import os.path
@@ -19,6 +20,24 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir,
from scripts import utils
+class Error(Exception):
+ """Base class for exceptions in this module."""
+
+
+def verify_branch(version_leap):
+ """Check that we're on the correct git branch."""
+ proc = subprocess.run(
+ ['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
+ check=True, capture_output=True, text=True)
+ branch = proc.stdout.strip()
+
+ if (
+ version_leap == 'patch' and not re.fullmatch(r'v\d+\.\d+\.\*', branch) or
+ version_leap != 'patch' and branch != 'main'
+ ):
+ raise Error(f"Invalid branch for {version_leap} release: {branch}")
+
+
def bump_version(version_leap="patch"):
"""Update qutebrowser release version.
@@ -46,6 +65,7 @@ if __name__ == "__main__":
utils.change_cwd()
if not args.commands:
+ verify_branch(args.bump)
bump_version(args.bump)
show_commit()
@@ -54,22 +74,30 @@ if __name__ == "__main__":
x_version = '.'.join([str(p) for p in qutebrowser.__version_info__[:-1]] +
['x'])
- print("Run the following commands to create a new release:")
- print("* git push origin; git push origin v{v}".format(v=version))
- if args.bump == 'patch':
- print("* git checkout main && git cherry-pick v{v} && "
- "git push origin".format(v=version))
+ if utils.ON_CI:
+ output_file = os.environ["GITHUB_OUTPUT"]
+ with open(output_file, "w", encoding="ascii") as f:
+ f.write(f"version={version}\n")
+ f.write(f"x_version={x_version}\n")
+
+ print(f"Outputs for {version} written to GitHub Actions output file")
else:
- print("* git branch v{x} v{v} && git push --set-upstream origin v{x}"
- .format(v=version, x=x_version))
- print("* Create new release via GitHub (required to upload release "
- "artifacts)")
- print("* Linux: git fetch && git checkout v{v} && "
- "tox -e build-release -- --upload"
- .format(v=version))
- print("* Windows: git fetch; git checkout v{v}; "
- "py -3.9 -m tox -e build-release -- --upload"
- .format(v=version))
- print("* macOS: git fetch && git checkout v{v} && "
- "tox -e build-release -- --upload"
- .format(v=version))
+ print("Run the following commands to create a new release:")
+ print("* git push origin; git push origin v{v}".format(v=version))
+ if args.bump == 'patch':
+ print("* git checkout main && git cherry-pick v{v} && "
+ "git push origin".format(v=version))
+ else:
+ print("* git branch v{x} v{v} && git push --set-upstream origin v{x}"
+ .format(v=version, x=x_version))
+ print("* Create new release via GitHub (required to upload release "
+ "artifacts)")
+ print("* Linux: git fetch && git checkout v{v} && "
+ "tox -e build-release -- --upload"
+ .format(v=version))
+ print("* Windows: git fetch; git checkout v{v}; "
+ "py -3.9 -m tox -e build-release -- --upload"
+ .format(v=version))
+ print("* macOS: git fetch && git checkout v{v} && "
+ "tox -e build-release -- --upload"
+ .format(v=version))