Skip to content

Instantly share code, notes, and snippets.

@sheldonhull
Last active March 29, 2024 17:23
Show Gist options
  • Save sheldonhull/ad1aaa06d404ba5a7d9d165f2125c946 to your computer and use it in GitHub Desktop.
Save sheldonhull/ad1aaa06d404ba5a7d9d165f2125c946 to your computer and use it in GitHub Desktop.
renovate-config-validator helps improve renovate config check to only run on certain changed files since it's slow
#!/usr/bin/env bash
# If npm global install package renovate is not found then install `npm install --global renovate`
if ! command -v renovate-config-validator &>/dev/null; then
echo "renovate-config-validator could not be found, installing..."
npm install --global renovate
fi
# Define an array of JSON files to validate
json_files=(
"packagerules-group-always.json"
"packagerules-disable-managers.json"
"packagerules-nuget-group.json"
"security.json"
"common.json"
"default.json"
"default-feeds.json"
)
change_found=false
# Iterate through the array of files
for file in "${json_files[@]}"; do
# Check if the file has been modified
if git diff --name-only --cached | grep -q "$file"; then
change_found=true
break # Exit the loop as soon as a change is detected
fi
done
# Check the flag and act accordingly
if [ "$change_found" = true ]; then
echo "⚙️ Change detected in specified files. proceeding..."
else
echo "- no changes detected in specified files, bypassing renovate-config-validator"
exit 0 # Exit with status 0 as no relevant changes were found
fi
# Loop through each JSON file and run the config validator
for file in "${json_files[@]}"; do
renovate-config-validator "$file"
if [[ $? -ne 0 ]]; then
# If the validator returns a non-zero exit code, exit with a 1
echo "❌ $file failed validation"
exit 1
fi
echo "✅ $file passed validation"
done
# If all validators pass, exit with a 0
exit 0
actions:
enabled:
- trunk-check-pre-commit
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
- trunk-upgrade-available
- renovate-config-validator
definitions:
- id: renovate-config-validator
description: Validate the config.
interactive: false
enabled: true
triggers:
- git_hooks:
- pre-commit
run: .trunk/renovate-config-validator.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment