diff options
Diffstat (limited to '.github/scripts')
| -rwxr-xr-x | .github/scripts/build-fftw-macos.sh | 15 | ||||
| -rw-r--r-- | .github/scripts/generate-change-list.py | 154 | ||||
| -rwxr-xr-x | .github/scripts/generate-quick-downloads.py | 9 | ||||
| -rw-r--r-- | .github/scripts/tests/test_generate_change_list.py | 263 | ||||
| -rw-r--r-- | .github/scripts/tests/test_release_workflow_policy.py | 16 |
5 files changed, 452 insertions, 5 deletions
diff --git a/.github/scripts/build-fftw-macos.sh b/.github/scripts/build-fftw-macos.sh index cbaf0291..00c24a40 100755 --- a/.github/scripts/build-fftw-macos.sh +++ b/.github/scripts/build-fftw-macos.sh @@ -10,6 +10,20 @@ version="$1" deployment_target="$2" prefix="$3" +architecture="${ARCH:-$(uname -m)}" +case "$architecture" in + x86_64) + simd_flags=(--enable-sse2 --enable-avx) + ;; + arm64) + simd_flags=(--enable-neon) + ;; + *) + echo "Unsupported macOS architecture: $architecture" >&2 + exit 2 + ;; +esac + curl -L --fail --retry 5 --retry-delay 10 -o fftw.tar.gz "https://www.fftw.org/fftw-${version}.tar.gz" tar -xzf fftw.tar.gz cd "fftw-${version}" @@ -19,6 +33,7 @@ cd "fftw-${version}" --enable-single \ --enable-threads \ --enable-shared --disable-static \ + "${simd_flags[@]}" \ CFLAGS="-O3 -mmacosx-version-min=${deployment_target}" \ LDFLAGS="-mmacosx-version-min=${deployment_target}" make -j"$(sysctl -n hw.ncpu)" diff --git a/.github/scripts/generate-change-list.py b/.github/scripts/generate-change-list.py new file mode 100644 index 00000000..19a73db8 --- /dev/null +++ b/.github/scripts/generate-change-list.py @@ -0,0 +1,154 @@ +#!/usr/bin/env python3 +"""Print a GitHub Release change list from the commit subjects of a public release tag. + +Usage: + generate-change-list.py <owner/repo> <tag> + +Prints nothing when no earlier release tag exists. +""" +import importlib.util +import re +import subprocess +import sys +from pathlib import Path + + +def load_script(name, filename): + spec = importlib.util.spec_from_file_location(name, Path(__file__).with_name(filename)) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +policy = load_script("release_policy", "release-policy.py") + +SUBJECT_RE = re.compile( + r"^(?P<type>[A-Za-z]+)(?:\((?P<scope>[^)]*)\))?(?P<breaking>!)?:\s*(?P<description>\S.*)$" +) +SECTIONS = (("feat", "New features"), ("fix", "Fixes"), ("perf", "Performance")) +INTERNAL_SCOPES = frozenset(("release", "ci", "test", "tests")) +# Pull request numbers in subjects belong to the private repository; on the public +# release page they would link to unrelated items, and @names would notify people. +TRAILING_PR_RE = re.compile(r"\s*\(#\d+\)$") +REFERENCE_RE = re.compile(r"[\w.-]+/[\w.-]+#\d+|\bGH-\d+\b|(?<![\w/])[#@][\w-]+") + + +def git(*args): + return subprocess.run(["git", *args], check=True, capture_output=True, text=True).stdout + + +def release_tags(): + tags = {} + for name in git("tag", "--list", "v*").split(): + try: + tags[name] = policy.classify(name[1:]) + except ValueError: + continue + return tags + + +def range_of(tag): + """Return the tag the list starts from and the tags whose history is left out.""" + current = policy.classify(tag[1:]) + order = policy.release_order(current) + tags = release_tags() + earlier = {name: identity for name, identity in tags.items() if policy.release_order(identity) < order} + if current["channel"] == "GA": + earlier = {name: identity for name, identity in earlier.items() if identity["channel"] == "GA"} + if not earlier: + return None + newest = lambda names: max(names, key=lambda name: policy.release_order(tags[name])) + # Version order ranks an earlier tag of the same X.Y line above every older line's tags. + base = newest(earlier) + # Copies of shipped commits sit on the current and the newest older line. + lines = {current["release_branch"]} + older = [name for name in earlier if tags[name]["release_branch"] not in lines] + if older: + lines.add(tags[newest(older)]["release_branch"]) + scanned = sorted(name for name in earlier if tags[name]["release_branch"] in lines) + return base, sorted(earlier), scanned, sorted(set(earlier) - set(scanned)) + + +def patch_ids(*revisions): + """Map each non-merge commit with a non-empty diff to its stable patch ID.""" + log = subprocess.run(["git", "log", "--no-merges", "-p", *revisions], check=True, capture_output=True).stdout + ids = subprocess.run(["git", "patch-id", "--stable"], input=log, check=True, capture_output=True).stdout + return {commit: patch for patch, commit in (line.split() for line in ids.decode().splitlines())} + + +def plain(text): + text = REFERENCE_RE.sub(lambda match: f"`{match.group(0)}`", text) + return text.replace("<", "<") + + +def markdown(text): + if text.count("`") % 2: + return plain(text) + # Leave existing code spans alone. + parts = text.split("`") + return "`".join(part if index % 2 else plain(part) for index, part in enumerate(parts)) + + +def entry(match, author): + text = markdown(TRAILING_PR_RE.sub("", match.group("description"))) + scope = match.group("scope") + if scope: + text = f"{markdown(scope)}: {text}" + if match.group("breaking"): + text += " (breaking)" + return f"- {text} ({author})" + + +def change_list(repo, tag): + span = range_of(tag) + if span is None: + return "" + base, excluded, scanned, unscanned = span + candidates = patch_ids(tag, "--not", *excluded) + shipped = set(patch_ids(*scanned, "--not", *unscanned).values()) + log = git("log", "--reverse", "--no-merges", "--format=%H%x00%aN%x00%s", tag, "--not", *excluded) + sections = {kind: [] for kind, _ in SECTIONS} + other = 0 + for line in log.splitlines(): + commit, author, subject = line.split("\0", 2) + if candidates.get(commit) in shipped: + continue + match = SUBJECT_RE.match(subject) + kind = match.group("type").lower() if match else None + scopes = {part.strip().lower() for part in match.group("scope").split(",")} if match and match.group("scope") else set() + if kind not in sections or (scopes and scopes <= INTERNAL_SCOPES): + other += 1 + continue + item = entry(match, author) + if item not in sections[kind]: + sections[kind].append(item) + + comparison = f"https://github.com/{repo}/compare/{base}...{tag}" + out = [f"## Changes since {base}"] + for kind, title in SECTIONS: + if sections[kind]: + out += ["", f"### {title}", *sections[kind]] + out.append("") + listed = any(sections.values()) + commits = f"{other} other commit" + ("" if other == 1 else "s") + if other and listed: + out.append(f"Plus {commits}: [full comparison]({comparison}).") + elif other: + out.append(f"No user-facing changes; {commits}: [full comparison]({comparison}).") + elif listed: + out.append(f"[Full comparison]({comparison}).") + else: + out.append(f"No source changes since {base}.") + return "\n".join(out) + "\n" + + +def main(argv): + if len(argv) != 3: + sys.stderr.write("usage: generate-change-list.py <owner/repo> <tag>\n") + return 2 + sys.stdout.write(change_list(argv[1], argv[2])) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main(sys.argv)) diff --git a/.github/scripts/generate-quick-downloads.py b/.github/scripts/generate-quick-downloads.py index 0ba21c36..7a07c6f1 100755 --- a/.github/scripts/generate-quick-downloads.py +++ b/.github/scripts/generate-quick-downloads.py @@ -4,8 +4,7 @@ The release workflow attaches every build artifact to the Release, which makes the assets list long and hard for an end user to navigate (installers sit among the command-line program tarballs, checksums, the manifest, and source). This emits a -short, curated per-platform installer picker to prepend to the auto-generated -release notes. +short, curated per-platform installer picker to put above the change list. It is *asset-driven*: platforms and architectures are derived from the asset filenames passed in, not hard-coded. New build variants (for example an added @@ -13,7 +12,7 @@ Linux architecture such as armhf) therefore appear in Quick Downloads automatically, with no edit to this script. The block is emitted on stdout, ending at the last platform line (no trailing -separator); the caller joins it to the auto-generated notes. +separator); the caller joins it to the change list. Usage: generate-quick-downloads.py <owner/repo> <tag> <asset-path-or-name>... @@ -108,8 +107,8 @@ def main(argv): if source: out += ["", "### Source", f"- [{source}]({url(source)})"] - # If nothing matched (no installer-grade assets), emit nothing so the - # caller leaves the auto-generated notes untouched. + # If nothing matched (no installer-grade assets), emit nothing; the caller + # then publishes the change list alone. if len(out) == 4: return 0 diff --git a/.github/scripts/tests/test_generate_change_list.py b/.github/scripts/tests/test_generate_change_list.py new file mode 100644 index 00000000..6d2e707c --- /dev/null +++ b/.github/scripts/tests/test_generate_change_list.py @@ -0,0 +1,263 @@ +import os +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path + + +SCRIPT = Path(__file__).resolve().parents[1] / "generate-change-list.py" +REPO = "WSJTX/wsjtx" + + +class ChangeListTest(unittest.TestCase): + def setUp(self): + self.directory = tempfile.TemporaryDirectory() + self.addCleanup(self.directory.cleanup) + self.repo = Path(self.directory.name) + self.env = { + **{key: value for key, value in os.environ.items() if not key.startswith("GIT_")}, + "GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_NOSYSTEM": "1", + "GIT_AUTHOR_EMAIL": "author@example.com", + "GIT_COMMITTER_NAME": "Committer", "GIT_COMMITTER_EMAIL": "committer@example.com", + } + self.git("init", "-q", "-b", "develop") + # Background auto-maintenance would race the directory's removal. + self.git("config", "maintenance.auto", "false") + self.commit("chore: start") + + def stamp(self, author="Test Author"): + # Distinct dates, so a cherry-pick onto the same parent is a real copy. + self.clock = getattr(self, "clock", 0) + 1 + date = f"@{1_700_000_000 + self.clock} +0000" + return {**self.env, "GIT_AUTHOR_NAME": author, "GIT_AUTHOR_DATE": date, "GIT_COMMITTER_DATE": date} + + def git(self, *args): + return subprocess.run( + ["git", *args], cwd=self.repo, env=self.stamp(), text=True, capture_output=True, check=True, + ).stdout.strip() + + def commit(self, subject, author="Test Author", change=None): + # A distinct change per commit: git treats all empty commits as cherry-picks of each other. + self.changes = getattr(self, "changes", 0) + 1 + change = change or f"change-{self.changes}.txt" + (self.repo / change).write_text(subject + "\n") + self.git("add", change) + subprocess.run( + ["git", "commit", "-qm", subject], + cwd=self.repo, env=self.stamp(author), check=True, capture_output=True, + ) + return self.git("rev-parse", "HEAD") + + def merge(self, ref, subject): + self.git("merge", "--no-ff", "-qm", subject, ref) + + def notes(self, tag): + result = subprocess.run( + [sys.executable, str(SCRIPT), REPO, tag], + cwd=self.repo, env=self.env, text=True, capture_output=True, + ) + self.assertEqual(result.returncode, 0, result.stderr) + return result.stdout + + def test_a_later_beta_lists_the_changes_since_the_previous_beta_in_commit_order(self): + self.git("checkout", "-qb", "release/3.3") + self.commit("feat: old feature") + self.git("tag", "v3.3.0-beta1") + self.commit("feat(decoder): new mode", author="Joe Taylor") + self.commit("fix(wav): keep the dial context", author="David Christle") + self.commit("fix: a later fix") + self.git("tag", "v3.3.0-beta2") + notes = self.notes("v3.3.0-beta2") + self.assertTrue(notes.startswith("## Changes since v3.3.0-beta1\n")) + self.assertIn("### New features\n- decoder: new mode (Joe Taylor)\n", notes) + self.assertIn("### Fixes\n- wav: keep the dial context (David Christle)\n- a later fix (Test Author)\n", notes) + self.assertNotIn("old feature", notes) + self.assertIn(f"[Full comparison](https://github.com/{REPO}/compare/v3.3.0-beta1...v3.3.0-beta2).", notes) + + def test_a_spent_beta_number_falls_back_to_the_newest_published_tag(self): + self.git("checkout", "-qb", "release/3.3") + self.git("tag", "v3.3.0-beta1") + self.commit("fix: carried by the unpublished beta2") + self.commit("fix: new in beta3") + self.git("tag", "v3.3.0-beta3") + notes = self.notes("v3.3.0-beta3") + self.assertTrue(notes.startswith("## Changes since v3.3.0-beta1\n")) + self.assertIn("- carried by the unpublished beta2", notes) + self.assertIn("- new in beta3", notes) + + def test_a_release_candidate_follows_the_last_beta_of_its_line(self): + self.git("checkout", "-qb", "release/3.3") + self.git("tag", "v3.3.0-beta4") + self.commit("fix: freeze-time fix") + self.git("tag", "v3.3.0-rc1") + notes = self.notes("v3.3.0-rc1") + self.assertTrue(notes.startswith("## Changes since v3.3.0-beta4\n")) + self.assertIn("- freeze-time fix", notes) + + def test_a_lines_first_release_leaves_out_what_the_previous_line_shipped(self): + self.commit("feat: in 3.2 already") + self.git("tag", "v3.0.2") + self.git("checkout", "-qb", "release/3.0", "HEAD~1") + self.commit("fix: only on the old line") + self.git("tag", "v3.0.3") + self.git("checkout", "-q", "develop") + self.git("checkout", "-qb", "release/3.2") + self.commit("fix: only on release/3.2") + self.git("checkout", "-q", "develop") + picked = self.commit("fix(gui): picked into 3.2", change="gui.txt") + self.git("checkout", "-q", "release/3.2") + self.git("cherry-pick", picked) + self.git("tag", "v3.2.0-rc1") + self.git("checkout", "-q", "develop") + self.merge("v3.0.3", "Merge 3.0.3 into develop") + self.commit("feat: new on develop") + self.git("checkout", "-qb", "release/3.3") + self.commit("build(release): start 3.3 at BETA 1") + self.git("tag", "v3.3.0-beta1") + notes = self.notes("v3.3.0-beta1") + self.assertTrue(notes.startswith("## Changes since v3.2.0-rc1\n")) + self.assertIn("- new on develop", notes) + for shipped in ("in 3.2 already", "only on release/3.2", "picked into 3.2", "only on the old line"): + self.assertNotIn(shipped, notes) + self.assertIn(f"/compare/v3.2.0-rc1...v3.3.0-beta1", notes) + + def test_a_beta_after_the_previous_ga_is_merged_back_lists_only_new_changes(self): + self.git("checkout", "-qb", "release/3.2") + self.git("tag", "v3.2.0-rc1") + self.git("checkout", "-q", "develop") + original = self.commit("fix(gui): first on develop", change="gui.txt") + self.git("checkout", "-qb", "release/3.3") + self.git("tag", "v3.3.0-beta1") + self.git("checkout", "-q", "release/3.2") + self.git("cherry-pick", original) + self.commit("fix: only on release/3.2") + self.git("tag", "v3.2.0") + self.git("checkout", "-q", "develop") + self.merge("v3.2.0", "Merge 3.2.0 into develop") + self.commit("fix: new on develop") + self.git("checkout", "-q", "release/3.3") + self.merge("develop", "Merge develop into release/3.3") + self.git("tag", "v3.3.0-beta2") + notes = self.notes("v3.3.0-beta2") + self.assertTrue(notes.startswith("## Changes since v3.3.0-beta1\n")) + self.assertIn("### Fixes\n- new on develop (Test Author)\n\n", notes) + self.assertNotIn("first on develop", notes) + self.assertNotIn("only on release/3.2", notes) + + def test_copies_that_a_merged_back_ga_shipped_are_not_listed_again(self): + self.git("checkout", "-qb", "release/3.2") + self.commit("fix: on release/3.2 before the picks") + self.git("tag", "v3.2.0-rc1") + self.git("checkout", "-q", "develop") + self.git("checkout", "-qb", "release/3.3") + self.git("tag", "v3.3.0-beta1") + self.git("checkout", "-q", "develop") + original = self.commit("fix(gui): develop original shipped in 3.2.0", change="gui.txt") + self.git("checkout", "-q", "release/3.2") + self.git("cherry-pick", original) + port = self.commit("fix(cat): made on release/3.2 first", change="cat.txt") + self.git("tag", "v3.2.0") + self.git("checkout", "-q", "develop") + self.git("cherry-pick", port) + self.merge("v3.2.0", "Merge 3.2.0 into develop") + self.commit("fix: new on develop") + self.git("checkout", "-q", "release/3.3") + self.merge("develop", "Merge develop into release/3.3") + self.git("tag", "v3.3.0-beta2") + self.git("tag", "v3.3.0") + for tag in ("v3.3.0-beta2", "v3.3.0"): + notes = self.notes(tag) + self.assertIn("### Fixes\n- new on develop (Test Author)\n\n", notes, tag) + self.assertNotIn("develop original", notes, tag) + self.assertNotIn("made on release/3.2 first", notes, tag) + + def test_a_ga_lists_everything_since_the_previous_ga(self): + self.git("tag", "v3.2.0") + self.git("checkout", "-qb", "release/3.3") + self.commit("feat: from beta1") + self.git("tag", "v3.3.0-beta1") + self.commit("fix: from rc1") + self.git("tag", "v3.3.0-rc1") + self.commit("fix: from GA") + self.git("tag", "v3.3.0") + notes = self.notes("v3.3.0") + self.assertTrue(notes.startswith("## Changes since v3.2.0\n")) + for change in ("from beta1", "from rc1", "from GA"): + self.assertIn(change, notes) + self.commit("fix: patch") + self.git("tag", "v3.3.1-rc1") + self.git("tag", "v3.3.1") + patch = self.notes("v3.3.1") + self.assertTrue(patch.startswith("## Changes since v3.3.0\n")) + self.assertIn("- patch", patch) + self.assertNotIn("from GA", patch) + self.assertEqual(self.notes("v3.3.0"), notes) + + def test_entries_are_grouped_cleaned_and_counted(self): + self.git("tag", "v3.3.0-beta1") + self.commit("feat(jtty)!: change the macro syntax") + self.commit("Fix(gui): uppercase type (#458)") + self.commit("fix: address PR #569 review for @k1jt") + self.commit("perf(fft): use SIMD") + self.commit("fix(gui): uppercase type (#458)") + self.commit("fix(jtty, tests): user-facing despite a test scope") + self.commit("fix(release): pipeline change") + self.commit("feat(ci, tests): pipeline feature") + self.commit("test: cover the decoder") + self.commit("Untyped subject that mentions fix") + self.git("checkout", "-qb", "topic") + self.commit("docs: topic change") + self.git("checkout", "-q", "develop") + self.merge("topic", "Merge pull request #12 from topic") + self.git("tag", "v3.3.0-beta2") + notes = self.notes("v3.3.0-beta2") + self.assertIn("### New features\n- jtty: change the macro syntax (breaking) (Test Author)\n\n", notes) + self.assertIn( + "### Fixes\n" + "- gui: uppercase type (Test Author)\n" + "- address PR `#569` review for `@k1jt` (Test Author)\n" + "- jtty, tests: user-facing despite a test scope (Test Author)\n\n", + notes, + ) + self.assertIn("### Performance\n- fft: use SIMD (Test Author)\n", notes) + self.assertNotIn("pipeline", notes) + self.assertNotIn("Merge pull request", notes) + self.assertIn("Plus 5 other commits: [full comparison]", notes) + + def test_references_are_neutralized_outside_code_spans_only(self): + self.git("tag", "v3.3.0-beta1") + for subject in ( + "fix: mail ops@example.com about C# and see https://example.com/docs/#anchor", + "fix: link WSJTX/wsjtx-internal#569, GH-12 and Hamlib/Hamlib#1940", + "fix: keep `a #12 @b` and <CR> literal", + "fix(@team): scope reference", + "fix: handle a lone ` in macros, see #12 and @k1jt", + ): + self.commit(subject) + self.git("tag", "v3.3.0-beta2") + notes = self.notes("v3.3.0-beta2") + self.assertIn("- mail ops@example.com about C# and see https://example.com/docs/#anchor (Test Author)\n", notes) + self.assertIn("- link `WSJTX/wsjtx-internal#569`, `GH-12` and `Hamlib/Hamlib#1940` (Test Author)\n", notes) + self.assertIn("- keep `a #12 @b` and <CR> literal (Test Author)\n", notes) + self.assertIn("- `@team`: scope reference (Test Author)\n", notes) + self.assertIn("- handle a lone ` in macros, see `#12` and `@k1jt` (Test Author)\n", notes) + + def test_a_range_without_listed_changes_says_so(self): + self.git("tag", "v3.3.0-beta1") + self.commit("test: only tests") + self.git("tag", "v3.3.0-beta2") + self.assertIn("\nNo user-facing changes; 1 other commit: [full comparison]", self.notes("v3.3.0-beta2")) + self.git("tag", "v3.3.0-beta3") + notes = self.notes("v3.3.0-beta3") + self.assertTrue(notes.startswith("## Changes since v3.3.0-beta2\n")) + self.assertIn("No source changes since v3.3.0-beta2.", notes) + + def test_no_earlier_release_tag_prints_nothing(self): + for tag in ("not-a-release", "build/v3.2.0-rc1", "v3.2", "v3.2.0-alpha1", "v3.3.0-beta1"): + self.git("tag", tag) + self.assertEqual(self.notes("v3.3.0-beta1"), "") + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/scripts/tests/test_release_workflow_policy.py b/.github/scripts/tests/test_release_workflow_policy.py index 8765cbe1..68e8c23d 100644 --- a/.github/scripts/tests/test_release_workflow_policy.py +++ b/.github/scripts/tests/test_release_workflow_policy.py @@ -150,6 +150,22 @@ class ReleaseWorkflowPolicyTests(unittest.TestCase): self.assertEqual(len(re.findall(r"^\s+continue$", publish, re.M)), 1) self.assertEqual(publish.count('cmp "$file"'), 1) + def test_a_new_release_body_carries_the_change_list_or_keeps_the_generated_notes(self): + self.assertIn("fetch-depth: 0", job(PUBLIC, "publish")) + publish = step(PUBLIC, "Publish public GitHub Release") + self.assertIn("--generate-notes", publish) + notes = publish[publish.index('if [ "$CREATED" = true ]; then'):] + self.assertIn('CHANGES=$(python3 .github/scripts/generate-change-list.py \\\n' + ' "$GITHUB_REPOSITORY" "$GITHUB_REF_NAME" || true)', notes) + self.assertRegex(notes, r'if \[ -z "\$CHANGES" \]; then\s+echo "::warning::[^"]*"\s+' + r'CHANGES=\$\(gh release view "\$GITHUB_REF_NAME" --json body --jq \.body \|\| true\)') + # Notes never fail a publication, and a body without changes never replaces GitHub's notes. + edit = notes.index("gh release edit") + self.assertRegex(notes[:edit], r'if \[ -z "\$CHANGES" \]; then\s+echo "::warning::[^"]*"\s+else\s+NOTES=\$CHANGES\s') + self.assertRegex(notes[edit:], r'^gh release edit "\$GITHUB_REF_NAME" --notes-file "\$RUNNER_TEMP/release-notes.md" \\\n' + r'\s+\|\| echo "::warning::[^"]*"\n\s+fi\n') + self.assertEqual(notes.count("gh release edit"), 1) + def test_windows_signing_guard_admits_only_rc_and_ga(self): guard = step(SIGN, "Require a public RC or GA invocation") self.assertIn('test "$(jq -r .channel <<<"$IDENTITY")" = "$CHANNEL"', guard) |
