scripts: Clean up build_release
This commit is contained in:
parent
afa456f396
commit
0c2a673e27
3
.flake8
3
.flake8
|
|
@ -42,6 +42,7 @@ exclude = .*,__pycache__,resources.py
|
||||||
# W503: like break before binary operator
|
# W503: like break before binary operator
|
||||||
# W504: line break after binary operator
|
# W504: line break after binary operator
|
||||||
# FI18: __future__ import "annotations" missing
|
# FI18: __future__ import "annotations" missing
|
||||||
|
# FI58: __future__ import "annotations" present
|
||||||
# PT004: fixture '{name}' does not return anything, add leading underscore
|
# PT004: fixture '{name}' does not return anything, add leading underscore
|
||||||
# PT011: pytest.raises(ValueError) is too broad, set the match parameter or use a more specific exception
|
# PT011: pytest.raises(ValueError) is too broad, set the match parameter or use a more specific exception
|
||||||
# PT012: pytest.raises() block should contain a single simple statement
|
# PT012: pytest.raises() block should contain a single simple statement
|
||||||
|
|
@ -54,7 +55,7 @@ ignore =
|
||||||
D102,D103,D106,D107,D104,D105,D209,D211,D401,D402,D403,D412,D413,
|
D102,D103,D106,D107,D104,D105,D209,D211,D401,D402,D403,D412,D413,
|
||||||
A003,
|
A003,
|
||||||
W503, W504,
|
W503, W504,
|
||||||
FI18,
|
FI18,FI58,
|
||||||
PT004,
|
PT004,
|
||||||
PT011,
|
PT011,
|
||||||
PT012
|
PT012
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
"""Build a new release."""
|
"""Build a new release."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -21,7 +22,7 @@ import collections
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import re
|
import re
|
||||||
import http
|
import http
|
||||||
from typing import Optional
|
from typing import Optional, TYPE_CHECKING
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -29,6 +30,10 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
import github3
|
||||||
|
import github3.repos.release
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
REPO_ROOT = pathlib.Path(__file__).resolve().parents[2]
|
REPO_ROOT = pathlib.Path(__file__).resolve().parents[2]
|
||||||
|
|
@ -564,6 +569,30 @@ def read_github_token(
|
||||||
return token
|
return token
|
||||||
|
|
||||||
|
|
||||||
|
def _github_find_release(
|
||||||
|
gh: github3.GitHub, tag: str, experimental: bool
|
||||||
|
) -> github3.repos.release.Release:
|
||||||
|
if experimental:
|
||||||
|
repo = gh.repository('qutebrowser', 'experiments')
|
||||||
|
else:
|
||||||
|
repo = gh.repository('qutebrowser', 'qutebrowser')
|
||||||
|
assert repo is not None
|
||||||
|
|
||||||
|
for release in repo.releases():
|
||||||
|
if release.tag_name == tag:
|
||||||
|
return release
|
||||||
|
|
||||||
|
releases = ", ".join(r.tag_name for r in repo.releases())
|
||||||
|
raise Exception( # pylint: disable=broad-exception-raised
|
||||||
|
f"No release found for {tag!r} in {repo.full_name}, found: {releases}")
|
||||||
|
|
||||||
|
|
||||||
|
def _github_assets(
|
||||||
|
release: github3.repos.release.Release, artifact: Artifact
|
||||||
|
) -> list[github3.repos.release.Asset]:
|
||||||
|
return [asset for asset in release.assets() if asset.name == artifact.path.name]
|
||||||
|
|
||||||
|
|
||||||
def github_upload(
|
def github_upload(
|
||||||
artifacts: list[Artifact],
|
artifacts: list[Artifact],
|
||||||
tag: str,
|
tag: str,
|
||||||
|
|
@ -580,41 +609,23 @@ def github_upload(
|
||||||
experimental: Upload to the experiments repo
|
experimental: Upload to the experiments repo
|
||||||
skip_if_exists: Skip uploading artifacts that already exist
|
skip_if_exists: Skip uploading artifacts that already exist
|
||||||
"""
|
"""
|
||||||
# pylint: disable=broad-exception-raised
|
|
||||||
import github3
|
import github3
|
||||||
import github3.exceptions
|
import github3.exceptions
|
||||||
utils.print_title("Uploading to github...")
|
utils.print_title("Uploading to github...")
|
||||||
|
|
||||||
gh = github3.login(token=gh_token)
|
gh = github3.login(token=gh_token)
|
||||||
|
assert gh is not None
|
||||||
if experimental:
|
release = _github_find_release(gh=gh, tag=tag, experimental=experimental)
|
||||||
repo = gh.repository('qutebrowser', 'experiments')
|
|
||||||
else:
|
|
||||||
repo = gh.repository('qutebrowser', 'qutebrowser')
|
|
||||||
|
|
||||||
release = None # to satisfy pylint
|
|
||||||
for release in repo.releases():
|
|
||||||
if release.tag_name == tag:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
releases = ", ".join(r.tag_name for r in repo.releases())
|
|
||||||
raise Exception(
|
|
||||||
f"No release found for {tag!r} in {repo.full_name}, found: {releases}")
|
|
||||||
|
|
||||||
for artifact in artifacts:
|
for artifact in artifacts:
|
||||||
assets = [
|
if _github_assets(release, artifact) and skip_if_exists:
|
||||||
asset for asset in release.assets() if asset.name == artifact.path.name
|
|
||||||
]
|
|
||||||
if assets and skip_if_exists:
|
|
||||||
print(f"Artifact {artifact.path.name} already exists, skipping")
|
print(f"Artifact {artifact.path.name} already exists, skipping")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
print(f"Uploading {artifact.path}")
|
print(f"Uploading {artifact.path}")
|
||||||
|
|
||||||
assets = [asset for asset in release.assets()
|
if (assets := _github_assets(release, artifact)):
|
||||||
if asset.name == artifact.path.name]
|
|
||||||
if assets:
|
|
||||||
print(f"Assets already exist: {assets}")
|
print(f"Assets already exist: {assets}")
|
||||||
|
|
||||||
if utils.ON_CI:
|
if utils.ON_CI:
|
||||||
|
|
@ -642,9 +653,7 @@ def github_upload(
|
||||||
|
|
||||||
print("Retrying!")
|
print("Retrying!")
|
||||||
|
|
||||||
assets = [asset for asset in release.assets()
|
if (assets := _github_assets(release, artifact)):
|
||||||
if asset.name == artifact.path.name]
|
|
||||||
if assets:
|
|
||||||
stray_asset = assets[0]
|
stray_asset = assets[0]
|
||||||
print(f"Deleting stray asset {stray_asset.name}")
|
print(f"Deleting stray asset {stray_asset.name}")
|
||||||
stray_asset.delete()
|
stray_asset.delete()
|
||||||
|
|
@ -654,7 +663,9 @@ def github_upload(
|
||||||
|
|
||||||
def check_pypi_exists(version: str) -> bool:
|
def check_pypi_exists(version: str) -> bool:
|
||||||
"""Check whether the given version exists on PyPI."""
|
"""Check whether the given version exists on PyPI."""
|
||||||
response = requests.get(f"https://pypi.org/pypi/qutebrowser/{version}/json")
|
response = requests.get(
|
||||||
|
f"https://pypi.org/pypi/qutebrowser/{version}/json", timeout=30
|
||||||
|
)
|
||||||
if response.status_code == http.HTTPStatus.NOT_FOUND:
|
if response.status_code == http.HTTPStatus.NOT_FOUND:
|
||||||
return False
|
return False
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue