-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const fs = require('fs') | ||
|
||
const resourcesPath = './components/ResourceHub/company-resources.json' | ||
const communityResourcesPath = | ||
'./components/ResourceHub/community-resources.json' | ||
|
||
const validateResource = (resource, index, resources) => { | ||
if (resources.findIndex(r => r.url === resource.url) !== index) { | ||
console.log(`Duplicate resource: ${resource.url}`) | ||
return false | ||
} | ||
if (!resource.name) { | ||
console.log(`Resource name is missing: ${resource.url}`) | ||
return false | ||
} | ||
if (!resource.type) { | ||
console.log(`Resource type is missing: ${resource.url}`) | ||
return false | ||
} | ||
if (!resource.date) { | ||
console.log(`Resource date is missing: ${resource.url}`) | ||
return false | ||
} | ||
if (!resource.description) { | ||
console.log(`Resource description is missing: ${resource.url}`) | ||
return false | ||
} | ||
if (!resource.tags || !resource.tags.length) { | ||
console.log(`Resource tags are missing: ${resource.url}`) | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
const validateResources = () => { | ||
const resources = [ | ||
...JSON.parse(fs.readFileSync(resourcesPath, 'utf8')), | ||
...JSON.parse(fs.readFileSync(communityResourcesPath, 'utf8')) | ||
] | ||
|
||
if (resources.map(validateResource).some(valid => !valid)) { | ||
process.exit(1) | ||
} | ||
} | ||
|
||
validateResources() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Validate resource hub JSON on PR | ||
|
||
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: pnpm/action-setup@v3 | ||
with: | ||
version: 8 | ||
- name: Install dependencies | ||
run: pnpm install | ||
- uses: reviewdog/action-setup@v1 | ||
with: | ||
reviewdog_version: latest | ||
- name: Validate resource hub JSON files | ||
env: | ||
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: pnpm validate-resources | reviewdog -f=checkstyle -name="Validate Resources" -reporter=github-pr-check -fail-on-error=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters