Skip to content

Merge pull request #9 from b-harvest/feat/somnia-foundation #24

Merge pull request #9 from b-harvest/feat/somnia-foundation

Merge pull request #9 from b-harvest/feat/somnia-foundation #24

name: Validator Profile Validation
on:
pull_request:
branches:
- main
- master
paths:
- 'testnet/**/*.json'
- 'mainnet/**/*.json'
- 'validate.js'
- '.github/workflows/validate-profiles.yml'
push:
branches:
- main
- master
paths:
- 'testnet/**/*.json'
- 'mainnet/**/*.json'
- 'validate.js'
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Run validation script
run: node validate.js
- name: Comment PR on failure
if: failure() && github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issue_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: '❌ **Validation Failed**\n\nYour validator profile has validation errors. Please check the workflow logs for details.\n\n**Common issues:**\n- Filename must be all lowercase\n- Required fields: moniker, details, profile, contact.email, contact.website\n- Image paths must start with `./images/` or `./background/`\n- Referenced image files must exist'
});
- name: Comment PR on success
if: success() && github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issue_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: '✅ **Validation Passed**\n\nYour validator profile has been successfully validated!'
});
check-filenames:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check for uppercase filenames (PR)
if: github.event_name == 'pull_request'
run: |
echo "Checking for uppercase filenames in testnet/ and mainnet/..."
# Fetch the base branch to ensure we have all necessary commits
git fetch origin ${{ github.base_ref }}
# Get all changed files in the entire PR (comparing base branch to PR head)
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
echo "Changed files in PR:"
echo "$CHANGED_FILES"
UPPERCASE_FILES=""
for file in $CHANGED_FILES; do
if [[ $file == testnet/*.json ]] || [[ $file == mainnet/*.json ]]; then
filename=$(basename "$file")
if [[ "$filename" != "validator-template.json" ]] && [[ "$filename" != "${filename,,}" ]]; then
UPPERCASE_FILES="$UPPERCASE_FILES\n - $file (should be: $(dirname $file)/${filename,,})"
fi
fi
done
if [ ! -z "$UPPERCASE_FILES" ]; then
echo "❌ Found files with uppercase characters:"
echo -e "$UPPERCASE_FILES"
exit 1
else
echo "✅ All filenames are lowercase"
fi
- name: Check for uppercase filenames (Push)
if: github.event_name == 'push'
run: |
echo "Checking all JSON filenames in testnet/ and mainnet/..."
UPPERCASE_FILES=""
for file in testnet/*.json mainnet/*.json; do
if [ -f "$file" ]; then
filename=$(basename "$file")
if [[ "$filename" != "validator-template.json" ]] && [[ "$filename" != "${filename,,}" ]]; then
UPPERCASE_FILES="$UPPERCASE_FILES\n - $file (should be: $(dirname $file)/${filename,,})"
fi
fi
done
if [ ! -z "$UPPERCASE_FILES" ]; then
echo "❌ Found files with uppercase characters:"
echo -e "$UPPERCASE_FILES"
exit 1
else
echo "✅ All filenames are lowercase"
fi
validation-status:
runs-on: ubuntu-latest
needs: [validate, check-filenames]
if: always()
steps:
- name: Set validation status
run: |
if [ "${{ needs.validate.result }}" == "success" ] && [ "${{ needs.check-filenames.result }}" == "success" ]; then
echo "✅ All checks passed"
exit 0
else
echo "❌ Validation failed"
exit 1
fi