Skip to content

Commit 613d105

Browse files
committed
feat: fix validate
1 parent afaec31 commit 613d105

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

.github/workflows/validate.yml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ on:
88
# Allow manual triggering of the workflow
99
workflow_dispatch:
1010

11+
# Add explicit permissions for the GITHUB_TOKEN
12+
permissions:
13+
contents: read
14+
pull-requests: write # Required to add comments to PRs
15+
1116
jobs:
1217
validate:
1318
runs-on: ubuntu-latest
@@ -29,21 +34,13 @@ jobs:
2934
- name: Run merge test
3035
run: bun run node scripts/merge.js
3136

32-
- name: Add validation status comment
33-
if: always()
34-
uses: actions/github-script@v6
37+
# Option 1: Use a dedicated action for PR comments instead
38+
- name: Add PR comment
39+
if: github.event_name == 'pull_request' && always()
40+
uses: marocchino/sticky-pull-request-comment@v2
3541
with:
36-
github-token: ${{ secrets.GITHUB_TOKEN }}
37-
script: |
38-
const conclusion = "${{ job.status }}";
39-
const emoji = conclusion === "success" ? "✅" : "❌";
40-
const message = conclusion === "success"
41-
? "All data files are valid!"
42-
: "There are issues with the data files. Please check the action logs for details.";
42+
header: validation-result
43+
message: |
44+
## Data Validation ${{ job.status == 'success' && '✅' || '❌' }}
4345
44-
github.rest.issues.createComment({
45-
issue_number: context.issue.number,
46-
owner: context.repo.owner,
47-
repo: context.repo.repo,
48-
body: `## Data Validation ${emoji}\n\n${message}`
49-
})
46+
${{ job.status == 'success' && 'All data files are valid!' || 'There are issues with the data files. Please check the action logs for details.' }}

bun.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@types/react-dom": "^19.0.4",
2121
"@vitejs/plugin-react-swc": "^3.8.0",
2222
"ajv": "^8.12.0",
23+
"ajv-formats": "^2.1.1",
2324
"autoprefixer": "^10.4.21",
2425
"eslint": "^9.22.0",
2526
"eslint-plugin-react-hooks": "^5.2.0",
@@ -250,6 +251,8 @@
250251

251252
"ajv": ["ajv@8.17.1", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g=="],
252253

254+
"ajv-formats": ["ajv-formats@2.1.1", "", { "dependencies": { "ajv": "^8.0.0" } }, "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA=="],
255+
253256
"ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="],
254257

255258
"argparse": ["argparse@2.0.1", "", {}, "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@types/react-dom": "^19.0.4",
2828
"@vitejs/plugin-react-swc": "^3.8.0",
2929
"ajv": "^8.12.0",
30+
"ajv-formats": "^2.1.1",
3031
"autoprefixer": "^10.4.21",
3132
"eslint": "^9.22.0",
3233
"eslint-plugin-react-hooks": "^5.2.0",

scripts/validate.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import { fileURLToPath } from 'url';
44
import Ajv from 'ajv';
5+
import addFormats from 'ajv-formats';
56

67
// Get directory name in ES modules
78
const __filename = fileURLToPath(import.meta.url);
@@ -20,8 +21,8 @@ const toolSchema = {
2021
description: { type: 'string', minLength: 10 },
2122
link: {
2223
type: 'string',
23-
format: 'uri',
24-
pattern: '^https?://'
24+
// Use pattern instead of format for URL validation
25+
pattern: '^https?://[\\w.-]+(\\.[\\w.-]+)+([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?$'
2526
},
2627
tags: {
2728
type: 'array',
@@ -34,6 +35,8 @@ const toolSchema = {
3435

3536
// Initialize Ajv
3637
const ajv = new Ajv({ allErrors: true });
38+
// Add format support (optional, since we're using pattern)
39+
addFormats(ajv);
3740
const validate = ajv.compile(toolSchema);
3841

3942
// Function to validate a JSON file
@@ -43,6 +46,13 @@ function validateJsonFile(filePath) {
4346
const fileContent = fs.readFileSync(filePath, 'utf8');
4447
const data = JSON.parse(fileContent);
4548

49+
// Basic URL validation (as a fallback)
50+
if (!data.link.startsWith('http://') && !data.link.startsWith('https://')) {
51+
console.error(`\x1b[31m❌ Validation failed for ${path.basename(filePath)}:\x1b[0m`);
52+
console.error(` - /link must start with http:// or https://`);
53+
return false;
54+
}
55+
4656
// Validate against schema
4757
const valid = validate(data);
4858

0 commit comments

Comments
 (0)