Skip to content

Commit

Permalink
Add workflow to validate resources
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-md committed Mar 21, 2024
1 parent 77b3961 commit 694a5f8
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/scripts/validateResources.js
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()
24 changes: 24 additions & 0 deletions .github/workflows/resource-check.yml
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dev": "next dev",
"generate-supported-networks": "node .github/scripts/generateSupportedNetworks.js",
"get-resources-og": "node .github/scripts/getResourcesOg.js",
"validate-resources": "node .github/scripts/validateResources.js",
"linkcheck": "find ./pages -name '*.md*' -print0 | xargs -0 -n1 pnpm markdown-link-check --quiet --progress --config linkchecker-config.json",
"lint": "eslint . && vale pages/ --minAlertLevel=error",
"start": "serve out",
Expand Down

0 comments on commit 694a5f8

Please sign in to comment.