Skip to content

Commit

Permalink
refactor: Move common python code into a library.
Browse files Browse the repository at this point in the history
We'll use this for other scripts.
  • Loading branch information
iphydf committed Dec 30, 2024
1 parent 3f78c2b commit 2c7d65b
Show file tree
Hide file tree
Showing 19 changed files with 1,474 additions and 634 deletions.
475 changes: 0 additions & 475 deletions .ci-scripts/validate-pr.py

This file was deleted.

1 change: 0 additions & 1 deletion .clog.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
repository = "https://github.com/TokTok/qTox"
changelog = "CHANGELOG.md"
from-latest-tag = true
ignore-before = "v1.3.0"
forked-from = [
# Actually since 8632be2, but there's no release for that yet.
# TODO(iphydf): Change to 8632be2 after release.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
if: github.event_name == 'pull_request'
run: |
.ci-scripts/create-identity.sh
.ci-scripts/validate-pr.py --no-sign
tools/validate-pr.py --no-sign
verify-signatures:
name: Verify release asset signatures
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ _[Bb]uild*/
_obj
_test
libs
__pycache__

# Git
*.orig
Expand Down
398 changes: 398 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions MAINTAINING.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ candidates).

### Step 1. Create a release PR

Most of these steps are automated by [`.ci-scripts/validate-pr.py`], which you
Most of these steps are automated by [`tools/validate-pr.py`], which you
can run locally to automate the pre-tagging process.

- Merge any Weblate PRs if they are still open.
- Create a new release PR branch, e.g.: `git checkout -b 1.18.0-rc.3`.
- Create a new release PR branch, e.g.: `git checkout -b release/v1.18.0-rc.3`.

**Automated method:**

- Run `.ci-scripts/validate-pr.py`.
- Run `tools/validate-pr.py`.

**Manual method:**

Expand Down Expand Up @@ -255,7 +255,6 @@ Once you're confident about your knowledge and you've been around the project
helping for a while, ask to be added to the `TokTok` organization on GitHub.

[commit message format]: /CONTRIBUTING.md#commit-message-format
[`.ci-scripts/validate-pr.py`]: /.ci-scripts/validate-pr.py
[`CONTRIBUTING.md`]: /CONTRIBUTING.md
[`merge-pr.sh`]: /merge-pr.sh
[`test-pr.sh`]: /test-pr.sh
Expand All @@ -265,6 +264,7 @@ helping for a while, ask to be added to the `TokTok` organization on GitHub.
[`tools/update-nodes.sh`]: /tools/update-nodes.sh
[`tools/update-versions.sh`]: /tools/update-versions.sh
[`tools/format-code.sh`]: /tools/format-code.sh
[`tools/validate-pr.py`]: /tools/validate-pr.py
[Flathub repository]: https://github.com/flathub/io.github.qtox.qTox
[`flatpak/io.github.qtox.qTox.json`]: /flatpak/io.github.qtox.qTox.json
[`flatpak/update_flathub_descriptor_dependencies.py`]: /flatpak/update_flathub_descriptor_dependencies.py
Expand Down
9 changes: 6 additions & 3 deletions flatpak/update_flathub_descriptor_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def parse_args() -> argparse.Namespace:
qTox. This script will iterate over all known dependencies in the manifest
and replace their tags with the ones specified by our download_xxx.sh
scripts. The commit hash for the tag will be replaced with whatever is
currently in the git remote
currently in the git remote.
""")
parser.add_argument(
"--flathub-manifest",
Expand Down Expand Up @@ -122,6 +122,10 @@ def load_flathub_manifest(flathub_manifest_path: str) -> Any:


def commit_from_tag(url: str, tag: str) -> str:
if tag.startswith("release/"):
return (subprocess.check_output( # nosec
["git", "rev-parse", tag], ).decode().strip())

git_output = subprocess.run( # nosec
["git", "ls-remote", url, f"{tag}^{{}}"],
check=True,
Expand Down Expand Up @@ -161,10 +165,9 @@ def update_archive_source(

def update_git_source(module: dict[str, Any], tag: str) -> None:
module_source = module["sources"][0]
module_source["tag"] = tag
module_source["commit"] = commit_from_tag(
module_source["url"],
module_source["tag"],
tag,
)


Expand Down
41 changes: 5 additions & 36 deletions tools/create-tarballs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import subprocess # nosec
import tempfile
from dataclasses import dataclass
from functools import cache as memoize

import requests
from lib import git
from lib import github


@dataclass
Expand All @@ -30,43 +31,11 @@ def parse_args() -> Config:
parser.add_argument(
"--tag",
help="Tag to create tarballs for",
default=git_tag(),
default=git.current_tag(),
)
return Config(**vars(parser.parse_args()))


@memoize
def github_token() -> str:
token = os.getenv("GITHUB_TOKEN")
if not token:
raise ValueError("GITHUB_TOKEN is needed to upload tarballs")
return token


@memoize
def github_release_id(tag: str) -> str:
response = requests.get(
f"https://api.github.com/repos/TokTok/qTox/releases/tags/{tag}",
headers={
"Authorization": f"token {github_token()}",
},
)
response.raise_for_status()
return str(response.json()["id"])


def git_tag() -> str:
return (subprocess.check_output( # nosec
[
"git",
"describe",
"--tags",
"--abbrev=0",
"--match",
"v*",
]).decode("utf-8").strip())


def create_tarballs(tag: str, tmpdir: str) -> None:
"""Create source tarballs with both .gz and .xz for the given tag."""
for prog in ("gzip", "xz"):
Expand Down Expand Up @@ -114,10 +83,10 @@ def upload_tarballs(tag: str, tmpdir: str) -> None:
print(f"Uploading {filename} to GitHub release {tag}")
with open(os.path.join(tmpdir, filename), "rb") as f:
response = requests.post(
f"https://uploads.github.com/repos/TokTok/qTox/releases/{github_release_id(tag)}/assets",
f"https://uploads.github.com/repos/TokTok/qTox/releases/{github.release_id(tag)}/assets",
headers={
"Authorization": f"token {github_token()}",
"Content-Type": content_type[suffix or ext],
**github.auth_headers(required=True),
},
data=f,
params={"name": filename},
Expand Down
Empty file added tools/lib/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions tools/lib/changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright © 2024 The TokTok team
import re


def parse() -> dict[str, str]:
messages: dict[str, str] = {}

with open("CHANGELOG.md", "r") as f:
version = None
message: list[str] = []
for line in f.read().splitlines():
version_found = re.search(r"^##\s*(v[^ ]+)", line)
if version_found:
version = version_found.group(1)
continue
if version:
if line.startswith("####") or line.startswith("<a name="):
while message and not message[-1].strip():
message.pop()
while message and not message[0].strip():
message.pop(0)
messages[version] = "\n".join(message)
version = None
message = []
else:
message.append(line)

return messages


def get_message(version: str) -> str:
messages = parse()
return messages[version]
Loading

0 comments on commit 2c7d65b

Please sign in to comment.