generated from NuschtOS/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
60 lines (53 loc) · 2.13 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: post-compare-link
description: "Post compare link when flake.lock changes"
branding:
color: purple
icon: edit-3
inputs:
debug:
description: Turn on set -x for debugging
required: false
default: false
runs:
using: composite
steps:
- name: Install nix
uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixpkgs-unstable
- name: Generate comment from changed flake.lock file
shell: bash
env:
DEBUG: ${{ inputs.debug }}
run: |
export PATH="$PATH:$(nix-build --expr 'with import <nixpkgs> { }; buildEnv { name = "PATH"; paths = [python3Packages.jsonpatch]; }')/bin"
if [[ $DEBUG != false ]]; then
set -x
DEBUG_CMD="set -x;"
fi
echo "flake.lock compare links:" > comment.md
before_flake_lock="$(mktemp)"
git show "origin/$GITHUB_BASE_REF:flake.lock" > "$before_flake_lock"
# when debugging, remove extra escape before dollars in xargs
(jsondiff "$before_flake_lock" flake.lock || true) | jq -c '.[] | select(.path|endswith("/rev"))' | \
xargs -d'\n' -n1 bash -c "$DEBUG_CMD"'in="$1"; \
locked="$(echo "$in" | jq -r .path | sed -e "s|^/|.\"|" -e "s/\(.\)\//\1\"\.\"/g" -e "s|\.\"rev$||g")"; \
old_rev="$(jq -r "$locked.rev" '"$before_flake_lock"')"; \
new_rev="$(echo "$in" | jq -r .value)"; \
path="$(jq -r "$locked | \"\(if .type == \"github\" then \"https://\(.host // \"github.com\")/\(.owner)/\(.repo)\" else if .type == \"git\" then .url | sub(\".git$\"; \"\") else \"error\" end end)/compare\"" flake.lock)"; \
echo "- $path/$old_rev...$new_rev" \
' "" >> comment.md
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: flake.lock compare links
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: 'comment.md'
edit-mode: replace