ci: validate renovate #31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
# shellcheck disable=SC1078 | |
echo 'd="$(mktemp)"' >> "$COMMENT_BUFFER" | |
# patch body to temporary file: | |
# cat << $sep | |
# ${DIFF_TO_BE_REPORTED}.diff | |
# $sep > "$d" | |
printf 'cat > "%s"\n' '$d' >> "$COMMENT_BUFFER" | |
printf ' <<' >> "$COMMENT_BUFFER" | |
printf '%s\n' "$sep" >> "$COMMENT_BUFFER" | |
cat "${DIFF_TO_BE_REPORTED}.diff" >> "$COMMENT_BUFFER" | |
printf "$sep" >> "$COMMENT_BUFFER" | |
printf '\n' | |
# 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}" |