From eb1cd0c9bbb84122269a41ae6b40bd9c379c993c Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 26 Mar 2024 18:32:25 +0100 Subject: [PATCH] build: replace changelog-d with local script hacking changelog-d to support not just github but also forgejo and gerrit is a lot more complicated than it's worth, even moreso since the entire thing can just as well be done with ~60 lines of python. this new script is also much cheaper to instantiate (being python), so having it enabled in all shells is far less of a hassle. we've also adjusted existing release notes that referenced a gerrit cl to auto-link to the cl in question, making the diff a bit bigger closes https://git.lix.systems/lix-project/lix/issues/176 Change-Id: I8ba7dd0070aad9ba4474401731215fcf5d9d2130 --- doc/manual/local.mk | 4 +- doc/manual/rl-next/config | 2 - doc/manual/rl-next/dup-attr-errors.md | 2 +- doc/manual/rl-next/nixversion-fake.md | 2 +- doc/manual/rl-next/short-expr-flag.md | 2 +- doc/manual/rl-next/upstart-removal.md | 2 +- doc/manual/src/contributing/hacking.md | 3 -- flake.nix | 7 +-- maintainers/build-release-notes.nix | 6 +++ maintainers/build-release-notes.py | 66 ++++++++++++++++++++++++++ maintainers/release-notes | 2 +- misc/changelog-d.cabal.nix | 31 ------------ misc/changelog-d.nix | 31 ------------ package.nix | 4 +- 14 files changed, 85 insertions(+), 79 deletions(-) delete mode 100644 doc/manual/rl-next/config create mode 100644 maintainers/build-release-notes.nix create mode 100755 maintainers/build-release-notes.py delete mode 100644 misc/changelog-d.cabal.nix delete mode 100644 misc/changelog-d.nix diff --git a/doc/manual/local.mk b/doc/manual/local.mk index b9e7b8398..b33a4f777 100644 --- a/doc/manual/local.mk +++ b/doc/manual/local.mk @@ -151,9 +151,9 @@ $(d)/language.json: $(doc_nix) # Generate "Upcoming release" notes (or clear it and remove from menu) $(d)/src/release-notes/rl-next.md: $(d)/rl-next $(d)/rl-next/* - @if type -p changelog-d > /dev/null; then \ + @if type -p build-release-notes > /dev/null; then \ echo " GEN " $@; \ - changelog-d doc/manual/rl-next > $@; \ + build-release-notes doc/manual/rl-next > $@; \ else \ echo " NULL " $@; \ true > $@; \ diff --git a/doc/manual/rl-next/config b/doc/manual/rl-next/config deleted file mode 100644 index b3c2e868f..000000000 --- a/doc/manual/rl-next/config +++ /dev/null @@ -1,2 +0,0 @@ -organization: NixOS -repository: nix diff --git a/doc/manual/rl-next/dup-attr-errors.md b/doc/manual/rl-next/dup-attr-errors.md index 127c8ceb1..cce3d9f30 100644 --- a/doc/manual/rl-next/dup-attr-errors.md +++ b/doc/manual/rl-next/dup-attr-errors.md @@ -1,6 +1,6 @@ --- synopsis: Duplicate attribute reports are more accurate -# prs: cl 557 +cls: 557 --- Duplicate attribute errors are now more accurate, showing the path at which an error was detected rather than the full, possibly longer, path that caused the error. diff --git a/doc/manual/rl-next/nixversion-fake.md b/doc/manual/rl-next/nixversion-fake.md index 1a97e412c..6e42b2bd2 100644 --- a/doc/manual/rl-next/nixversion-fake.md +++ b/doc/manual/rl-next/nixversion-fake.md @@ -1,6 +1,6 @@ --- synopsis: "`builtins.nixVersion` now returns a fixed value \"2.18.3-lix\"" -# prs: cl 558 +cls: 558 --- `builtins.nixVersion` now returns a fixed value `"2.18.3-lix"`. This prevents diff --git a/doc/manual/rl-next/short-expr-flag.md b/doc/manual/rl-next/short-expr-flag.md index a02c944bd..5fddd3a25 100644 --- a/doc/manual/rl-next/short-expr-flag.md +++ b/doc/manual/rl-next/short-expr-flag.md @@ -1,6 +1,6 @@ --- synopsis: reintroduce shortened `-E` form for `--expr` to new CLI -# prs: cl 605 +cls: 605 --- In the past, it was possible to supply a shorter `-E` flag instead of fully diff --git a/doc/manual/rl-next/upstart-removal.md b/doc/manual/rl-next/upstart-removal.md index faec2264a..b1b7ad176 100644 --- a/doc/manual/rl-next/upstart-removal.md +++ b/doc/manual/rl-next/upstart-removal.md @@ -1,6 +1,6 @@ --- synopsis: Upstart scripts removed -# prs: cl 574 +cls: 574 --- Upstart scripts have been removed from Lix, since Upstart is obsolete and has diff --git a/doc/manual/src/contributing/hacking.md b/doc/manual/src/contributing/hacking.md index 3693361bb..133a61b5c 100644 --- a/doc/manual/src/contributing/hacking.md +++ b/doc/manual/src/contributing/hacking.md @@ -340,9 +340,6 @@ Significant changes should add the following header, which moves them to the top significance: significant ``` - -See also the [format documentation](https://github.com/haskell/cabal/blob/master/CONTRIBUTING.md#changelog). - ### Build process Releases have a precomputed `rl-MAJOR.MINOR.md`, and no `rl-next.md`. diff --git a/flake.nix b/flake.nix index 21d6de9e8..eab714f99 100644 --- a/flake.nix +++ b/flake.nix @@ -150,7 +150,8 @@ # Forward from the previous stage as we don’t want it to pick the lowdown override nixUnstable = prev.nixUnstable; - changelog-d = final.buildPackages.callPackage ./misc/changelog-d.nix { }; + build-release-notes = + final.buildPackages.callPackage ./maintainers/build-release-notes.nix { }; boehmgc-nix = (final.boehmgc.override { enableLargeConfig = true; }).overrideAttrs (o: { @@ -238,7 +239,7 @@ nix = pkgs.callPackage ./package.nix { inherit versionSuffix fileset officialRelease buildUnreleasedNotes; - inherit (pkgs) changelog-d; + inherit (pkgs) build-release-notes; internalApiDocs = true; boehmgc = pkgs.boehmgc-nix; busybox-sandbox-shell = pkgs.busybox-sandbox-shell; @@ -288,7 +289,7 @@ rl-next = let pkgs = nixpkgsFor.${system}.native; in pkgs.buildPackages.runCommand "test-rl-next-release-notes" { } '' - LANG=C.UTF-8 ${pkgs.changelog-d}/bin/changelog-d ${./doc/manual/rl-next} >$out + LANG=C.UTF-8 ${lib.getExe pkgs.build-release-notes} ${./doc/manual/rl-next} >$out ''; } // (lib.optionalAttrs (builtins.elem system linux64BitSystems)) { dockerImage = self.hydraJobs.dockerImage.${system}; diff --git a/maintainers/build-release-notes.nix b/maintainers/build-release-notes.nix new file mode 100644 index 000000000..9462e33d7 --- /dev/null +++ b/maintainers/build-release-notes.nix @@ -0,0 +1,6 @@ +{ lib, python3, writeShellScriptBin }: + +writeShellScriptBin "build-release-notes" '' + exec ${lib.getExe (python3.withPackages (p: [ p.python-frontmatter ]))} \ + ${./build-release-notes.py} "$@" +'' diff --git a/maintainers/build-release-notes.py b/maintainers/build-release-notes.py new file mode 100755 index 000000000..ba645d19a --- /dev/null +++ b/maintainers/build-release-notes.py @@ -0,0 +1,66 @@ +import frontmatter +import sys +import pathlib +import textwrap + +GH_BASE = "https://github.com/NixOS/nix" +FORGEJO_BASE = "https://git.lix.systems/lix-project/lix" +GERRIT_BASE = "https://gerrit.lix.systems/c/lix/+" + +SIGNIFICANCECES = { + None: 0, + 'significant': 10, +} + +def format_link(ident: str, gh_part: str, fj_part: str) -> str: + # FIXME: deprecate github as default + if ident.isdigit(): + num, link, base = int(ident), f"#{ident}", f"{GH_BASE}/{gh_part}" + elif ident.startswith("gh#"): + num, link, base = int(ident[3:]), ident, f"{GH_BASE}/{gh_part}" + elif ident.startswith("fj#"): + num, link, base = int(ident[3:]), ident, f"{FORGEJO_BASE}/{fj_part}" + else: + raise Exception("unrecognized reference format", ident) + return f"[{link}]({base}/{num})" + +def format_issue(issue: str) -> str: + return format_link(issue, "issues", "issues") +def format_pr(pr: str) -> str: + return format_link(pr, "pull", "pulls") +def format_cl(cl: str) -> str: + clid = int(cl) + return f"[cl/{clid}]({GERRIT_BASE}/{clid})" + +paths = pathlib.Path(sys.argv[1]).glob('*.md') +entries = [] +for p in paths: + try: + e = frontmatter.load(p) + if 'synopsis' not in e.metadata: + raise Exception('missing synposis') + unknownKeys = set(e.metadata.keys()) - set(('synopsis', 'cls', 'issues', 'prs', 'significance')) + if unknownKeys: + raise Exception('unknown keys', unknownKeys) + entries.append((p, e)) + except Exception as e: + e.add_note(f"in {p}") + raise + +for p, entry in sorted(entries, key=lambda e: (-SIGNIFICANCECES[e[1].metadata.get('significance')], e[0])): + try: + header = entry.metadata['synopsis'] + links = [] + links += map(format_issue, str(entry.metadata.get('issues', "")).split()) + links += map(format_pr, str(entry.metadata.get('prs', "")).split()) + links += map(format_cl, str(entry.metadata.get('cls', "")).split()) + if links != []: + header += " " + " ".join(links) + if header: + print(f"- {header}") + print() + print(textwrap.indent(entry.content, ' ')) + print() + except Exception as e: + e.add_note(f"in {p}") + raise diff --git a/maintainers/release-notes b/maintainers/release-notes index 34cd85a56..c7a4e5074 100755 --- a/maintainers/release-notes +++ b/maintainers/release-notes @@ -152,7 +152,7 @@ section_title="Release $version_full ($DATE)" # TODO add minor number, and append? echo "# $section_title" echo - changelog-d doc/manual/rl-next | sed -e 's/ *$//' + build-release-notes doc/manual/rl-next ) | tee -a $file log "Wrote $file" diff --git a/misc/changelog-d.cabal.nix b/misc/changelog-d.cabal.nix deleted file mode 100644 index 76f9353cd..000000000 --- a/misc/changelog-d.cabal.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ mkDerivation, aeson, base, bytestring, cabal-install-parsers -, Cabal-syntax, containers, directory, filepath, frontmatter -, generic-lens-lite, lib, mtl, optparse-applicative, parsec, pretty -, regex-applicative, text, pkgs -}: -let rev = "f30f6969e9cd8b56242309639d58acea21c99d06"; -in -mkDerivation { - pname = "changelog-d"; - version = "0.1"; - src = pkgs.fetchurl { - name = "changelog-d-${rev}.tar.gz"; - url = "https://codeberg.org/roberth/changelog-d/archive/${rev}.tar.gz"; - hash = "sha256-8a2+i5u7YoszAgd5OIEW0eYUcP8yfhtoOIhLJkylYJ4="; - } // { inherit rev; }; - isLibrary = false; - isExecutable = true; - libraryHaskellDepends = [ - aeson base bytestring cabal-install-parsers Cabal-syntax containers - directory filepath frontmatter generic-lens-lite mtl parsec pretty - regex-applicative text - ]; - executableHaskellDepends = [ - base bytestring Cabal-syntax directory filepath - optparse-applicative - ]; - doHaddock = false; - description = "Concatenate changelog entries into a single one"; - license = lib.licenses.gpl3Plus; - mainProgram = "changelog-d"; -} diff --git a/misc/changelog-d.nix b/misc/changelog-d.nix deleted file mode 100644 index 1b20f4596..000000000 --- a/misc/changelog-d.nix +++ /dev/null @@ -1,31 +0,0 @@ -# Taken temporarily from -{ - callPackage, - lib, - haskell, - haskellPackages, -}: - -let - hsPkg = haskellPackages.callPackage ./changelog-d.cabal.nix { }; - - addCompletions = haskellPackages.generateOptparseApplicativeCompletions ["changelog-d"]; - - haskellModifications = - lib.flip lib.pipe [ - addCompletions - haskell.lib.justStaticExecutables - ]; - - mkDerivationOverrides = finalAttrs: oldAttrs: { - - version = oldAttrs.version + "-git-${lib.strings.substring 0 7 oldAttrs.src.rev}"; - - meta = oldAttrs.meta // { - homepage = "https://codeberg.org/roberth/changelog-d"; - maintainers = [ lib.maintainers.roberth ]; - }; - - }; -in - (haskellModifications hsPkg).overrideAttrs mkDerivationOverrides diff --git a/package.nix b/package.nix index 1392bbe62..3c4971605 100644 --- a/package.nix +++ b/package.nix @@ -8,7 +8,7 @@ boehmgc, nlohmann_json, bison, - changelog-d, + build-release-notes, boost, brotli, bzip2, @@ -159,7 +159,7 @@ in stdenv.mkDerivation (finalAttrs: { jq lsof ] ++ lib.optional stdenv.hostPlatform.isLinux util-linuxMinimal - ++ lib.optional (!officialRelease && buildUnreleasedNotes) changelog-d + ++ lib.optional (!officialRelease && buildUnreleasedNotes) build-release-notes ++ lib.optional internalApiDocs doxygen ++ lib.optionals buildWithMeson [ meson