From 27487d5c48bb0898f2b0db061f197c174794f714 Mon Sep 17 00:00:00 2001 From: Justin Eveland Date: Mon, 31 Aug 2020 17:57:45 -0400 Subject: [PATCH] fix: add check to see if file exists before require (#631) --- .github/workflows/pr.yml | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 951b1e1d41..bb3676bd5e 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -89,29 +89,38 @@ jobs: uses: actions/github-script@v2 with: script: | + const fs = require('fs'); const projectTags = require(`${process.env.GITHUB_WORKSPACE}/src/data/project-tags/project-tags.json`).map(t => t.slug); const modifiedProjectFiles = process.env.PROJECT_FILES ? process.env.PROJECT_FILES.split(' ') : null + console.log(`Detected Project Files: ${JSON.stringify(modifiedProjectFiles, null, 2)}`) let errors = [] // Check all modified project json files if (modifiedProjectFiles) { - modifiedProjectFiles.map(f => { - const projectJson = require(`${process.env.GITHUB_WORKSPACE}/${f}`) - console.log(projectJson) - - // Check tags - let invalidTags = [] - if ( projectJson.projectTags ) { - projectJson.projectTags.map(pt => { - if (!projectTags.includes(pt)) { - invalidTags.push(pt); + modifiedProjectFiles.forEach(f => { + const fileName = `${process.env.GITHUB_WORKSPACE}/${f}`; + const exists = fs.existsSync(fileName) + + if (!exists) { + console.log(`INFO:: File not found: ${fileName}`) + } else { + const projectJson = require(`${process.env.GITHUB_WORKSPACE}/${f}`) + console.log(projectJson) + + // Check tags + let invalidTags = [] + if ( projectJson.projectTags ) { + projectJson.projectTags.map(pt => { + if (!projectTags.includes(pt)) { + invalidTags.push(pt); + } + }) + + // Collect invalidTags into errors + if (invalidTags.length > 0) { + errors.push({file: f, invalidTags: invalidTags}) } - }) - - // Collect invalidTags into errors - if (invalidTags.length > 0) { - errors.push({file: f, invalidTags: invalidTags}) } } })