diff --git a/.github/scripts/validateResources.js b/.github/scripts/validateResources.js index b356ce02..9572f6b6 100644 --- a/.github/scripts/validateResources.js +++ b/.github/scripts/validateResources.js @@ -5,29 +5,36 @@ const communityResourcesPath = './components/ResourceHub/community-resources.json' const validateResource = (resource, index, resources) => { - const errorMessage = resourcesPath + ':1:1:' if (resources.findIndex(r => r.url === resource.url) !== index) { - console.log(errorMessage + `Duplicate resource: ${resource.url}`) + console.log(`Duplicate resource`) return false } if (!resource.name) { - console.log(errorMessage + `Resource name is missing: ${resource.url}`) + console.log(`Resource name is missing`) return false } if (!resource.type) { - console.log(errorMessage + `Resource type is missing: ${resource.url}`) + console.log(`Resource type is missing`) return false } if (!resource.date) { - console.log(errorMessage + `Resource date is missing: ${resource.url}`) + console.log(`Resource date is missing`) return false } if (!resource.description) { - console.log(errorMessage + `Resource description is missing: ${resource.url}`) + console.log(`Resource description is missing`) return false } if (!resource.tags || !resource.tags.length) { - console.log(errorMessage + `Resource tags are missing: ${resource.url}`) + console.log(errorMessage + `Resource tags are missing`) + return false + } + if ( + resource.url.includes('youtube') && + (!resource.url.startsWith('https://www.youtube.com/watch?v=') || + resource.url.length !== 43) + ) { + console.log(`Invalid YouTube URL`) return false } return true diff --git a/.github/workflows/resource-check.yml b/.github/workflows/resource-check.yml deleted file mode 100644 index c8c9e7a8..00000000 --- a/.github/workflows/resource-check.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Validate resource hub JSON - -on: pull_request - -jobs: - generate-supported-networks: - runs-on: ubuntu-latest - steps: - - name: Use Node.js 20.x - uses: actions/setup-node@v4 - with: - node-version: '20.x' - - uses: reviewdog/action-setup@v1 - with: - reviewdog_version: latest - - uses: actions/checkout@v4 - - name: Validate resource hub JSON files - env: - REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: node .github/scripts/validateResources.js | reviewdog -efm="%f:%l:%c:%m" -name="Validate Resources" -reporter=github-check -fail-on-error=true \ No newline at end of file diff --git a/package.json b/package.json index 47ae4f1d..3d61ba65 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "start": "serve out", "test": "env-cmd cypress run --headless", "typecheck": "tsc --noEmit --incremental false", - "prepush": "pnpm lint && pnpm typecheck", + "prepush": "pnpm lint && pnpm typecheck && pnpm validate-resources", "prepare": "husky install" }, "repository": {