From dea2d9e473ffcc34198ea8601a233664643751f1 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Tue, 19 Nov 2024 14:35:29 -0600 Subject: [PATCH] support key-val hosts --- .github/workflows/build.yml | 2 +- .github/workflows/update.yml | 14 +++++++++++--- pkgs/oizys/default.nix | 2 +- pkgs/oizys/nimble.lock | 4 ++-- pkgs/oizys/src/oizys.nim | 20 +++++++++++++++----- pkgs/oizys/src/oizys/github.nim | 5 +++-- 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 189c4e5..3b7b847 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,7 +41,7 @@ jobs: - uses: ./.github/actions/nix with: attic_token: ${{ secrets.ATTIC_TOKEN }} - clean: true + # clean: true btrfs: true - name: write lock file diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index a0e3260..4a10265 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -2,6 +2,13 @@ name: Flake Update / Build on: workflow_dispatch: + inputs: + hosts: + description: 'list of hosts to build' + required: true + default: 'othalan,algiz' + type: string + schedule: # At minute 00:00 on Monday, Wednesday, and Friday. - cron: 0 0 * * 1,3,5 @@ -51,7 +58,7 @@ jobs: nix run . -- cache - --host,=",othalan,algiz" + --host,="${{ inputs.hosts }}" --flake . --debug -- @@ -94,7 +101,7 @@ jobs: nix run . -- ci update - --host,=othalan,algiz,mannaz,naudiz + --host,="${{ inputs.hosts }}" --flake . --debug -- @@ -102,7 +109,8 @@ jobs: - run: | echo "# system diffs" >> $GITHUB_STEP_SUMMARY - for host in othalan algiz mannaz naudiz; do + hosts="${{ inputs.hosts }}" + for host in ${hosts//,/ }; do echo "## $host" >> $GITHUB_STEP_SUMMARY nix run "nixpkgs#nvd" -- --color always diff ./$host-current ./$host-updated >> $host-summary.md printf '```\n%s\n```\n' "$(nix run "nixpkgs#nvd" -- diff ./$host-current ./$host-updated)" >> $GITHUB_STEP_SUMMARY diff --git a/pkgs/oizys/default.nix b/pkgs/oizys/default.nix index 914f257..57ff330 100644 --- a/pkgs/oizys/default.nix +++ b/pkgs/oizys/default.nix @@ -8,7 +8,7 @@ buildNimblePackage { verions = "unstable"; src = lib.cleanSource ./.; nativeBuildInputs = [ openssl ]; - nimbleDepsHash = "sha256-1YoGvWvoJJSMauDbeH8ZHuK+QQot48Mkye9TeWteT8k="; + nimbleDepsHash = "sha256-IWdlWC+j2h15WjVXXdDyxDZsb0/Ti1+jy6RfmqHFkjs="; meta = { description = "nix begat oizys"; diff --git a/pkgs/oizys/nimble.lock b/pkgs/oizys/nimble.lock index 6b88463..3babe60 100644 --- a/pkgs/oizys/nimble.lock +++ b/pkgs/oizys/nimble.lock @@ -3,12 +3,12 @@ "packages": { "hwylterm": { "version": "0.1.0", - "vcsRevision": "c5f70cec4e40ba396f59162e98c359a1a1ea4fe1", + "vcsRevision": "ef573dc0f8bf39f80704f92cfab39e1b9af82492", "url": "https://github.com/daylinmorgan/hwylterm", "downloadMethod": "git", "dependencies": [], "checksums": { - "sha1": "5727969a8e82e29a7581c13cc7cc45996dbca5a1" + "sha1": "ccb51201898b5e913ffee1e18bdf4d9fc4004386" } }, "jsony": { diff --git a/pkgs/oizys/src/oizys.nim b/pkgs/oizys/src/oizys.nim index 8170b03..618846a 100644 --- a/pkgs/oizys/src/oizys.nim +++ b/pkgs/oizys/src/oizys.nim @@ -1,5 +1,5 @@ ## nix begat oizys -import std/[os, osproc, sequtils, strformat, strutils] +import std/[os, osproc, sequtils, strformat, strutils, tables] import hwylterm, hwylterm/[hwylcli] import oizys/[context, github, nix, logging] @@ -77,17 +77,27 @@ hwylCli: ciUpdate(args) [gha] - ... "trigger GHA" + ... """ + trigger GHA + + examples: + [b]oizys gha update[/] --input:hosts:othalan,algiz,mannaz + """ flags: - # make a key/value input that is passed to workflows and encoded in json - # i.e. --input:ref:main + input: + T seq[KVString] + ? "inputs for dispatch" `ref`: T string ? "git ref/branch/tag to trigger workflow on" * "main" run: + # TODO: support file operations like gh + # i.e. @flake.lock means read a file a flake.lock and use it's contents if args.len == 0: fatalQuit "expected workflow file name" - createDispatch(args[0], `ref`) + let inputs = + input.mapIt((it.key, it.val)).toTable() + createDispatch(args[0], `ref`, inputs) [dry] ... "dry run build" diff --git a/pkgs/oizys/src/oizys/github.nim b/pkgs/oizys/src/oizys/github.nim index 033056f..471b59e 100644 --- a/pkgs/oizys/src/oizys/github.nim +++ b/pkgs/oizys/src/oizys/github.nim @@ -100,13 +100,14 @@ proc getInProgressRun( warn "timeout reached waiting for workflow to start" -proc createDispatch*(workflowFileName: string, `ref`: string) = +proc createDispatch*(workflowFileName: string, `ref`: string, inputs: Table[string, string]) = ## https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event let workflow = if workflowFileName.endsWith(".yml") or workflowFileName.endsWith(".yaml"): workflowFileName else: workflowFileName & ".yml" - let body = %*{"ref": `ref`} + let body = %*{"ref": `ref`, "inputs": inputs} info fmt"creating dispatch event for {workflow}" + debug "with body: " & $body postGhApi( fmt"https://api.github.com/repos/daylinmorgan/oizys/actions/workflows/{workflow}/dispatches", body