From 062d945e631817a871377294ec570ad146cb77b4 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sun, 15 Sep 2024 19:05:04 +0100 Subject: [PATCH 01/22] [WIP]: new-plugin CI workflow --- .github/workflows/new-plugin.yml | 149 +++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 .github/workflows/new-plugin.yml diff --git a/.github/workflows/new-plugin.yml b/.github/workflows/new-plugin.yml new file mode 100644 index 0000000000..d1e43e1cd1 --- /dev/null +++ b/.github/workflows/new-plugin.yml @@ -0,0 +1,149 @@ +name: new-plugin +on: + push: + branch: + - "main" + paths: + - "plugins/**" + +# Prevent running this workflow concurrently +concurrency: + group: "matrix-messages" + +jobs: + setup: + name: Collect metadata and setup job matrix + runs-on: ubuntu-latest + timeout-minutes: 40 + if: github.repository == 'nix-community/nixvim' + + outputs: + plugins: ${{ steps.get_info.outputs.json }} + pr_number: ${{ steps.pr.outputs.number }} + pr_url: ${{ steps.get_pr.outputs.url }} + pr_author_name: ${{ steps.get_pr.outputs.author_name }} + pr_author_url: ${{ steps.get_pr.outputs.author_url }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Nix + uses: cachix/install-nix-action@v26 + with: + nix_path: nixpkgs=channel:nixos-unstable + github_access_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Get plugins info + id: get_info + run: | + # Use `nix eval` to get json arrays containing plugins available on the pushed commit, and the previous commit + OLD_PLUGINS=$( + nix eval 'github:${{ github.repository }}/${{ github.event.before }}#nixvimConfiguration.options.plugins' \ + --apply 'builtins.attrNames' \ + --json + ) + NEW_PLUGINS=$( + nix eval '.#nixvimConfiguration.options.plugins' \ + --apply 'builtins.attrNames' \ + --json + ) + OLD_COLORSCHEMES=$( + nix eval 'github:${{ github.repository }}/${{ github.event.before }}#nixvimConfiguration.options.colorschemes' \ + --apply 'builtins.attrNames' \ + --json + ) + NEW_COLORSCHEMES=$( + nix eval '.#nixvimConfiguration.options.colorschemes' \ + --apply 'builtins.attrNames' \ + --json + ) + PLUGIN_JSON="{ \"old\": $OLD_PLUGINS, \"new\": $NEW_PLUGINS }" + COLORSCHEME_JSON="{ \"old\": $OLD_COLORSCHEMES, \"new\": $NEW_COLORSCHEMES }" + + # Collect added/removed plugins by subtracting old/new arrays + GROUPED="{ + \"added\": { + \"plugin\": $(echo "$PLUGIN_JSON" | jq '.new-.old'), + \"colorscheme\": $(echo "$COLORSCHEME_JSON" | jq '.new-.old') + }, + \"removed\": { + \"plugin\": $(echo "$PLUGIN_JSON" | jq '.old-.new'), + \"colorscheme\": $(echo "$COLORSCHEME_JSON" | jq '.old-.new') + } + }" + + # Un-group types to `{ "added": [ { "type": "plugin", "name": "foo" } ], "removed": [] }` + GROUPED_BY_CHANGE=$(echo "$GROUPED" | jq -c 'map_values(to_entries | map(.key as $type | .value[] | { type: $type, name: . }))') + # TODO: When plugins are removed, try to detect renames heuristically + + # Write to GITHUB_OUTPUT + JSON=$(echo "$GROUPED_BY_CHANGE" | jq -c 'to_entries | map(.key as $change | .value[] | . += { change: $change })') + echo "json=$JSON" >> $GITHUB_OUTPUT + + - name: Get PR info + id: get_pr + if: steps.get_info.outputs.json != '[]' + env: + GH_TOKEN: ${{ github.token }} + run: | + # `gh` will have already printed to stderr, so no need to parse the response json + JSON=$( + gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${{ github.repository }}/commits/${{ github.sha }}/pulls + ) || exit 1 + + if [[ "$(echo "$JSON" | jq -c '.')" = "[]" ]]; then + # No associated PR + # TODO: does this need special handling? + else + # Print key=value pairs to GITHUB_OUTPUT + echo "$JSON" | \ + jq -r '.[0] | { number: .number, url: .html_url, author_name: .user.login, author_url: .user.html_url } | to_entries[] | "\(.key)=\(.value)"' \ + >> $GITHUB_OUTPUT + fi + + send: + name: Send matrix message + runs-on: ubuntu-latest + needs: setup + strategy: + matrix: + plugins: ${{ fromJSON(needs.setup.outputs.plugins) }} + env: + name: ${{ matrix.plugins.name }} + type: ${{ matrix.plugins.type }} + change: ${{ matrix.plugins.change }} + pr_number: ${{ needs.setup.outputs.pr_number }} + pr_url: ${{ needs.setupt_pr.outputs.pr_url }} + pr_author_name: ${{ needs.setupt_pr.outputs.pr_author_name }} + pr_author_url: ${{ needs.setupt_pr.outputs.pr_author_url }} + + steps: + - name: Install matrix-msg tool + uses: lkiesow/matrix-notification@v1 + with: + token: ${{ secrets.CI_MATRIX_TOKEN }} + server: ${{ secrets.CI_MATRIX_SERVER }} + room: ${{ secrets.CI_MATRIX_ROOM }} + tool: true + + - name: Send message and print summary + run: | + # Message text; plain-text & html + # TODO: format as-per existing announcements + # See available env-vars above + msg="Hello, world!" + html_msg="Hello, world!" + + # stdout + echo "$msg" + + # markdown summary + echo "$html_msg" >> $GITHUG_STEP_SUMMARY + + # matrix message + matrix-msg "$msg" "$html_msg" + # TODO: update stdout/step_summary with msg success/failure From 9be5d2a15bfe6e749bac0c238587cbd02792a9b8 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Mon, 16 Sep 2024 19:58:54 +0100 Subject: [PATCH 02/22] fixup! [WIP]: new-plugin CI workflow --- .github/workflows/new-plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-plugin.yml b/.github/workflows/new-plugin.yml index d1e43e1cd1..6a93824a31 100644 --- a/.github/workflows/new-plugin.yml +++ b/.github/workflows/new-plugin.yml @@ -1,7 +1,7 @@ name: new-plugin on: push: - branch: + branches: - "main" paths: - "plugins/**" From c5aad47c3dcb5f1876feca5349e6bafb71f80210 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Mon, 16 Sep 2024 23:30:44 +0100 Subject: [PATCH 03/22] refactor: move most logic into a python script --- .github/workflows/new-plugin.yml | 54 ++++++----------------------- flake-modules/dev/default.nix | 5 ++- flake-modules/dev/plugin-info.nix | 56 +++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 45 deletions(-) create mode 100644 flake-modules/dev/plugin-info.nix diff --git a/.github/workflows/new-plugin.yml b/.github/workflows/new-plugin.yml index 6a93824a31..e830321cff 100644 --- a/.github/workflows/new-plugin.yml +++ b/.github/workflows/new-plugin.yml @@ -37,49 +37,11 @@ jobs: - name: Get plugins info id: get_info run: | - # Use `nix eval` to get json arrays containing plugins available on the pushed commit, and the previous commit - OLD_PLUGINS=$( - nix eval 'github:${{ github.repository }}/${{ github.event.before }}#nixvimConfiguration.options.plugins' \ - --apply 'builtins.attrNames' \ - --json - ) - NEW_PLUGINS=$( - nix eval '.#nixvimConfiguration.options.plugins' \ - --apply 'builtins.attrNames' \ - --json - ) - OLD_COLORSCHEMES=$( - nix eval 'github:${{ github.repository }}/${{ github.event.before }}#nixvimConfiguration.options.colorschemes' \ - --apply 'builtins.attrNames' \ - --json - ) - NEW_COLORSCHEMES=$( - nix eval '.#nixvimConfiguration.options.colorschemes' \ - --apply 'builtins.attrNames' \ - --json - ) - PLUGIN_JSON="{ \"old\": $OLD_PLUGINS, \"new\": $NEW_PLUGINS }" - COLORSCHEME_JSON="{ \"old\": $OLD_COLORSCHEMES, \"new\": $NEW_COLORSCHEMES }" - - # Collect added/removed plugins by subtracting old/new arrays - GROUPED="{ - \"added\": { - \"plugin\": $(echo "$PLUGIN_JSON" | jq '.new-.old'), - \"colorscheme\": $(echo "$COLORSCHEME_JSON" | jq '.new-.old') - }, - \"removed\": { - \"plugin\": $(echo "$PLUGIN_JSON" | jq '.old-.new'), - \"colorscheme\": $(echo "$COLORSCHEME_JSON" | jq '.old-.new') - } - }" - - # Un-group types to `{ "added": [ { "type": "plugin", "name": "foo" } ], "removed": [] }` - GROUPED_BY_CHANGE=$(echo "$GROUPED" | jq -c 'map_values(to_entries | map(.key as $type | .value[] | { type: $type, name: . }))') - # TODO: When plugins are removed, try to detect renames heuristically - - # Write to GITHUB_OUTPUT - JSON=$(echo "$GROUPED_BY_CHANGE" | jq -c 'to_entries | map(.key as $change | .value[] | . += { change: $change })') - echo "json=$JSON" >> $GITHUB_OUTPUT + # Run the `plugin-info` tool, printing the result to write to GITHUB_OUTPUT + echo "json=$( + nix run .#plugin-info -- \ + --old 'github:${{ github.repository }}/${{ github.event.before }}' + )" >> $GITHUB_OUTPUT - name: Get PR info id: get_pr @@ -136,7 +98,11 @@ jobs: # TODO: format as-per existing announcements # See available env-vars above msg="Hello, world!" - html_msg="Hello, world!" + html_msg=" +

[💾 NEW PLUGIN]

+

helpview.nvim support has been added !

+

Description: Decorations for vimdoc/help files in Neovim.
Documentation
PR by khaneliman

+ " # stdout echo "$msg" diff --git a/flake-modules/dev/default.nix b/flake-modules/dev/default.nix index 2f76438a1c..a8f64ea0db 100644 --- a/flake-modules/dev/default.nix +++ b/flake-modules/dev/default.nix @@ -1,7 +1,10 @@ { lib, inputs, ... }: { imports = - [ ./devshell.nix ] + [ + ./devshell.nix + ./plugin-info.nix + ] ++ lib.optional (inputs.git-hooks ? flakeModule) inputs.git-hooks.flakeModule ++ lib.optional (inputs.treefmt-nix ? flakeModule) inputs.treefmt-nix.flakeModule; diff --git a/flake-modules/dev/plugin-info.nix b/flake-modules/dev/plugin-info.nix new file mode 100644 index 0000000000..74a10efbdd --- /dev/null +++ b/flake-modules/dev/plugin-info.nix @@ -0,0 +1,56 @@ +{ + perSystem = + { pkgs, ... }: + { + apps.plugin-info.program = + pkgs.writers.writePython3Bin "test_python3" + { + libraries = with pkgs.python3Packages; [ pyyaml ]; + flakeIgnore = [ + "E501" # Line length + ]; + } + '' + import json + import subprocess + + + def get_plugins(flake: str) -> list[str]: + expr = 'x: with builtins; listToAttrs (map (name: { inherit name; value = attrNames x.''${name}; }) [ "plugins" "colorschemes" ])' + cmd = ['nix', 'eval', f"{flake}#nixvimConfiguration.options", '--apply', expr, '--json'] + out = subprocess.check_output(cmd) + # Parse as json, converting the lists to sets + return {k: set(v) for k, v in json.loads(out).items()} + + + # FIXME: get `old` and `compact` from argparse + old = 'github:nix-community/nixvim/336ba155ffcb20902b93873ad84527a833f57dc8' + compact = True + + plugins = {'old': get_plugins(old), 'new': get_plugins('.')} + + # TODO: also guess at "renamed" plugins heuristically + plugin_diff = { + 'added': {ns: plugins['new'][ns] - plugins['old'][ns] for ns in ['plugins', 'colorschemes']}, + 'removed': {ns: plugins['old'][ns] - plugins['new'][ns] for ns in ['plugins', 'colorschemes']} + } + + # Flatten the above dict into a list of entries; each with a 'name', 'namespace', & 'action' key + # TODO: add additional metadata to each entry, such as the `originalName`, `pkg.meta.description`, etc + plugin_entries = [ + {'name': name, 'namespace': namespace, 'action': action} + for action, namespaces in plugin_diff.items() + for namespace, plugins in namespaces.items() + for name in plugins + ] + + # Print json for use in CI matrix + print(json.dumps( + plugin_entries, + separators=((',', ':') if compact else None), + indent=(None if compact else 4), + sort_keys=(not compact) + )) + ''; + }; +} From e59e6f84e88eff656e278dcfd79a36a6aa073d36 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 17 Sep 2024 17:10:02 +0100 Subject: [PATCH 04/22] rename `plugin-info` -> `ci-new-plugin-matrix` --- flake-modules/dev/ci-new-plugin-matrix.nix | 12 +++++ flake-modules/dev/ci-new-plugin-matrix.py | 42 ++++++++++++++++ flake-modules/dev/default.nix | 2 +- flake-modules/dev/plugin-info.nix | 56 ---------------------- 4 files changed, 55 insertions(+), 57 deletions(-) create mode 100644 flake-modules/dev/ci-new-plugin-matrix.nix create mode 100644 flake-modules/dev/ci-new-plugin-matrix.py delete mode 100644 flake-modules/dev/plugin-info.nix diff --git a/flake-modules/dev/ci-new-plugin-matrix.nix b/flake-modules/dev/ci-new-plugin-matrix.nix new file mode 100644 index 0000000000..bb00841e9d --- /dev/null +++ b/flake-modules/dev/ci-new-plugin-matrix.nix @@ -0,0 +1,12 @@ +{ + perSystem = + { pkgs, ... }: + { + apps.plugin-info.program = pkgs.writers.writePython3Bin "test_python3" { + libraries = with pkgs.python3Packages; [ ]; + flakeIgnore = [ + "E501" # Line length + ]; + } (builtins.readFile ./ci-new-plugin-matrix.py); + }; +} diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py new file mode 100644 index 0000000000..40380e95b3 --- /dev/null +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -0,0 +1,42 @@ +import json +import subprocess + + +def get_plugins(flake: str) -> list[str]: + # TODO: shorten line length so we can keep flake8 E501 + expr = 'x: with builtins; listToAttrs (map (name: { inherit name; value = attrNames x.''${name}; }) [ "plugins" "colorschemes" ])' + cmd = ['nix', 'eval', f"{flake}#nixvimConfiguration.options", '--apply', expr, '--json'] + out = subprocess.check_output(cmd) + # Parse as json, converting the lists to sets + return {k: set(v) for k, v in json.loads(out).items()} + + +# FIXME: get `old` and `compact` from argparse +old = 'github:nix-community/nixvim/336ba155ffcb20902b93873ad84527a833f57dc8' +compact = True + +plugins = {'old': get_plugins(old), 'new': get_plugins('.')} + +# TODO: also guess at "renamed" plugins heuristically +plugin_diff = { + 'added': {ns: plugins['new'][ns] - plugins['old'][ns] for ns in ['plugins', 'colorschemes']}, + 'removed': {ns: plugins['old'][ns] - plugins['new'][ns] for ns in ['plugins', 'colorschemes']} +} + +# Flatten the above dict into a list of entries; each with a 'name', 'namespace', & 'action' key +# TODO: add additional metadata to each entry, such as the `originalName`, `pkg.meta.description`, etc +plugin_entries = [ + {'name': name, 'namespace': namespace, 'action': action} + for action, namespaces in plugin_diff.items() + for namespace, plugins in namespaces.items() + for name in plugins +] + +# Print json for use in CI matrix +print(json.dumps( + plugin_entries, + separators=((',', ':') if compact else None), + indent=(None if compact else 4), + sort_keys=(not compact) +)) + diff --git a/flake-modules/dev/default.nix b/flake-modules/dev/default.nix index a8f64ea0db..32821276d8 100644 --- a/flake-modules/dev/default.nix +++ b/flake-modules/dev/default.nix @@ -2,8 +2,8 @@ { imports = [ + ./ci-new-plugin-matrix.nix ./devshell.nix - ./plugin-info.nix ] ++ lib.optional (inputs.git-hooks ? flakeModule) inputs.git-hooks.flakeModule ++ lib.optional (inputs.treefmt-nix ? flakeModule) inputs.treefmt-nix.flakeModule; diff --git a/flake-modules/dev/plugin-info.nix b/flake-modules/dev/plugin-info.nix deleted file mode 100644 index 74a10efbdd..0000000000 --- a/flake-modules/dev/plugin-info.nix +++ /dev/null @@ -1,56 +0,0 @@ -{ - perSystem = - { pkgs, ... }: - { - apps.plugin-info.program = - pkgs.writers.writePython3Bin "test_python3" - { - libraries = with pkgs.python3Packages; [ pyyaml ]; - flakeIgnore = [ - "E501" # Line length - ]; - } - '' - import json - import subprocess - - - def get_plugins(flake: str) -> list[str]: - expr = 'x: with builtins; listToAttrs (map (name: { inherit name; value = attrNames x.''${name}; }) [ "plugins" "colorschemes" ])' - cmd = ['nix', 'eval', f"{flake}#nixvimConfiguration.options", '--apply', expr, '--json'] - out = subprocess.check_output(cmd) - # Parse as json, converting the lists to sets - return {k: set(v) for k, v in json.loads(out).items()} - - - # FIXME: get `old` and `compact` from argparse - old = 'github:nix-community/nixvim/336ba155ffcb20902b93873ad84527a833f57dc8' - compact = True - - plugins = {'old': get_plugins(old), 'new': get_plugins('.')} - - # TODO: also guess at "renamed" plugins heuristically - plugin_diff = { - 'added': {ns: plugins['new'][ns] - plugins['old'][ns] for ns in ['plugins', 'colorschemes']}, - 'removed': {ns: plugins['old'][ns] - plugins['new'][ns] for ns in ['plugins', 'colorschemes']} - } - - # Flatten the above dict into a list of entries; each with a 'name', 'namespace', & 'action' key - # TODO: add additional metadata to each entry, such as the `originalName`, `pkg.meta.description`, etc - plugin_entries = [ - {'name': name, 'namespace': namespace, 'action': action} - for action, namespaces in plugin_diff.items() - for namespace, plugins in namespaces.items() - for name in plugins - ] - - # Print json for use in CI matrix - print(json.dumps( - plugin_entries, - separators=((',', ':') if compact else None), - indent=(None if compact else 4), - sort_keys=(not compact) - )) - ''; - }; -} From 7444a06fbb3a2a2b7b23c31b7a88dd7e23bf820d Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 17 Sep 2024 17:16:43 +0100 Subject: [PATCH 05/22] add `main` fn --- flake-modules/dev/ci-new-plugin-matrix.py | 75 +++++++++++++++-------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index 40380e95b3..e11aa78724 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -4,39 +4,62 @@ def get_plugins(flake: str) -> list[str]: # TODO: shorten line length so we can keep flake8 E501 - expr = 'x: with builtins; listToAttrs (map (name: { inherit name; value = attrNames x.''${name}; }) [ "plugins" "colorschemes" ])' - cmd = ['nix', 'eval', f"{flake}#nixvimConfiguration.options", '--apply', expr, '--json'] + expr = ( + "x: with builtins; listToAttrs (map (name: { inherit name; value = attrNames x." + '${name}; }) [ "plugins" "colorschemes" ])' + ) + cmd = [ + "nix", + "eval", + f"{flake}#nixvimConfiguration.options", + "--apply", + expr, + "--json", + ] out = subprocess.check_output(cmd) # Parse as json, converting the lists to sets return {k: set(v) for k, v in json.loads(out).items()} -# FIXME: get `old` and `compact` from argparse -old = 'github:nix-community/nixvim/336ba155ffcb20902b93873ad84527a833f57dc8' -compact = True +def main(args) -> None: + plugins = {"old": get_plugins(args.old), "new": get_plugins(".")} -plugins = {'old': get_plugins(old), 'new': get_plugins('.')} + # TODO: also guess at "renamed" plugins heuristically + plugin_diff = { + "added": { + ns: plugins["new"][ns] - plugins["old"][ns] + for ns in ["plugins", "colorschemes"] + }, + "removed": { + ns: plugins["old"][ns] - plugins["new"][ns] + for ns in ["plugins", "colorschemes"] + }, + } -# TODO: also guess at "renamed" plugins heuristically -plugin_diff = { - 'added': {ns: plugins['new'][ns] - plugins['old'][ns] for ns in ['plugins', 'colorschemes']}, - 'removed': {ns: plugins['old'][ns] - plugins['new'][ns] for ns in ['plugins', 'colorschemes']} -} + # Flatten the above dict into a list of entries; each with a 'name', 'namespace', & 'action' key + # TODO: add additional metadata to each entry, such as the `originalName`, `pkg.meta.description`, etc + plugin_entries = [ + {"name": name, "namespace": namespace, "action": action} + for action, namespaces in plugin_diff.items() + for namespace, plugins in namespaces.items() + for name in plugins + ] -# Flatten the above dict into a list of entries; each with a 'name', 'namespace', & 'action' key -# TODO: add additional metadata to each entry, such as the `originalName`, `pkg.meta.description`, etc -plugin_entries = [ - {'name': name, 'namespace': namespace, 'action': action} - for action, namespaces in plugin_diff.items() - for namespace, plugins in namespaces.items() - for name in plugins -] + # Print json for use in CI matrix + print( + json.dumps( + plugin_entries, + separators=((",", ":") if args.compact else None), + indent=(None if args.compact else 4), + sort_keys=(not args.compact), + ) + ) -# Print json for use in CI matrix -print(json.dumps( - plugin_entries, - separators=((',', ':') if compact else None), - indent=(None if compact else 4), - sort_keys=(not compact) -)) +if __name__ == "__main__": + # FIXME: get args from argparse + args = { + "old": "github:nix-community/nixvim/336ba155ffcb20902b93873ad84527a833f57dc8", + "compact": True, + } + main(args) From 6e85d650a16147a1abdd7eda6c9e103d3f7eb235 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 17 Sep 2024 17:30:33 +0100 Subject: [PATCH 06/22] fixup rename --- flake-modules/dev/ci-new-plugin-matrix.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake-modules/dev/ci-new-plugin-matrix.nix b/flake-modules/dev/ci-new-plugin-matrix.nix index bb00841e9d..97b9131a38 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.nix +++ b/flake-modules/dev/ci-new-plugin-matrix.nix @@ -2,7 +2,7 @@ perSystem = { pkgs, ... }: { - apps.plugin-info.program = pkgs.writers.writePython3Bin "test_python3" { + apps.ci-new-plugin-matrix.program = pkgs.writers.writePython3Bin "test_python3" { libraries = with pkgs.python3Packages; [ ]; flakeIgnore = [ "E501" # Line length From de40c6a981d733321c199fef0fc9feca434fecef Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 17 Sep 2024 17:30:56 +0100 Subject: [PATCH 07/22] Comply with flake8 line length --- flake-modules/dev/ci-new-plugin-matrix.nix | 3 --- flake-modules/dev/ci-new-plugin-matrix.py | 25 ++++++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/flake-modules/dev/ci-new-plugin-matrix.nix b/flake-modules/dev/ci-new-plugin-matrix.nix index 97b9131a38..ea0305fcb5 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.nix +++ b/flake-modules/dev/ci-new-plugin-matrix.nix @@ -4,9 +4,6 @@ { apps.ci-new-plugin-matrix.program = pkgs.writers.writePython3Bin "test_python3" { libraries = with pkgs.python3Packages; [ ]; - flakeIgnore = [ - "E501" # Line length - ]; } (builtins.readFile ./ci-new-plugin-matrix.py); }; } diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index e11aa78724..a0a894dc67 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -1,12 +1,17 @@ +import argparse import json import subprocess def get_plugins(flake: str) -> list[str]: - # TODO: shorten line length so we can keep flake8 E501 expr = ( - "x: with builtins; listToAttrs (map (name: { inherit name; value = attrNames x." - '${name}; }) [ "plugins" "colorschemes" ])' + 'x: ' + 'with builtins; ' + 'listToAttrs (' + ' map' + ' (name: { inherit name; value = attrNames x.${name}; })' + ' [ "plugins" "colorschemes" ]' + ')' ) cmd = [ "nix", @@ -36,8 +41,10 @@ def main(args) -> None: }, } - # Flatten the above dict into a list of entries; each with a 'name', 'namespace', & 'action' key - # TODO: add additional metadata to each entry, such as the `originalName`, `pkg.meta.description`, etc + # Flatten the above dict into a list of entries; each with a 'name', + # 'namespace', & 'action' key + # TODO: add additional metadata to each entry, such as the `originalName`, + # `pkg.meta.description`, etc plugin_entries = [ {"name": name, "namespace": namespace, "action": action} for action, namespaces in plugin_diff.items() @@ -58,8 +65,14 @@ def main(args) -> None: if __name__ == "__main__": # FIXME: get args from argparse + parser = argparse.ArgumentParser() + parser.add_argument('old') + parser.add_argument('--compact', '-c') args = { - "old": "github:nix-community/nixvim/336ba155ffcb20902b93873ad84527a833f57dc8", + "old": ( + "github:nix-community/nixvim/" + "336ba155ffcb20902b93873ad84527a833f57dc8" + ), "compact": True, } main(args) From 8a1432fb0a0a4e844391d741c9f2c87a25e7ecdc Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 17 Sep 2024 18:33:27 +0100 Subject: [PATCH 08/22] continue stubbing --- flake-modules/dev/ci-new-plugin-matrix.py | 83 +++++++++++++++++------ 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index a0a894dc67..0ca4757925 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -1,17 +1,18 @@ import argparse import json +import re import subprocess def get_plugins(flake: str) -> list[str]: expr = ( - 'x: ' - 'with builtins; ' - 'listToAttrs (' - ' map' - ' (name: { inherit name; value = attrNames x.${name}; })' + "x: " + "with builtins; " + "listToAttrs (" + " map" + " (name: { inherit name; value = attrNames x.${name}; })" ' [ "plugins" "colorschemes" ]' - ')' + ")" ) cmd = [ "nix", @@ -41,16 +42,21 @@ def main(args) -> None: }, } - # Flatten the above dict into a list of entries; each with a 'name', - # 'namespace', & 'action' key + # Flatten the above dict into a list of entries; + # each with 'name' and 'namespace' keys # TODO: add additional metadata to each entry, such as the `originalName`, # `pkg.meta.description`, etc - plugin_entries = [ - {"name": name, "namespace": namespace, "action": action} + plugin_entries = { + action: {"name": name, "namespace": namespace} for action, namespaces in plugin_diff.items() for namespace, plugins in namespaces.items() for name in plugins - ] + } + + # Unless `--raw`, we should produce formatted message text + if not args.raw: + # TODO: convert entries to message strings + plugin_entries = plugin_entries # Print json for use in CI matrix print( @@ -63,16 +69,49 @@ def main(args) -> None: ) +# Describes an argparse type that should represent a flakeref, +# or a partial flakeref that we can normalise using some defaults. +def flakeref(arg): + default_protocol = "github:" + default_repo = "nix-community/nixvim" + sha_rxp = re.compile(r"^[A-Fa-f0-9]{6,40}$") + repo_rxp = re.compile( + r"^(?P[^:/]+:)?(?P(:?[^/]+)/(:?[^/]+))(?P/[A-Fa-f0-9]{6,40})?$" # noqa: E501 + ) + if sha_rxp.match(arg): + return f"{default_protocol}{default_repo}/{arg}" + elif m := repo_rxp.match(arg): + protocol = m.group("protocol") or default_protocol + repo = m.group("repo") + sha = m.group("sha") or "" + return protocol + repo + sha + else: + raise argparse.ArgumentTypeError(f"Not a valid flakeref: {arg}") + + if __name__ == "__main__": - # FIXME: get args from argparse - parser = argparse.ArgumentParser() - parser.add_argument('old') - parser.add_argument('--compact', '-c') - args = { - "old": ( - "github:nix-community/nixvim/" - "336ba155ffcb20902b93873ad84527a833f57dc8" + parser = argparse.ArgumentParser( + prog="ci-new-plugin-matrix", + description=( + "Generate a JSON matrix for use in CI, " "describing newly added plugins." ), - "compact": True, - } - main(args) + ) + parser.add_argument( + "old", + metavar="flakeref", + help="the (old) flake ref to compare against", + type=flakeref, + ) + parser.add_argument( + "--compact", + "-c", + help="produce compact json instead of prettifying", + action="store_true", + ) + parser.add_argument( + "--raw", + "-r", + help="produce raw data instead of message strings", + action="store_true", + ) + main(parser.parse_args()) From 20ede593b769d6c0e8ae2a183d3f3b96b18e3662 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 17 Sep 2024 20:00:51 +0100 Subject: [PATCH 09/22] more work... --- .github/workflows/new-plugin.yml | 50 ++++++++++++----- flake-modules/dev/ci-new-plugin-matrix.nix | 3 ++ flake-modules/dev/ci-new-plugin-matrix.py | 62 +++++++++++++++++----- 3 files changed, 88 insertions(+), 27 deletions(-) diff --git a/.github/workflows/new-plugin.yml b/.github/workflows/new-plugin.yml index e830321cff..7cb12b0614 100644 --- a/.github/workflows/new-plugin.yml +++ b/.github/workflows/new-plugin.yml @@ -40,12 +40,13 @@ jobs: # Run the `plugin-info` tool, printing the result to write to GITHUB_OUTPUT echo "json=$( nix run .#plugin-info -- \ - --old 'github:${{ github.repository }}/${{ github.event.before }}' + -c \ + 'github:${{ github.repository }}/${{ github.event.before }}' )" >> $GITHUB_OUTPUT - name: Get PR info id: get_pr - if: steps.get_info.outputs.json != '[]' + if: steps.get_info.outputs.json != '{}' env: GH_TOKEN: ${{ github.token }} run: | @@ -71,13 +72,15 @@ jobs: name: Send matrix message runs-on: ubuntu-latest needs: setup + if: ${{ fromJSON(needs.setup.outputs.plugins).removed == [] && fromJSON(needs.setup.outputs.plugins).added != [] }} strategy: matrix: - plugins: ${{ fromJSON(needs.setup.outputs.plugins) }} + added: ${{ fromJSON(needs.setup.outputs.plugins).added }} env: - name: ${{ matrix.plugins.name }} - type: ${{ matrix.plugins.type }} - change: ${{ matrix.plugins.change }} + name: ${{ matrix.added.name }} + plain: ${{ matrix.added.plain }} + html: ${{ matrix.added.html }} + markdown: ${{ matrix.added.markdown }} pr_number: ${{ needs.setup.outputs.pr_number }} pr_url: ${{ needs.setupt_pr.outputs.pr_url }} pr_author_name: ${{ needs.setupt_pr.outputs.pr_author_name }} @@ -98,18 +101,37 @@ jobs: # TODO: format as-per existing announcements # See available env-vars above msg="Hello, world!" - html_msg=" -

[💾 NEW PLUGIN]

-

helpview.nvim support has been added !

-

Description: Decorations for vimdoc/help files in Neovim.
Documentation
PR by khaneliman

- " # stdout - echo "$msg" + echo "$plain" # markdown summary - echo "$html_msg" >> $GITHUG_STEP_SUMMARY + echo "$markdown" >> $GITHUG_STEP_SUMMARY # matrix message - matrix-msg "$msg" "$html_msg" + matrix-msg "$plain" "$html" # TODO: update stdout/step_summary with msg success/failure + + report: + name: Report removed plugins + runs-on: ubuntu-latest + needs: setup + if: ${{ fromJSON(needs.setup.outputs.plugins).removed != [] }} + env: + json: ${{ needs.setup.outputs.plugins }} + pr_number: ${{ needs.setup.outputs.pr_number }} + pr_url: ${{ needs.setupt_pr.outputs.pr_url }} + pr_author_name: ${{ needs.setupt_pr.outputs.pr_author_name }} + pr_author_url: ${{ needs.setupt_pr.outputs.pr_author_url }} + + steps: + - name: Comment on PR + if: ${{ needs.setup.outputs.pr_number }} + env: + GH_TOKEN: ${{ github.token }} + BODY: | + Hi from new-plugin workflow! + run: | + gh pr comment '${{ needs.setup.outputs.pr_number }}' \ + --repo '${{ github.repository }}' \ + --body "$BODY" diff --git a/flake-modules/dev/ci-new-plugin-matrix.nix b/flake-modules/dev/ci-new-plugin-matrix.nix index ea0305fcb5..97b9131a38 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.nix +++ b/flake-modules/dev/ci-new-plugin-matrix.nix @@ -4,6 +4,9 @@ { apps.ci-new-plugin-matrix.program = pkgs.writers.writePython3Bin "test_python3" { libraries = with pkgs.python3Packages; [ ]; + flakeIgnore = [ + "E501" # Line length + ]; } (builtins.readFile ./ci-new-plugin-matrix.py); }; } diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index 0ca4757925..d820714f7d 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -1,16 +1,32 @@ import argparse +import enum import json import re import subprocess +# TODO: use this example as a template +html_msg = """ +

[💾 NEW PLUGIN]

+

helpview.nvim support has been added !

+

Description: Decorations for vimdoc/help files in Neovim.
Documentation
PR by khaneliman

+""" + +class Format(enum.Enum): + PLAIN = "plain" + HTML = "html" + MARKDOWN = "markdown" + + +# Gets a list of plugins that exist in the flake. +# Grouped as "plugins" and "colorschemes" def get_plugins(flake: str) -> list[str]: expr = ( - "x: " + "options: " "with builtins; " "listToAttrs (" " map" - " (name: { inherit name; value = attrNames x.${name}; })" + " (name: { inherit name; value = attrNames options.${name}; })" ' [ "plugins" "colorschemes" ]' ")" ) @@ -27,6 +43,16 @@ def get_plugins(flake: str) -> list[str]: return {k: set(v) for k, v in json.loads(out).items()} +def render_added_plugin(plugin: dict, format: Format) -> str: + match format: + case Format.PLAIN: + return f"{plugin['name']} was added!" + case Format.HTML: + return f"{plugin['name']} was added!" + case Format.MARKDOWN: + return f"`{plugin['name']}` was added!" + + def main(args) -> None: plugins = {"old": get_plugins(args.old), "new": get_plugins(".")} @@ -46,17 +72,29 @@ def main(args) -> None: # each with 'name' and 'namespace' keys # TODO: add additional metadata to each entry, such as the `originalName`, # `pkg.meta.description`, etc + # Maybe we can use a `Plugin` class for this? plugin_entries = { - action: {"name": name, "namespace": namespace} + action: [ + {"name": name, "namespace": namespace} + for namespace, plugins in namespaces.items() + for name in plugins + ] for action, namespaces in plugin_diff.items() - for namespace, plugins in namespaces.items() - for name in plugins } - # Unless `--raw`, we should produce formatted message text - if not args.raw: - # TODO: convert entries to message strings - plugin_entries = plugin_entries + # Unless `--raw`, we should produce formatted text for added plugins + if not args.raw and "added" in plugin_entries: + plugin_entries.update( + added=[ + { + "name": plugin["name"], + "plain": render_added_plugin(plugin, Format.PLAIN), + "html": render_added_plugin(plugin, Format.HTML), + "markdown": render_added_plugin(plugin, Format.MARKDOWN) + } + for plugin in plugin_entries["added"] + ] + ) # Print json for use in CI matrix print( @@ -76,7 +114,7 @@ def flakeref(arg): default_repo = "nix-community/nixvim" sha_rxp = re.compile(r"^[A-Fa-f0-9]{6,40}$") repo_rxp = re.compile( - r"^(?P[^:/]+:)?(?P(:?[^/]+)/(:?[^/]+))(?P/[A-Fa-f0-9]{6,40})?$" # noqa: E501 + r"^(?P[^:/]+:)?(?P(:?[^/]+)/(:?[^/]+))(?P/[A-Fa-f0-9]{6,40})?$" ) if sha_rxp.match(arg): return f"{default_protocol}{default_repo}/{arg}" @@ -92,9 +130,7 @@ def flakeref(arg): if __name__ == "__main__": parser = argparse.ArgumentParser( prog="ci-new-plugin-matrix", - description=( - "Generate a JSON matrix for use in CI, " "describing newly added plugins." - ), + description="Generate a JSON matrix for use in CI, describing newly added plugins.", ) parser.add_argument( "old", From 09b6f90a302edc05d8ce6138f4b374589a56ea2e Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 17 Sep 2024 20:45:02 +0100 Subject: [PATCH 10/22] start fleshing out message text --- flake-modules/dev/ci-new-plugin-matrix.py | 109 ++++++++++++++-------- 1 file changed, 68 insertions(+), 41 deletions(-) diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index d820714f7d..85e6b08010 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -4,13 +4,6 @@ import re import subprocess -# TODO: use this example as a template -html_msg = """ -

[💾 NEW PLUGIN]

-

helpview.nvim support has been added !

-

Description: Decorations for vimdoc/help files in Neovim.
Documentation
PR by khaneliman

-""" - class Format(enum.Enum): PLAIN = "plain" @@ -18,39 +11,10 @@ class Format(enum.Enum): MARKDOWN = "markdown" -# Gets a list of plugins that exist in the flake. -# Grouped as "plugins" and "colorschemes" -def get_plugins(flake: str) -> list[str]: - expr = ( - "options: " - "with builtins; " - "listToAttrs (" - " map" - " (name: { inherit name; value = attrNames options.${name}; })" - ' [ "plugins" "colorschemes" ]' - ")" - ) - cmd = [ - "nix", - "eval", - f"{flake}#nixvimConfiguration.options", - "--apply", - expr, - "--json", - ] - out = subprocess.check_output(cmd) - # Parse as json, converting the lists to sets - return {k: set(v) for k, v in json.loads(out).items()} - - -def render_added_plugin(plugin: dict, format: Format) -> str: - match format: - case Format.PLAIN: - return f"{plugin['name']} was added!" - case Format.HTML: - return f"{plugin['name']} was added!" - case Format.MARKDOWN: - return f"`{plugin['name']}` was added!" +icons = { + "plugin": "💾", + "colorscheme": "🎨", +} def main(args) -> None: @@ -90,7 +54,7 @@ def main(args) -> None: "name": plugin["name"], "plain": render_added_plugin(plugin, Format.PLAIN), "html": render_added_plugin(plugin, Format.HTML), - "markdown": render_added_plugin(plugin, Format.MARKDOWN) + "markdown": render_added_plugin(plugin, Format.MARKDOWN), } for plugin in plugin_entries["added"] ] @@ -107,6 +71,69 @@ def main(args) -> None: ) +# Gets a list of plugins that exist in the flake. +# Grouped as "plugins" and "colorschemes" +def get_plugins(flake: str) -> list[str]: + expr = ( + "options: " + "with builtins; " + "listToAttrs (" + " map" + " (name: { inherit name; value = attrNames options.${name}; })" + ' [ "plugins" "colorschemes" ]' + ")" + ) + cmd = [ + "nix", + "eval", + f"{flake}#nixvimConfiguration.options", + "--apply", + expr, + "--json", + ] + out = subprocess.check_output(cmd) + # Parse as json, converting the lists to sets + return {k: set(v) for k, v in json.loads(out).items()} + + +def render_added_plugin(plugin: dict, format: Format) -> str: + name = plugin["name"] + namespace = plugin["namespace"] + kind = namespace[:-1] + plugin_url = "TODO" # TODO + docs_url = f"https://nix-community.github.io/nixvim/{namespace}/{name}/index.html" + + match format: + case Format.PLAIN: + return ( + f"[{icons[kind]} NEW {kind.upper()}]\n\n" + f"{name} support has been added!\n\n" + # TODO: f"Description: {plugin_description}" + f"URL: {plugin_url}" + f"Docs: {docs_url}\n" + # TODO: f"PR by {pr_author}: {pr_url}\n" + ) + case Format.HTML: + # TODO: render from the markdown below? + return ( + f"

[{icons[kind]} NEW {kind.upper()}]

\n" + f'

{name} support has been added!

\n' + "

\n" + # TODO: f"Description: {plugin_description}
\n" + f'PR by {pr_author}\n' + "

\n" + ) + case Format.MARKDOWN: + return ( + f"\\[{icons[kind]} NEW {kind.upper()}\\]\n\n" + f"[{name}]({plugin_url}) support has been added!\n\n" + # TODO: f"Description: {plugin_description}\n" + f"[Documentation]({docs_url})\n" + # TODO: f'[PR]({pr_url}) by [{pr_author}](https://github.com/{pr_author})\n' + ) + + # Describes an argparse type that should represent a flakeref, # or a partial flakeref that we can normalise using some defaults. def flakeref(arg): From 101d54d697161960096ae1a1541305076d2a25f9 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 17 Sep 2024 22:18:07 +0100 Subject: [PATCH 11/22] move pr fetching to python script --- .github/workflows/new-plugin.yml | 72 ++++++--------- flake-modules/dev/ci-new-plugin-matrix.nix | 4 +- flake-modules/dev/ci-new-plugin-matrix.py | 100 ++++++++++++++++++--- 3 files changed, 118 insertions(+), 58 deletions(-) diff --git a/.github/workflows/new-plugin.yml b/.github/workflows/new-plugin.yml index 7cb12b0614..fc7db71646 100644 --- a/.github/workflows/new-plugin.yml +++ b/.github/workflows/new-plugin.yml @@ -16,13 +16,8 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 40 if: github.repository == 'nix-community/nixvim' - outputs: - plugins: ${{ steps.get_info.outputs.json }} - pr_number: ${{ steps.pr.outputs.number }} - pr_url: ${{ steps.get_pr.outputs.url }} - pr_author_name: ${{ steps.get_pr.outputs.author_name }} - pr_author_url: ${{ steps.get_pr.outputs.author_url }} + json: ${{ steps.get_info.outputs.json }} steps: - name: Checkout repository @@ -44,47 +39,23 @@ jobs: 'github:${{ github.repository }}/${{ github.event.before }}' )" >> $GITHUB_OUTPUT - - name: Get PR info - id: get_pr - if: steps.get_info.outputs.json != '{}' - env: - GH_TOKEN: ${{ github.token }} - run: | - # `gh` will have already printed to stderr, so no need to parse the response json - JSON=$( - gh api \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/${{ github.repository }}/commits/${{ github.sha }}/pulls - ) || exit 1 - - if [[ "$(echo "$JSON" | jq -c '.')" = "[]" ]]; then - # No associated PR - # TODO: does this need special handling? - else - # Print key=value pairs to GITHUB_OUTPUT - echo "$JSON" | \ - jq -r '.[0] | { number: .number, url: .html_url, author_name: .user.login, author_url: .user.html_url } | to_entries[] | "\(.key)=\(.value)"' \ - >> $GITHUB_OUTPUT - fi - send: name: Send matrix message runs-on: ubuntu-latest needs: setup - if: ${{ fromJSON(needs.setup.outputs.plugins).removed == [] && fromJSON(needs.setup.outputs.plugins).added != [] }} + if: ${{ fromJSON(needs.setup.outputs.json).removed == [] && fromJSON(needs.setup.outputs.json).added != [] }} strategy: matrix: - added: ${{ fromJSON(needs.setup.outputs.plugins).added }} + added: ${{ fromJSON(needs.setup.outputs.json).added }} env: name: ${{ matrix.added.name }} plain: ${{ matrix.added.plain }} html: ${{ matrix.added.html }} markdown: ${{ matrix.added.markdown }} - pr_number: ${{ needs.setup.outputs.pr_number }} - pr_url: ${{ needs.setupt_pr.outputs.pr_url }} - pr_author_name: ${{ needs.setupt_pr.outputs.pr_author_name }} - pr_author_url: ${{ needs.setupt_pr.outputs.pr_author_url }} + pr_number: ${{ fromJSON(needs.setup.outputs.json).pr.number }} + pr_url: ${{ fromJSON(needs.setup.outputs.json).pr.url }} + pr_author_name: ${{ fromJSON(needs.setup.outputs.json).pr.author_name }} + pr_author_url: ${{ fromJSON(needs.setup.outputs.json).pr.author_url }} steps: - name: Install matrix-msg tool @@ -116,22 +87,29 @@ jobs: name: Report removed plugins runs-on: ubuntu-latest needs: setup - if: ${{ fromJSON(needs.setup.outputs.plugins).removed != [] }} + if: ${{ fromJSON(needs.setup.outputs.json).removed != [] }} env: - json: ${{ needs.setup.outputs.plugins }} - pr_number: ${{ needs.setup.outputs.pr_number }} - pr_url: ${{ needs.setupt_pr.outputs.pr_url }} - pr_author_name: ${{ needs.setupt_pr.outputs.pr_author_name }} - pr_author_url: ${{ needs.setupt_pr.outputs.pr_author_url }} + json: ${{ needs.setup.outputs.json }} steps: - name: Comment on PR - if: ${{ needs.setup.outputs.pr_number }} + if: ${{ fromJSON(needs.setup.outputs.json).pr }} env: GH_TOKEN: ${{ github.token }} - BODY: | - Hi from new-plugin workflow! + num: ${{ fromJSON(needs.setup.outputs.json).pr.number }} run: | - gh pr comment '${{ needs.setup.outputs.pr_number }}' \ + body=" + > [!WARNING] + > Not posting announcements to Matrix because plugins were removed in this PR. + > Please post announcements manually. + + Added: + $(echo "$json" | jq -r '.added[] | "- \(.name)"') + + Removed: + $(echo "$json" | jq -r '.removed[] | "- \(.)"') + " + + gh pr comment "$num" \ --repo '${{ github.repository }}' \ - --body "$BODY" + --body "$body" diff --git a/flake-modules/dev/ci-new-plugin-matrix.nix b/flake-modules/dev/ci-new-plugin-matrix.nix index 97b9131a38..0986ba6ef6 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.nix +++ b/flake-modules/dev/ci-new-plugin-matrix.nix @@ -3,7 +3,9 @@ { pkgs, ... }: { apps.ci-new-plugin-matrix.program = pkgs.writers.writePython3Bin "test_python3" { - libraries = with pkgs.python3Packages; [ ]; + libraries = with pkgs.python3Packages; [ + requests + ]; flakeIgnore = [ "E501" # Line length ]; diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index 85e6b08010..2319bd3b13 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -1,8 +1,12 @@ import argparse import enum import json +import os import re import subprocess +from sys import stderr + +import requests class Format(enum.Enum): @@ -46,15 +50,31 @@ def main(args) -> None: for action, namespaces in plugin_diff.items() } + # Only lookup PR if something was added or removed + if plugin_entries["added"] or plugin_entries["removed"]: + if pr := get_pr( + sha=args.head, + # TODO: should this be configurable? + repo="nix-community/nixvim", + token=args.token, + ): + plugin_entries["pr"] = { + "number": pr["number"], + "url": pr["html_url"], + "author_name": pr["user"]["login"], + "author_url": pr["user"]["html_url"], + } + # Unless `--raw`, we should produce formatted text for added plugins if not args.raw and "added" in plugin_entries: + pr = plugin_entries.get("pr") or None plugin_entries.update( added=[ { "name": plugin["name"], - "plain": render_added_plugin(plugin, Format.PLAIN), - "html": render_added_plugin(plugin, Format.HTML), - "markdown": render_added_plugin(plugin, Format.MARKDOWN), + "plain": render_added_plugin(plugin, pr, Format.PLAIN), + "html": render_added_plugin(plugin, pr, Format.HTML), + "markdown": render_added_plugin(plugin, pr, Format.MARKDOWN), } for plugin in plugin_entries["added"] ] @@ -96,7 +116,38 @@ def get_plugins(flake: str) -> list[str]: return {k: set(v) for k, v in json.loads(out).items()} -def render_added_plugin(plugin: dict, format: Format) -> str: +def get_head_sha() -> str: + return subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip() + + +def get_pr(sha: str, repo: str, token: str = None) -> dict: + headers = { + "Accept": "application/vnd.github+json", + "X-GitHub-Api-Version": "2022-11-28", + } + if token: + headers["Authorization"] = f"Bearer {token}" + + res = requests.get( + url=f"https://api.github.com/repos/{repo}/commits/{sha}/pulls", headers=headers + ) + + if res.status_code != 200: + try: + message = res.json()["message"] + except requests.exceptions.JSONDecodeError: + message = res.text + # FIXME: Maybe we should panic and fail CI? + print(f"{message} (HTTP {res.status_code})", file=stderr) + return None + + # If no matching PR exists, an empty list is returned + if data := res.json(): + return data[0] + return None + + +def render_added_plugin(plugin: dict, pr: dict, format: Format) -> str: name = plugin["name"] namespace = plugin["namespace"] kind = namespace[:-1] @@ -111,7 +162,11 @@ def render_added_plugin(plugin: dict, format: Format) -> str: # TODO: f"Description: {plugin_description}" f"URL: {plugin_url}" f"Docs: {docs_url}\n" - # TODO: f"PR by {pr_author}: {pr_url}\n" + + ( + f"PR #{pr['number']} by {pr['author_name']}: {pr['url']}\n" + if pr + else "No PR\n" + ) ) case Format.HTML: # TODO: render from the markdown below? @@ -120,9 +175,13 @@ def render_added_plugin(plugin: dict, format: Format) -> str: f'

{name} support has been added!

\n' "

\n" # TODO: f"Description: {plugin_description}
\n" - f'PR by {pr_author}\n' - "

\n" + f'PR #{pr['number']} by {pr['author_name']}\n' + if pr + else "
No PR\n" + ) + + "

\n" ) case Format.MARKDOWN: return ( @@ -130,7 +189,11 @@ def render_added_plugin(plugin: dict, format: Format) -> str: f"[{name}]({plugin_url}) support has been added!\n\n" # TODO: f"Description: {plugin_description}\n" f"[Documentation]({docs_url})\n" - # TODO: f'[PR]({pr_url}) by [{pr_author}](https://github.com/{pr_author})\n' + + ( + f'[PR \\#{pr['number']}]({pr['url']}) by [{pr['author_name']}]({pr['author_url']})\n' + if pr + else "No PR\n" + ) ) @@ -165,6 +228,15 @@ def flakeref(arg): help="the (old) flake ref to compare against", type=flakeref, ) + parser.add_argument( + "--head", + help="(optional) the current git commit, will default to using `git rev-parse HEAD`", + ) + parser.add_argument( + "--github-token", + dest="token", + help="(optional) github token, the GITHUB_TOKEN environment variable is used as a fallback", + ) parser.add_argument( "--compact", "-c", @@ -177,4 +249,12 @@ def flakeref(arg): help="produce raw data instead of message strings", action="store_true", ) - main(parser.parse_args()) + args = parser.parse_args() + + # Handle defaults lazily + if not args.token: + args.token = os.getenv("GITHUB_TOKEN") + if not args.head: + args.head = get_head_sha() + + main(args) From f8fe2c63b51d72953bd7315fca967c67c2f30867 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 17 Sep 2024 23:53:34 +0100 Subject: [PATCH 12/22] flesh out metadata --- flake-modules/dev/ci-new-plugin-matrix.nix | 1 + flake-modules/dev/ci-new-plugin-matrix.py | 82 ++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/flake-modules/dev/ci-new-plugin-matrix.nix b/flake-modules/dev/ci-new-plugin-matrix.nix index 0986ba6ef6..ca540de5b3 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.nix +++ b/flake-modules/dev/ci-new-plugin-matrix.nix @@ -8,6 +8,7 @@ ]; flakeIgnore = [ "E501" # Line length + "W503" # Line break before binary operator ]; } (builtins.readFile ./ci-new-plugin-matrix.py); }; diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index 2319bd3b13..ff9e7a4a35 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -65,6 +65,12 @@ def main(args) -> None: "author_url": pr["user"]["html_url"], } + # Expand the added plugins with additional metadata from the flake + if "added" in plugin_entries: + print("About to add meta to added plugins") + plugin_entries["added"] = get_plugin_meta(plugin_entries["added"]) + apply_fallback_descriptions(plugin_entries["added"], token=args.token) + # Unless `--raw`, we should produce formatted text for added plugins if not args.raw and "added" in plugin_entries: pr = plugin_entries.get("pr") or None @@ -116,10 +122,86 @@ def get_plugins(flake: str) -> list[str]: return {k: set(v) for k, v in json.loads(out).items()} +# Map a list of plugin entries, populating them with additional metadata +def get_plugin_meta(plugins: list[dict]) -> list[dict]: + expr = ( + "cfg: " + "with builtins; " + "let " + # Assume the json won't include any double-single-quotes: + f" plugins = fromJSON ''{json.dumps(plugins, separators=(",", ":"))}'';" + ' namespaces = ["plugins" "colorschemes"];' + "in " + "map ({name, namespace}: let " + " nixvimInfo = cfg.config.meta.nixvimInfo.${namespace}.${name} or {};" + " package = cfg.options.${namespace}.${name}.package.default; " + "in {" + " inherit name namespace;" + " inherit (nixvimInfo) url;" + ' description = package.meta.description or null;' + "}) plugins" + ) + cmd = [ + "nix", + "eval", + ".#nixvimConfiguration", + "--apply", + expr, + "--json", + ] + out = subprocess.check_output(cmd) + return json.loads(out) + + +# Walks the plugin list, fetching descriptions from github if missing +def apply_fallback_descriptions(plugins: list[dict], token: str): + gh_rxp = re.compile(r"^https?://github.com/(?P[^/]+)/(?P[^/]+)(?:[/#?].*)?$") + for plugin in plugins: + if plugin.get("description"): + continue + if m := gh_rxp.match(plugin["url"]): + plugin["description"] = ( + get_github_description( + owner=m.group("owner"), repo=m.group("repo"), token=token + ) + or None + ) + continue + plugin["description"] = None + + +# TODO: extract the HTTP request logic into a shared function +def get_github_description(owner: str, repo: str, token: str) -> str: + headers = { + "Accept": "application/vnd.github+json", + "X-GitHub-Api-Version": "2022-11-28", + } + if token: + headers["Authorization"] = f"Bearer {token}" + + res = requests.get( + url=f"https://api.github.com/repos/{owner}/{repo}", headers=headers + ) + + if res.status_code != 200: + try: + message = res.json()["message"] + except requests.exceptions.JSONDecodeError: + message = res.text + # FIXME: Maybe we should panic and fail CI? + print(f"{message} (HTTP {res.status_code})", file=stderr) + return None + + if data := res.json(): + return data["description"] + return None + + def get_head_sha() -> str: return subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip() +# TODO: extract the HTTP request logic into a shared function def get_pr(sha: str, repo: str, token: str = None) -> dict: headers = { "Accept": "application/vnd.github+json", From 5e59a9283fa41c49f1230974df29488fa4f917d5 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 17 Sep 2024 23:57:04 +0100 Subject: [PATCH 13/22] also report issues in workflow summary --- .github/workflows/new-plugin.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/new-plugin.yml b/.github/workflows/new-plugin.yml index fc7db71646..2588988ac3 100644 --- a/.github/workflows/new-plugin.yml +++ b/.github/workflows/new-plugin.yml @@ -110,6 +110,10 @@ jobs: $(echo "$json" | jq -r '.removed[] | "- \(.)"') " + # Markdown summary + echo "$body" >> $GITHUG_STEP_SUMMARY + + # PR comment gh pr comment "$num" \ --repo '${{ github.repository }}' \ --body "$body" From cdf709d1de87f8ee6779be9604d159d83b5c69c1 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 17 Sep 2024 23:59:29 +0100 Subject: [PATCH 14/22] remove old TODO --- flake-modules/dev/ci-new-plugin-matrix.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index ff9e7a4a35..fcb7b373de 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -38,9 +38,6 @@ def main(args) -> None: # Flatten the above dict into a list of entries; # each with 'name' and 'namespace' keys - # TODO: add additional metadata to each entry, such as the `originalName`, - # `pkg.meta.description`, etc - # Maybe we can use a `Plugin` class for this? plugin_entries = { action: [ {"name": name, "namespace": namespace} @@ -155,7 +152,9 @@ def get_plugin_meta(plugins: list[dict]) -> list[dict]: # Walks the plugin list, fetching descriptions from github if missing def apply_fallback_descriptions(plugins: list[dict], token: str): - gh_rxp = re.compile(r"^https?://github.com/(?P[^/]+)/(?P[^/]+)(?:[/#?].*)?$") + gh_rxp = re.compile( + r"^https?://github.com/(?P[^/]+)/(?P[^/]+)(?:[/#?].*)?$" + ) for plugin in plugins: if plugin.get("description"): continue From 1bdfcb5cff2228d41a512bd9b61c1a8b4051a0dc Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 18 Sep 2024 00:09:40 +0100 Subject: [PATCH 15/22] include url & description in message render --- flake-modules/dev/ci-new-plugin-matrix.py | 26 +++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index fcb7b373de..bd94e494ca 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -232,7 +232,7 @@ def render_added_plugin(plugin: dict, pr: dict, format: Format) -> str: name = plugin["name"] namespace = plugin["namespace"] kind = namespace[:-1] - plugin_url = "TODO" # TODO + plugin_url = plugin["url"] docs_url = f"https://nix-community.github.io/nixvim/{namespace}/{name}/index.html" match format: @@ -240,8 +240,12 @@ def render_added_plugin(plugin: dict, pr: dict, format: Format) -> str: return ( f"[{icons[kind]} NEW {kind.upper()}]\n\n" f"{name} support has been added!\n\n" - # TODO: f"Description: {plugin_description}" - f"URL: {plugin_url}" + + ( + f"Description: {desc}\n" + if (desc := plugin.get("description")) + else "" + ) + + f"URL: {plugin_url}" f"Docs: {docs_url}\n" + ( f"PR #{pr['number']} by {pr['author_name']}: {pr['url']}\n" @@ -255,8 +259,12 @@ def render_added_plugin(plugin: dict, pr: dict, format: Format) -> str: f"

[{icons[kind]} NEW {kind.upper()}]

\n" f'

{name} support has been added!

\n' "

\n" - # TODO: f"Description: {plugin_description}
\n" - f'\n" + if (desc := plugin.get("description")) + else "" + ) + + f'PR #{pr['number']} by {pr['author_name']}\n' if pr @@ -268,8 +276,12 @@ def render_added_plugin(plugin: dict, pr: dict, format: Format) -> str: return ( f"\\[{icons[kind]} NEW {kind.upper()}\\]\n\n" f"[{name}]({plugin_url}) support has been added!\n\n" - # TODO: f"Description: {plugin_description}\n" - f"[Documentation]({docs_url})\n" + + ( + f"Description: {desc}\n" + if (desc := plugin.get("description")) + else "" + ) + + f"[Documentation]({docs_url})\n" + ( f'[PR \\#{pr['number']}]({pr['url']}) by [{pr['author_name']}]({pr['author_url']})\n' if pr From 1084983cee0dbbf199dd4f6d342b495822da9600 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 18 Sep 2024 00:25:59 +0100 Subject: [PATCH 16/22] ci/new-plugins: use the plugin's `originalName` --- docs/mdbook/default.nix | 6 +++--- flake-modules/dev/ci-new-plugin-matrix.py | 9 +++++---- lib/neovim-plugin.nix | 2 +- lib/vim-plugin.nix | 2 +- modules/misc/nixvim-info.nix | 12 +++++++----- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/docs/mdbook/default.nix b/docs/mdbook/default.nix index 93d3585f59..b2fa803069 100644 --- a/docs/mdbook/default.nix +++ b/docs/mdbook/default.nix @@ -63,13 +63,13 @@ let maintToMD = m: if m ? github then "[${m.name}](https://github.com/${m.github})" else m.name; in # Make sure this path has a valid info attrset - if info ? file && info ? description && info ? url then + if info._type or null == "nixvimInfo" then "# ${lib.last path}\n\n" - + (lib.optionalString (info.url != null) "**URL:** [${info.url}](${info.url})\n\n") + + (lib.optionalString (info.url or null != null) "**URL:** [${info.url}](${info.url})\n\n") + (lib.optionalString ( maintainers != [ ] ) "**Maintainers:** ${lib.concatStringsSep ", " maintainersNames}\n\n") - + lib.optionalString (info.description != null) '' + + lib.optionalString (info.description or null != null) '' --- diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index bd94e494ca..e17b418266 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -134,7 +134,7 @@ def get_plugin_meta(plugins: list[dict]) -> list[dict]: " package = cfg.options.${namespace}.${name}.package.default; " "in {" " inherit name namespace;" - " inherit (nixvimInfo) url;" + " inherit (nixvimInfo) originalName url;" ' description = package.meta.description or null;' "}) plugins" ) @@ -230,6 +230,7 @@ def get_pr(sha: str, repo: str, token: str = None) -> dict: def render_added_plugin(plugin: dict, pr: dict, format: Format) -> str: name = plugin["name"] + display_name = plugin["originalName"] namespace = plugin["namespace"] kind = namespace[:-1] plugin_url = plugin["url"] @@ -239,7 +240,7 @@ def render_added_plugin(plugin: dict, pr: dict, format: Format) -> str: case Format.PLAIN: return ( f"[{icons[kind]} NEW {kind.upper()}]\n\n" - f"{name} support has been added!\n\n" + f"{display_name} support has been added!\n\n" + ( f"Description: {desc}\n" if (desc := plugin.get("description")) @@ -257,7 +258,7 @@ def render_added_plugin(plugin: dict, pr: dict, format: Format) -> str: # TODO: render from the markdown below? return ( f"

[{icons[kind]} NEW {kind.upper()}]

\n" - f'

{name} support has been added!

\n' + f'

{display_name} support has been added!

\n' "

\n" + ( f"Description: {desc}
\n" @@ -275,7 +276,7 @@ def render_added_plugin(plugin: dict, pr: dict, format: Format) -> str: case Format.MARKDOWN: return ( f"\\[{icons[kind]} NEW {kind.upper()}\\]\n\n" - f"[{name}]({plugin_url}) support has been added!\n\n" + f"[{display_name}]({plugin_url}) support has been added!\n\n" + ( f"Description: {desc}\n" if (desc := plugin.get("description")) diff --git a/lib/neovim-plugin.nix b/lib/neovim-plugin.nix index fce2c0a7fe..85133f15b2 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -66,7 +66,7 @@ meta = { inherit maintainers; nixvimInfo = { - inherit description; + inherit description originalName; url = args.url or opt.package.default.meta.homepage; path = [ namespace diff --git a/lib/vim-plugin.nix b/lib/vim-plugin.nix index c7c9406d69..335a5090d4 100644 --- a/lib/vim-plugin.nix +++ b/lib/vim-plugin.nix @@ -66,7 +66,7 @@ meta = { inherit maintainers; nixvimInfo = { - inherit description; + inherit description originalName; url = args.url or opt.package.default.meta.homepage; path = [ namespace diff --git a/modules/misc/nixvim-info.nix b/modules/misc/nixvim-info.nix index 219f9202ac..e135a96540 100644 --- a/modules/misc/nixvim-info.nix +++ b/modules/misc/nixvim-info.nix @@ -25,11 +25,13 @@ ( acc: def: lib.recursiveUpdate acc ( - lib.setAttrByPath def.value.path { - inherit (def) file; - url = def.value.url or null; - description = def.value.description or null; - } + lib.setAttrByPath def.value.path ( + { + inherit (def) file; + _type = "nixvimInfo"; + } + // builtins.removeAttrs def.value [ "path" ] + ) ) ) { From 46007c9f9caa3c1a782ace465387b6cf1a5cfce8 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 18 Sep 2024 00:28:33 +0100 Subject: [PATCH 17/22] ci: drop `or {}` from nixvimInfo lookup --- flake-modules/dev/ci-new-plugin-matrix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index e17b418266..145b1e8c99 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -130,7 +130,7 @@ def get_plugin_meta(plugins: list[dict]) -> list[dict]: ' namespaces = ["plugins" "colorschemes"];' "in " "map ({name, namespace}: let " - " nixvimInfo = cfg.config.meta.nixvimInfo.${namespace}.${name} or {};" + " nixvimInfo = cfg.config.meta.nixvimInfo.${namespace}.${name};" " package = cfg.options.${namespace}.${name}.package.default; " "in {" " inherit name namespace;" From 020c371b63d5c1a872f1e1f6b7c63d0bddb49b6b Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 18 Sep 2024 00:30:44 +0100 Subject: [PATCH 18/22] fixup! ci/new-plugins: use the plugin's `originalName` --- flake-modules/dev/ci-new-plugin-matrix.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index 145b1e8c99..4d4a7e1570 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -134,7 +134,8 @@ def get_plugin_meta(plugins: list[dict]) -> list[dict]: " package = cfg.options.${namespace}.${name}.package.default; " "in {" " inherit name namespace;" - " inherit (nixvimInfo) originalName url;" + " inherit (nixvimInfo) url;" + " display_name = nixvimInfo.originalName or name;" ' description = package.meta.description or null;' "}) plugins" ) @@ -230,7 +231,7 @@ def get_pr(sha: str, repo: str, token: str = None) -> dict: def render_added_plugin(plugin: dict, pr: dict, format: Format) -> str: name = plugin["name"] - display_name = plugin["originalName"] + display_name = plugin["display_name"] namespace = plugin["namespace"] kind = namespace[:-1] plugin_url = plugin["url"] From a10c785fe571af640a8b6e58756ef3c54059ca33 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 18 Sep 2024 00:36:08 +0100 Subject: [PATCH 19/22] fixup: cleanup some leftovers in ci workflow --- .github/workflows/new-plugin.yml | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/.github/workflows/new-plugin.yml b/.github/workflows/new-plugin.yml index 2588988ac3..f4d858e008 100644 --- a/.github/workflows/new-plugin.yml +++ b/.github/workflows/new-plugin.yml @@ -52,10 +52,6 @@ jobs: plain: ${{ matrix.added.plain }} html: ${{ matrix.added.html }} markdown: ${{ matrix.added.markdown }} - pr_number: ${{ fromJSON(needs.setup.outputs.json).pr.number }} - pr_url: ${{ fromJSON(needs.setup.outputs.json).pr.url }} - pr_author_name: ${{ fromJSON(needs.setup.outputs.json).pr.author_name }} - pr_author_url: ${{ fromJSON(needs.setup.outputs.json).pr.author_url }} steps: - name: Install matrix-msg tool @@ -68,11 +64,6 @@ jobs: - name: Send message and print summary run: | - # Message text; plain-text & html - # TODO: format as-per existing announcements - # See available env-vars above - msg="Hello, world!" - # stdout echo "$plain" @@ -80,8 +71,12 @@ jobs: echo "$markdown" >> $GITHUG_STEP_SUMMARY # matrix message - matrix-msg "$plain" "$html" - # TODO: update stdout/step_summary with msg success/failure + if matrix-msg "$plain" "$html" + then + echo "Matrix message sent successfully" >> $GITHUG_STEP_SUMMARY + else + echo "Matrix message failed" >> $GITHUG_STEP_SUMMARY + fi report: name: Report removed plugins From 027c9d9ecf7f1f449207cb55bc145653e9dd8cde Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 18 Sep 2024 00:38:20 +0100 Subject: [PATCH 20/22] add an `hr` to the workflow summary --- .github/workflows/new-plugin.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/new-plugin.yml b/.github/workflows/new-plugin.yml index f4d858e008..39b1fbb869 100644 --- a/.github/workflows/new-plugin.yml +++ b/.github/workflows/new-plugin.yml @@ -69,6 +69,7 @@ jobs: # markdown summary echo "$markdown" >> $GITHUG_STEP_SUMMARY + echo -e "\n---\n" >> $GITHUG_STEP_SUMMARY # matrix message if matrix-msg "$plain" "$html" From efc7089d5c1fe1b826ee79af793bf8632af39cf0 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 18 Sep 2024 00:41:17 +0100 Subject: [PATCH 21/22] remove unused assignment in nix expr --- flake-modules/dev/ci-new-plugin-matrix.py | 1 - 1 file changed, 1 deletion(-) diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index 4d4a7e1570..a9e49d54d3 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -127,7 +127,6 @@ def get_plugin_meta(plugins: list[dict]) -> list[dict]: "let " # Assume the json won't include any double-single-quotes: f" plugins = fromJSON ''{json.dumps(plugins, separators=(",", ":"))}'';" - ' namespaces = ["plugins" "colorschemes"];' "in " "map ({name, namespace}: let " " nixvimInfo = cfg.config.meta.nixvimInfo.${namespace}.${name};" From 0b73fcd805cf02a127160bde26f8001fa766ee1c Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 18 Sep 2024 00:43:11 +0100 Subject: [PATCH 22/22] add fallbacks to `url` metadata --- flake-modules/dev/ci-new-plugin-matrix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake-modules/dev/ci-new-plugin-matrix.py b/flake-modules/dev/ci-new-plugin-matrix.py index a9e49d54d3..07ac61b3ce 100644 --- a/flake-modules/dev/ci-new-plugin-matrix.py +++ b/flake-modules/dev/ci-new-plugin-matrix.py @@ -133,7 +133,7 @@ def get_plugin_meta(plugins: list[dict]) -> list[dict]: " package = cfg.options.${namespace}.${name}.package.default; " "in {" " inherit name namespace;" - " inherit (nixvimInfo) url;" + " url = nixvimInfo.url or package.meta.homepage or null;" " display_name = nixvimInfo.originalName or name;" ' description = package.meta.description or null;' "}) plugins"