-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (60 loc) · 2.26 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
name: validate renovate
on:
pull_request:
paths:
- 'renovate.json'
- '.github/workflows/validate-renovate.yml'
permissions:
contents: read
issues: write
jobs:
lint:
name: run renovate-config-validator
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: run lint
id: lint
run: |
# renovate: npm:renovate
ver="37.291.0"
# pinned on exact version
package="renovate@=$ver"
echo "npx: $(pnpx --version)"
echo "installing: $package..."
export H="$(mktemp)"
echo '{' >> "$H"
# let's do main part, but avoid pipefail
(pnpx --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"
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"
GIT_TRACE=1 git diff --no-index "$OLD.old.txt" "$NEW.new.txt" >> "${DIFF_TO_BE_REPORTED}.diff"
echo "uploading"
printf 'DIFF=%s' "$(cat "${DIFF_TO_BE_REPORTED}.diff")" >> "$GITHUB_OUTPUT"
- name: report diff
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DIFF_TEXT: ${{ steps.lint.outputs.DIFF }}
URL: ${{ github.event.pull_request.html_url }}
run: |
COMMENT_BUFFER="$(mktemp)"
printf "I'm sorry, but this config should be migrated. Please apply following patch file to proceed:" >> "$COMMENT_BUFFER"
printf '```diff' >> "$COMMENT_BUFFER"
cat "$DIFF_TEXT" >> "$COMMENT_BUFFER"
printf '```' >> "$COMMENT_BUFFER"
gh pr comment -F "$COMMENT_BUFFER" "${URL}"