ci: validate renovate #17
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 | |
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: $(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" | |
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 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}" |