-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (89 loc) · 3.42 KB
/
validate-renovate.yml
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: validate renovate
on:
pull_request:
paths:
- 'renovate.json'
- '.github/workflows/validate-renovate.yml'
permissions:
contents: read
pull-requests: write
jobs:
lint:
name: run renovate-config-validator
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: run lint and report
env:
URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ github.token }}
run: |
# renovate: npm:renovate
ver="37.291.0"
# pinned on exact version
package="renovate@=$ver"
echo "npx: $(npx --version)"
echo "installing: $package..."
export H="$(mktemp)"
echo '{' >> "$H"
# let's do main part, but avoid pipefail
(npx --yes --package "$package" -- renovate-config-validator --strict || true)\
| ruby -e 'File.open(ENV[?H], ?a) {|r| while gets; puts $_; $> = r if $_.strip == "WARN: Config migration necessary" ;end; }'
echo '}' >> "$H"
# exit early if migration is not required
if [ "$(wc -c "$H")" -eq 0 ]; then
exit 0
fi
echo "---"
echo "Collected output: $H"
cat "$H"
echo "---"
# init and extract
OLD="$(mktemp)"
mv "$OLD" "${OLD}.old.txt"
NEW="$(mktemp)"
mv "$NEW" "${NEW}.new.txt"
echo "extracting fields"
jq -r '.oldConfig' < "$H" > "${OLD}.old.txt"
jq -r '.newConfig' < "$H" > "${NEW}.new.txt"
DIFF_TO_BE_REPORTED="$(mktemp)"
mv "$DIFF_TO_BE_REPORTED" "${DIFF_TO_BE_REPORTED}.diff"
echo "computing diff"
# fold into $?=0 even if they are different:
# > This form implies --exit-code
GIT_TRACE=1 git diff --no-index "$OLD.old.txt" "$NEW.new.txt" >> "${DIFF_TO_BE_REPORTED}.diff" || true
COMMENT_BUFFER="$(mktemp)"
sep='EOS_SOMEWHAT_DUMMY_LINES'
echo "I'm sorry, but this config should be migrated. Please apply following patch file to proceed:" >> "$COMMENT_BUFFER"
echo '```sh >> "$COMMENT_BUFFER"
# header
echo '#!/bin/sh' >> "$COMMENT_BUFFER"
# make temporary
echo 'd="$(mktemp)"' >> "$COMMENT_BUFFER"
# patch body to temporary file:
# cat << $sep
# ${DIFF_TO_BE_REPORTED}.diff
# $sep > "$d"
printf 'cat <<' >> "$COMMENT_BUFFER"
printf '%s\n' "$sep" >> "$COMMENT_BUFFER"
cat "${DIFF_TO_BE_REPORTED}.diff" >> "$COMMENT_BUFFER"
printf "$sep" >> "$COMMENT_BUFFER"
printf '> "$d"\n' >> "$COMMENT_BUFFER"
# apply patch
echo 'patch -p1 < "$d"' >> "$COMMENT_BUFFER"
# close code-block
echo '```' >> "$COMMENT_BUFFER"
echo >> "$COMMENT_BUFFER"
echo '<details>' >> "$COMMENT_BUFFER"
echo >> "$COMMENT_BUFFER"
echo '<summary>Patch</summary>'
echo >> "$COMMENT_BUFFER"
echo '```patch' >> "$COMMENT_BUFFER"
cat "${DIFF_TO_BE_REPORTED}.diff" >> "$COMMENT_BUFFER"
echo '```' >> "$COMMENT_BUFFER"
echo >> "$COMMENT_BUFFER"
echo '</details>' >> "$COMMENT_BUFFER"
echo '--- [DEBUG] REPORTER ---'
cat "$COMMENT_BUFFER"
echo '------------------------'
gh pr comment -F "$COMMENT_BUFFER" "${URL}"