diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 765046f..b4cd3c1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -74,9 +74,9 @@ pre: - touch foo.txt - mkdir -p bar && touch bar/bar.txt artifacts: + untracked: true paths: - - foo.txt - - bar + - package.json pre-test: stage: prepare diff --git a/index.js b/index.js index ec0100e..d19020a 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,12 @@ const osExec = promisify(require("child_process").exec); const merge = require("lodash.merge"); const define = require("./src/pre-defined"); -const { getValidUrl, mkdirpRecSync, drawPipeline } = require("./src/utils"); +const { + getValidUrl, + mkdirpRecSync, + readdirRecSync, + drawPipeline, +} = require("./src/utils"); const { ARGV, ONLY_JOBS, @@ -486,8 +491,8 @@ async function main() { if ("artifacts" in job) { ARTIFACTS[name] = {}; - if (job.artifacts.paths) { - for (const file of job.artifacts.paths) { + const copyFiles = (files) => { + for (const file of files) { const fileAbs = path.join(PROJECT_FILES_TEMP_DIR, file); const targetAbs = path.join( GLCI_ARTIFACTS_DIR, @@ -501,6 +506,21 @@ async function main() { ARTIFACTS[name][file] = targetAbs; } + }; + + if (job.artifacts.untracked === true) { + const untracked = readdirRecSync( + PROJECT_FILES_TEMP_DIR, + [], + "", + projectFiles + ).filter((file) => !projectFiles.includes(file)); + + copyFiles(untracked); + } + + if (job.artifacts.paths) { + copyFiles(job.artifacts.paths); } } diff --git a/src/utils.js b/src/utils.js index 75ca067..9c2c996 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,8 +1,12 @@ const fs = require("fs-extra"); +const path = require("path"); const chalk = require("chalk"); -const { RESERVED_JOB_NAMES } = require("./constants"); +const { RESERVED_JOB_NAMES, DEFAULT_STAGES } = require("./constants"); +/** + * given an url, returns the cleaned url with protocol + */ function getValidUrl(url) { const newUrl = decodeURIComponent(url).trim().replace(/\s/g, ""); @@ -17,12 +21,44 @@ function getValidUrl(url) { return newUrl; } +/** + * recursive mkdir -p + */ function mkdirpRecSync(dir) { if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } } +/** + * recursively list a directory files + * if projectFiles is given, not going rec on a directory that isn't in it + */ +function readdirRecSync(dir, files, parent, projectFiles = []) { + const currentDirFiles = fs.readdirSync(dir, { + withFileTypes: true, + }); + + for (const file of currentDirFiles) { + const fileRel = path.join(parent, file.name); + + if ( + !file.isDirectory() || + (!projectFiles.includes(fileRel) && + !projectFiles.some((name) => path.dirname(name) === fileRel)) + ) { + files.push(fileRel); + } else { + readdirRecSync(fileRel, files, fileRel, projectFiles); + } + } + + return files; +} + +/** + * logs a representation of a pipeline jobs + */ function drawPipeline(ci, onlyJobs) { // [[ "test", [ "test:unit", "test:e2e" ] ], [ "build", "build:staging" ]] const rows = []; @@ -112,5 +148,6 @@ function drawPipeline(ci, onlyJobs) { module.exports = { getValidUrl, mkdirpRecSync, + readdirRecSync, drawPipeline, };