diff --git a/.gitignore b/.gitignore index 59662a0..3f3f6e0 100644 --- a/.gitignore +++ b/.gitignore @@ -236,4 +236,5 @@ $RECYCLE.BIN/ # End of https://www.toptal.com/developers/gitignore/api/node,windows,macos,linux,visualstudiocode -.vscode/ \ No newline at end of file +.vscode/ +reporting \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index f17e3d6..9941db4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -27793,7 +27793,7 @@ module.exports = { const got = __nccwpck_require__(3061) const core = __nccwpck_require__(2186) const ejs = __nccwpck_require__(8431) -const { readFile } = (__nccwpck_require__(7147).promises) +const { readFile, existsSync, mkdirSync } = (__nccwpck_require__(7147).promises) const { join } = __nccwpck_require__(1017) const { softAssign } = __nccwpck_require__(7348) const databaseSchema = __nccwpck_require__(5324) @@ -27850,6 +27850,15 @@ const generateIssueContent = async (scores, renderBadge) => { return ejs.render(template, { scores: scoresInScope, renderBadge }) } +const makeDirectory = ({ path }) => { + const directories = path.split('/').slice(0, -1).join('/') + core.debug(`Making directory ${directories}`) + if (!existsSync(directories)) { + core.debug('Making directory: ', path) + mkdirSync(directories, { recursive: true }) + } +} + module.exports = { validateDatabaseIntegrity: validateAgainstSchema(databaseSchema, 'database'), validateScopeIntegrity: validateAgainstSchema(scopeSchema, 'scope'), @@ -27857,7 +27866,8 @@ module.exports = { saveScore, getScore, generateReportContent, - generateIssueContent + generateIssueContent, + makeDirectory } @@ -28137,7 +28147,7 @@ const { readFile, writeFile, stat } = (__nccwpck_require__(7147).promises) const { isDifferent } = __nccwpck_require__(9497) const { updateOrCreateSegment } = __nccwpck_require__(7794) const { generateScores, generateScope } = __nccwpck_require__(4351) -const { validateDatabaseIntegrity, validateScopeIntegrity } = __nccwpck_require__(1608) +const { validateDatabaseIntegrity, validateScopeIntegrity, makeDirectory } = __nccwpck_require__(1608) async function run () { let octokit @@ -28234,6 +28244,8 @@ async function run () { // Save changes core.info('Saving changes to database and report') + console.log('Saving changes to database and report') + makeDirectory(reportPath) await writeFile(databasePath, JSON.stringify(newDatabaseState, null, 2)) await writeFile(reportPath, reportTagsEnabled ? updateOrCreateSegment({ @@ -28246,6 +28258,7 @@ async function run () { if (discoveryEnabled) { core.info('Saving changes to scope...') + makeDirectory(scopePath) await writeFile(scopePath, JSON.stringify(scope, null, 2)) } diff --git a/src/action.js b/src/action.js index a8e7025..a8b12b1 100644 --- a/src/action.js +++ b/src/action.js @@ -7,7 +7,7 @@ const { readFile, writeFile, stat } = require('fs').promises const { isDifferent } = require('@ulisesgascon/is-different') const { updateOrCreateSegment } = require('@ulisesgascon/text-tags-manager') const { generateScores, generateScope } = require('./') -const { validateDatabaseIntegrity, validateScopeIntegrity } = require('./utils') +const { validateDatabaseIntegrity, validateScopeIntegrity, makeDirectory } = require('./utils') async function run () { let octokit @@ -104,6 +104,8 @@ async function run () { // Save changes core.info('Saving changes to database and report') + console.log('Saving changes to database and report') + makeDirectory(reportPath) await writeFile(databasePath, JSON.stringify(newDatabaseState, null, 2)) await writeFile(reportPath, reportTagsEnabled ? updateOrCreateSegment({ @@ -116,6 +118,7 @@ async function run () { if (discoveryEnabled) { core.info('Saving changes to scope...') + makeDirectory(scopePath) await writeFile(scopePath, JSON.stringify(scope, null, 2)) } diff --git a/src/utils.js b/src/utils.js index 901d4b0..f671e8e 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,7 +1,7 @@ const got = require('got') const core = require('@actions/core') const ejs = require('ejs') -const { readFile } = require('fs').promises +const { readFile, existsSync, mkdirSync } = require('fs').promises const { join } = require('path') const { softAssign } = require('@ulisesgascon/soft-assign-deep-property') const databaseSchema = require('../schemas/database.json') @@ -58,6 +58,15 @@ const generateIssueContent = async (scores, renderBadge) => { return ejs.render(template, { scores: scoresInScope, renderBadge }) } +const makeDirectory = ( path ) => { + const directories = path.split('/').slice(0, -1).join('/') + core.debug(`Making directory ${directories}`) + if (!existsSync(directories)) { + core.debug('Making directory: ', path) + mkdirSync(directories, { recursive: true }) + } +} + module.exports = { validateDatabaseIntegrity: validateAgainstSchema(databaseSchema, 'database'), validateScopeIntegrity: validateAgainstSchema(scopeSchema, 'scope'), @@ -65,5 +74,6 @@ module.exports = { saveScore, getScore, generateReportContent, - generateIssueContent + generateIssueContent, + makeDirectory }