Skip to content
This repository was archived by the owner on Apr 7, 2025. It is now read-only.

Commit 27487d5

Browse files
authored
fix: add check to see if file exists before require (#631)
1 parent a5be44e commit 27487d5

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

.github/workflows/pr.yml

+24-15
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,38 @@ jobs:
8989
uses: actions/github-script@v2
9090
with:
9191
script: |
92+
const fs = require('fs');
9293
const projectTags = require(`${process.env.GITHUB_WORKSPACE}/src/data/project-tags/project-tags.json`).map(t => t.slug);
9394
9495
const modifiedProjectFiles = process.env.PROJECT_FILES ? process.env.PROJECT_FILES.split(' ') : null
96+
console.log(`Detected Project Files: ${JSON.stringify(modifiedProjectFiles, null, 2)}`)
9597
let errors = []
9698
9799
// Check all modified project json files
98100
if (modifiedProjectFiles) {
99-
modifiedProjectFiles.map(f => {
100-
const projectJson = require(`${process.env.GITHUB_WORKSPACE}/${f}`)
101-
console.log(projectJson)
102-
103-
// Check tags
104-
let invalidTags = []
105-
if ( projectJson.projectTags ) {
106-
projectJson.projectTags.map(pt => {
107-
if (!projectTags.includes(pt)) {
108-
invalidTags.push(pt);
101+
modifiedProjectFiles.forEach(f => {
102+
const fileName = `${process.env.GITHUB_WORKSPACE}/${f}`;
103+
const exists = fs.existsSync(fileName)
104+
105+
if (!exists) {
106+
console.log(`INFO:: File not found: ${fileName}`)
107+
} else {
108+
const projectJson = require(`${process.env.GITHUB_WORKSPACE}/${f}`)
109+
console.log(projectJson)
110+
111+
// Check tags
112+
let invalidTags = []
113+
if ( projectJson.projectTags ) {
114+
projectJson.projectTags.map(pt => {
115+
if (!projectTags.includes(pt)) {
116+
invalidTags.push(pt);
117+
}
118+
})
119+
120+
// Collect invalidTags into errors
121+
if (invalidTags.length > 0) {
122+
errors.push({file: f, invalidTags: invalidTags})
109123
}
110-
})
111-
112-
// Collect invalidTags into errors
113-
if (invalidTags.length > 0) {
114-
errors.push({file: f, invalidTags: invalidTags})
115124
}
116125
}
117126
})

0 commit comments

Comments
 (0)