From f158f6e4119401c23401ab47967f0ef4a0dbeebf Mon Sep 17 00:00:00 2001 From: Philipp Hochkamp Date: Mon, 28 Mar 2022 18:41:31 +0200 Subject: [PATCH] ci test --- .github/flake-to-md.awk | 131 ++++++++++++++++++++++++++++++++++ .github/workflows/update.yaml | 11 +-- 2 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 .github/flake-to-md.awk diff --git a/.github/flake-to-md.awk b/.github/flake-to-md.awk new file mode 100644 index 00000000..f2cba472 --- /dev/null +++ b/.github/flake-to-md.awk @@ -0,0 +1,131 @@ +# Parses a flake lock update commit and output readable markdown with proper +# https://github.com/sandhose/nixconf/blob/master/misc/flake-to-markdown.awk +# compare links + +function unquote (str) { + split(str, arr, "'"); + return arr[2]; +} + +function parse_flakeref (flakeref, res) { + split(flakeref, arr, ":"); + type = arr[1]; + tmp = arr[2]; + split(tmp, arr, "?"); + tmp = arr[1]; + n = split(tmp, arr, "/"); + commit = arr[n]; + repo = arr[1] + for (i = 2; i < n; i++) { + repo = repo "/" arr[i]; + } + + res["type"] = type; + res["commit"] = commit; + res["repo"] = repo; +} + +function short (sha) { + return substr(sha, 1, 8); +} + +# Show the raw output in a foldable section +BEGIN { + print "
Raw output

"; + print ""; + print "```"; +} + +# Print all lines anyway +{ print } + +# This is a "Updated input 'x'" ine +$3 ~ /input/ { + input = unquote($4); + operations[input] = $2; + next; +} + +# This is a "'type:foo/bar/1234' (2021-01-01)" line +$2 ~ /\(.*\)/ { + input_from[input] = unquote($1) + input_from_date[input] = substr($2, 2, 10); + next; +} + +# This is a "→ 'type:foo/bar/1234' (2021-01-01)" line +$3 ~ /\(.*\)/ { + input_to[input] = unquote($2) + input_to_date[input] = substr($3, 2, 10); + next; +} + +END { + print "```"; + print ""; + print "

"; + print ""; + + # Once we gathered the information we needed, we can show it properly + for (input in operations) { + operation = operations[input]; + details = ""; + link = ""; + + # For "updated" inputs, we have two flake refs + if (operation == "Updated") { + from = input_from[input]; + to = input_to[input]; + from_date = input_from_date[input] + to_date = input_to_date[input] + parse_flakeref(from, parsed_from); + parse_flakeref(to, parsed_to); + type = parsed_to["type"]; + repo = parsed_to["repo"]; + from_commit = parsed_from["commit"]; + to_commit = parsed_to["commit"]; + + compare = sprintf("`%s` ➡️ `%s`", short(from_commit), short(to_commit)); + # Render the details according to the ref type + if (type == "github") { + compare = sprintf("[%s](https://github.com/%s/compare/%s...%s)", compare, repo, from_commit, to_commit); + link = sprintf("https://github.com/%s", repo); + } else if (type == "gitlab") { + compare = sprintf("[%s](https://gitlab.com/%s/-/compare/%s...%s)", compare, repo, from_commit, to_commit); + link = sprintf("https://gitlab.com/%s", repo); + } + + details = sprintf("%s (%s to %s)", compare, from_date, to_date); + # For "added" inputs, we have one flake ref + } else if (operation == "Added") { + ref = input_from[input]; + parse_flakeref(ref, parsed_ref); + type = parsed_ref["type"]; + repo = parsed_ref["repo"]; + commit = parsed_ref["commit"]; + + # Render the details according to the ref type + if (type == "github") { + details = sprintf("[github.com/%s](https://github.com/%s/tree/%s/)", repo, repo, commit); + link = sprintf("https://github.com/%s", repo); + } else if (type == "gitlab") { + details = sprintf("[gitlab.com/%s](https://gitlab.com/%s/-/tree/%s/)", repo, repo, commit); + link = sprintf("https://gitlab.com/%s", repo); + } else { + details = sprintf("`%s`", ref); + } + } + + if (link) { + input_txt = sprintf("[`%s`](%s)", input, link); + } else { + input_txt = sprintf("`%s`", input); + } + + if (details) { + printf(" - %s input %s: %s\n", operation, input_txt, details); + } else { + printf(" - %s input %s.\n", operation, input_txt); + } + } +} diff --git a/.github/workflows/update.yaml b/.github/workflows/update.yaml index cbf0d3eb..6948e13e 100644 --- a/.github/workflows/update.yaml +++ b/.github/workflows/update.yaml @@ -21,7 +21,7 @@ jobs: - uses: cachix/install-nix-action@v16 with: - install_url: https://releases.nixos.org/nix/nix-2.4/install + install_url: https://releases.nixos.org/nix/nix-2.6.1/install extra_nix_config: | experimental-features = nix-command flakes access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} @@ -32,21 +32,22 @@ jobs: git config user.email 'noreply@github.com' - name: Update lock file - run: nix flake update --no-registries --commit-lock-file + run: nix flake update --no-use-registries --commit-lock-file - name: Get commit message id: commit run: | - message="$(git log -1 --pretty=%B | tail +3 | awk -f ./misc/flake-to-markdown.awk)" + message="$(git log -1 --pretty=%B | tail +3 | awk -f ./.github/flake-to-md.awk)" message="${message//'%'/'%25'}" message="${message//$'\n'/'%0A'}" message="${message//$'\r'/'%0D'}" echo "::set-output name=message::$message" - name: Create Pull Request - uses: peter-evans/create-pull-request@v3.14.0 + uses: peter-evans/create-pull-request@v4 with: token: "${{ steps.generate-token.outputs.token }}" title: "Automated Flake update" body: "${{ steps.commit.outputs.message }}" - delete-branch: truec + delete-branch: true + assignees: thexyno