diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 7c2f7ba..8050b69 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -17,7 +17,7 @@ _Replace the example values below with your real details._ |---|---| | **Shop name** | Your shop name | | **Website** | https://yourshop.com | -| **Region** | Your region | +| **Region** | Europe / North America / South America / Asia Pacific / Middle East / Africa / India | | **Where to find you in the community** | Your X, Discord, Instagram, TikTok, Nostr, or other public link (PR context only; JSON `social` supports only `x`, `instagram`, `youtube`, `tiktok`, `nostr`) | --- diff --git a/.github/workflows/validate-vendor.yml b/.github/workflows/validate-vendor.yml index f7a4455..ac4fa1c 100644 --- a/.github/workflows/validate-vendor.yml +++ b/.github/workflows/validate-vendor.yml @@ -13,7 +13,7 @@ permissions: jobs: validate: - name: Validate schema, slug & logo + name: Validate schema, slug, and logos runs-on: ubuntu-latest steps: - name: Checkout @@ -23,102 +23,10 @@ jobs: uses: actions/setup-node@v5 with: node-version: 22 + cache: npm - - name: Install validators - run: npm install -g ajv-cli@5.0.0 ajv-formats@3.0.1 + - name: Install dependencies + run: npm ci - - name: Validate vendors directory filenames - run: | - ERRORS=0 - - for f in vendors/*; do - [ -f "$f" ] || continue - base=$(basename "$f") - [[ "$base" == _* ]] && continue - - if [[ "$base" != *.json ]]; then - echo "::error file=$f::Invalid vendor filename. Vendor files must end with .json" - ERRORS=$((ERRORS + 1)) - continue - fi - - if [[ ! "$base" =~ ^[a-z0-9]+(-[a-z0-9]+)*\.json$ ]]; then - echo "::error file=$f::Invalid vendor filename. Use lowercase letters, numbers, and single hyphens only" - ERRORS=$((ERRORS + 1)) - fi - done - - if [ "$ERRORS" -gt 0 ]; then - echo "::error::$ERRORS invalid vendor filename(s) found." - exit 1 - fi - - - name: Validate each vendor JSON - run: | - ERRORS=0 - - for f in vendors/*.json; do - # Skip internal files (_schema.json, _example.json, etc.) - [[ "$(basename "$f")" == _* ]] && continue - - echo "" - echo "━━━ Checking: $f ━━━" - - # 1. JSON schema validation - if ! ajv validate -s vendors/_schema.json -d "$f" -c ajv-formats --strict=false; then - echo "::error file=$f::Schema validation failed" - ERRORS=$((ERRORS + 1)) - continue - fi - - # 2. Slug must match filename - FILE_ERRORS=0 - slug=$(jq -r '.slug' "$f") - expected=$(basename "$f" .json) - if [ "$slug" != "$expected" ]; then - echo "::error file=$f::Slug '$slug' does not match filename — rename the file to '$slug.json' or change the slug to '$expected'" - ERRORS=$((ERRORS + 1)) - FILE_ERRORS=$((FILE_ERRORS + 1)) - fi - - # 3. Logo filename must match slug - logo=$(jq -r '.logo' "$f") - logo_filename="$logo" - logo_stem="${logo_filename%.*}" - if [ "$logo_stem" != "$slug" ]; then - echo "::error file=$f::Logo filename '$logo_stem' does not match slug '$slug'" - ERRORS=$((ERRORS + 1)) - FILE_ERRORS=$((FILE_ERRORS + 1)) - fi - - # 4. Logo file must exist - logo_path="logos/$logo" - if [ ! -f "$logo_path" ]; then - echo "::error file=$f::Logo not found: $logo_path" - ERRORS=$((ERRORS + 1)) - FILE_ERRORS=$((FILE_ERRORS + 1)) - else - # 5. Logo must be ≤ 200 KB - size=$(stat -c%s "$logo_path" 2>/dev/null || stat -f%z "$logo_path") - if [ "$size" -gt 204800 ]; then - echo "::error file=$f::Logo exceeds 200 KB (${size} bytes) — please compress it" - ERRORS=$((ERRORS + 1)) - FILE_ERRORS=$((FILE_ERRORS + 1)) - else - echo "✓ Logo OK (${size} bytes)" - fi - fi - - if [ "$FILE_ERRORS" -eq 0 ]; then - echo "✓ $f is valid" - fi - done - - if [ "$ERRORS" -gt 0 ]; then - echo "" - echo "::error::$ERRORS validation error(s) found. Please fix them before merging." - exit 1 - fi - - echo "" - echo "✅ All vendor files are valid!" + - name: Run repository validator + run: npm run validate diff --git a/scripts/validate-all.mjs b/scripts/validate-all.mjs index cb74949..00f9c69 100644 --- a/scripts/validate-all.mjs +++ b/scripts/validate-all.mjs @@ -41,7 +41,14 @@ for (const file of allVendorEntries) { for (const file of files) { const filePath = path.join(vendorsDir, file) - const data = JSON.parse(fs.readFileSync(filePath, "utf-8")) + let data + try { + data = JSON.parse(fs.readFileSync(filePath, "utf-8")) + } catch (err) { + console.error(`❌ ${file} — Invalid JSON: ${err.message}`) + errors++ + continue + } const valid = validate(data) if (!valid) {