From c221ed024af1dbbd67c9d61b451355f00792bede Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 00:12:01 +0300 Subject: [PATCH 01/19] implement caching strategy --- build/gulp/tasks/test-vulns.ts | 60 ++++++++++++++++++++++++++++++++++ gulpfile.ts | 1 + package.json | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 build/gulp/tasks/test-vulns.ts diff --git a/build/gulp/tasks/test-vulns.ts b/build/gulp/tasks/test-vulns.ts new file mode 100644 index 0000000000..c552045faa --- /dev/null +++ b/build/gulp/tasks/test-vulns.ts @@ -0,0 +1,60 @@ +import * as fs from 'fs' +import { task } from 'gulp' +import * as path from 'path' +import sh from '../sh' + +import debug from 'debug' + +import config from '../../../config' + +const { paths } = config + +const SCAN_RESULTS_DIR = paths.base('.vuln-scans') + +const log = message => debug.log(message) +log.success = message => debug.log(`✔ ${message}`) + +const ensureDirExists = path => { + if (!fs.existsSync(path)) { + sh(`mkdir -p ${path}`) + } +} + +const getTodayScanFilePath = () => { + const now = new Date() + const fileName = `snyk-${now.getUTCFullYear()}-${now.getUTCMonth() + 1}-${now.getUTCDate()}` + + return path.resolve(SCAN_RESULTS_DIR, fileName) +} + +const recentlyChecked = () => { + const recentCheckFilePath = getTodayScanFilePath() + return fs.existsSync(recentCheckFilePath) +} + +const registerRecentSucessfulScan = async () => { + ensureDirExists(SCAN_RESULTS_DIR) + + const recentScanFilePath = getTodayScanFilePath() + await sh(`touch ${recentScanFilePath}`) +} + +/** + * The following strategy is used to perform vulnerabilites scan + * - check if there is marker of recent sucessful scan + * - if this marker exists, skip checks + * - if there is no marker, perform check + * - if check is successful, create successful check marker + */ +task('test:vulns', async () => { + if (recentlyChecked()) { + log.success('Vulnerabilities check was already performed recently, skipping..') + return + } + + log('Scanning dependency packages for vulnerabilities..') + await sh(`yarn snyk test`) + log.success('Vulnerability scan is successfully passed.') + + registerRecentSucessfulScan() +}) diff --git a/gulpfile.ts b/gulpfile.ts index ba23bc51e9..c34184f67a 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -14,6 +14,7 @@ require('./build/gulp/tasks/screener') require('./build/gulp/tasks/git') require('./build/gulp/tasks/test-unit') require('./build/gulp/tasks/test-projects') +require('./build/gulp/tasks/test-vulns') // global tasks task('build', series('dll', parallel('dist', 'build:docs'))) diff --git a/package.json b/package.json index 75c2f3976d..82fc059105 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "pretest": "yarn satisfied", "test": "gulp test", "test:watch": "gulp test:watch", - "test:vulns": "snyk test", + "test:vulns": "gulp test:vulns", "test:visual": "gulp screener", "test:projects": "gulp test:projects", "generate:component": "gulp generate:component" From 374fce2a66d0ae7c3568c0a9d66c51c3f6e48da3 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 00:13:05 +0300 Subject: [PATCH 02/19] adjust file name of scan marker --- build/gulp/tasks/test-vulns.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/gulp/tasks/test-vulns.ts b/build/gulp/tasks/test-vulns.ts index c552045faa..da29e90e98 100644 --- a/build/gulp/tasks/test-vulns.ts +++ b/build/gulp/tasks/test-vulns.ts @@ -22,7 +22,8 @@ const ensureDirExists = path => { const getTodayScanFilePath = () => { const now = new Date() - const fileName = `snyk-${now.getUTCFullYear()}-${now.getUTCMonth() + 1}-${now.getUTCDate()}` + const fileName = `snyk-scanned-${now.getUTCFullYear()}-${now.getUTCMonth() + + 1}-${now.getUTCDate()}` return path.resolve(SCAN_RESULTS_DIR, fileName) } From f585290b8a31d7ab25653c297544d8eea8d1935b Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 11:18:31 +0100 Subject: [PATCH 03/19] add yarn lock hash to marker file name --- build/gulp/tasks/test-vulns.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/build/gulp/tasks/test-vulns.ts b/build/gulp/tasks/test-vulns.ts index da29e90e98..3466bcef31 100644 --- a/build/gulp/tasks/test-vulns.ts +++ b/build/gulp/tasks/test-vulns.ts @@ -3,6 +3,8 @@ import { task } from 'gulp' import * as path from 'path' import sh from '../sh' +import * as crypto from 'crypto' + import debug from 'debug' import config from '../../../config' @@ -14,6 +16,13 @@ const SCAN_RESULTS_DIR = paths.base('.vuln-scans') const log = message => debug.log(message) log.success = message => debug.log(`✔ ${message}`) +const computeHash = filePath => { + const md5 = crypto.createHash('md5') + md5.update(fs.readFileSync(paths.base('yarn.lock'))) + + return md5.digest('hex') +} + const ensureDirExists = path => { if (!fs.existsSync(path)) { sh(`mkdir -p ${path}`) @@ -21,9 +30,11 @@ const ensureDirExists = path => { } const getTodayScanFilePath = () => { + const yarnLockHash = computeHash(paths.base('yarn.lock')) const now = new Date() + const fileName = `snyk-scanned-${now.getUTCFullYear()}-${now.getUTCMonth() + - 1}-${now.getUTCDate()}` + 1}-${now.getUTCDate()}-${yarnLockHash.slice(0, 8)}` return path.resolve(SCAN_RESULTS_DIR, fileName) } From 144aaa75f762efffe8a8d216b24341968426842c Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 11:23:13 +0100 Subject: [PATCH 04/19] add change to build config --- .circleci/config.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 328faa1561..5f6a81c9ae 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,9 +49,17 @@ jobs: - run: name: Report coverage command: bash <(curl -s https://codecov.io/bash) + + - restore_cache: + key: v1-vuln-tests - run: name: Vulnerability Tests command: yarn test:vulns + - save_cache: + key: v1-vuln-tests + paths: + - .vuln-tests + - run: name: Visual Tests command: yarn test:visual From e66b5545160856af2c17fdbbc043af7879014955 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 11:37:28 +0100 Subject: [PATCH 05/19] fix dir name in build config --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5f6a81c9ae..ae68d062b0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -51,14 +51,14 @@ jobs: command: bash <(curl -s https://codecov.io/bash) - restore_cache: - key: v1-vuln-tests + key: v1-vuln-scans - run: name: Vulnerability Tests command: yarn test:vulns - save_cache: - key: v1-vuln-tests + key: v1-vuln-scans paths: - - .vuln-tests + - .vuln-scans - run: name: Visual Tests From 25a8a62449e895494854371ea1434f1f50f0f8a1 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 11:59:20 +0100 Subject: [PATCH 06/19] improve caching strategy --- .circleci/config.yml | 4 ++-- build/gulp/tasks/test-vulns.ts | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ae68d062b0..f7fa2e9e5c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -51,12 +51,12 @@ jobs: command: bash <(curl -s https://codecov.io/bash) - restore_cache: - key: v1-vuln-scans + key: v1-vuln-scans-{{ checksum "yarn.lock" }} - run: name: Vulnerability Tests command: yarn test:vulns - save_cache: - key: v1-vuln-scans + key: v1-vuln-scans-{{ checksum "yarn.lock" }} paths: - .vuln-scans diff --git a/build/gulp/tasks/test-vulns.ts b/build/gulp/tasks/test-vulns.ts index 3466bcef31..cea67d8b20 100644 --- a/build/gulp/tasks/test-vulns.ts +++ b/build/gulp/tasks/test-vulns.ts @@ -1,26 +1,26 @@ import * as fs from 'fs' import { task } from 'gulp' import * as path from 'path' -import sh from '../sh' - import * as crypto from 'crypto' - import debug from 'debug' +const memoize = require('fast-memoize') + import config from '../../../config' +import sh from '../sh' const { paths } = config -const SCAN_RESULTS_DIR = paths.base('.vuln-scans') +const SCAN_RESULTS_DIR_PREFIX = '.vuln-scans' const log = message => debug.log(message) log.success = message => debug.log(`✔ ${message}`) const computeHash = filePath => { - const md5 = crypto.createHash('md5') - md5.update(fs.readFileSync(paths.base('yarn.lock'))) + const sha256 = crypto.createHash('sha256') + sha256.update(fs.readFileSync(filePath)) - return md5.digest('hex') + return sha256.digest('base64') } const ensureDirExists = path => { @@ -29,14 +29,18 @@ const ensureDirExists = path => { } } -const getTodayScanFilePath = () => { +const getScanResultsDirPath = memoize(() => { const yarnLockHash = computeHash(paths.base('yarn.lock')) + return paths.base(`${SCAN_RESULTS_DIR_PREFIX}-${yarnLockHash}`) +}) + +const getTodayScanFilePath = () => { const now = new Date() const fileName = `snyk-scanned-${now.getUTCFullYear()}-${now.getUTCMonth() + - 1}-${now.getUTCDate()}-${yarnLockHash.slice(0, 8)}` + 1}-${now.getUTCDate()}` - return path.resolve(SCAN_RESULTS_DIR, fileName) + return path.resolve(getScanResultsDirPath(), fileName) } const recentlyChecked = () => { @@ -45,7 +49,7 @@ const recentlyChecked = () => { } const registerRecentSucessfulScan = async () => { - ensureDirExists(SCAN_RESULTS_DIR) + ensureDirExists(getScanResultsDirPath()) const recentScanFilePath = getTodayScanFilePath() await sh(`touch ${recentScanFilePath}`) From 9e3f0fc51a842a9546f52d9ae6681210f6ac8d8f Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 13:19:19 +0100 Subject: [PATCH 07/19] just restore cache --- .circleci/config.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f7fa2e9e5c..2fd358df9d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -55,10 +55,6 @@ jobs: - run: name: Vulnerability Tests command: yarn test:vulns - - save_cache: - key: v1-vuln-scans-{{ checksum "yarn.lock" }} - paths: - - .vuln-scans - run: name: Visual Tests From a662a54f907ca10bb626bd3c9843cd677d7713ee Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 13:20:40 +0100 Subject: [PATCH 08/19] temporary remove lint and tests --- .circleci/config.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2fd358df9d..2ff4ce19b9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,18 +37,6 @@ jobs: - ~/.cache/yarn - .yarn-cache - node_modules - - run: - name: Lint - command: yarn lint - - run: - name: Prettier - command: yarn prettier - - run: - name: Unit Tests - command: yarn test --strict --maxWorkers=4 - - run: - name: Report coverage - command: bash <(curl -s https://codecov.io/bash) - restore_cache: key: v1-vuln-scans-{{ checksum "yarn.lock" }} From a74b4c9d1e9984c41391052db6fe79ca4f652cb5 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 13:27:13 +0100 Subject: [PATCH 09/19] try --- build/gulp/tasks/test-vulns.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/build/gulp/tasks/test-vulns.ts b/build/gulp/tasks/test-vulns.ts index cea67d8b20..ff93748069 100644 --- a/build/gulp/tasks/test-vulns.ts +++ b/build/gulp/tasks/test-vulns.ts @@ -45,6 +45,7 @@ const getTodayScanFilePath = () => { const recentlyChecked = () => { const recentCheckFilePath = getTodayScanFilePath() + console.warn('recent check file path is', recentCheckFilePath) return fs.existsSync(recentCheckFilePath) } From af2426316eae179dabed0da3dfaab92deceb396f Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 13:36:47 +0100 Subject: [PATCH 10/19] fix caching strategy --- .circleci/config.yml | 4 ++++ build/gulp/tasks/test-vulns.ts | 20 ++++---------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ff4ce19b9..f12f1301ab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -43,6 +43,10 @@ jobs: - run: name: Vulnerability Tests command: yarn test:vulns + - save_cache: + key: v1-vuln-scans-{{ checksum "yarn.lock" }} + paths: + - .vuln-scans - run: name: Visual Tests diff --git a/build/gulp/tasks/test-vulns.ts b/build/gulp/tasks/test-vulns.ts index ff93748069..5cc9aa94a0 100644 --- a/build/gulp/tasks/test-vulns.ts +++ b/build/gulp/tasks/test-vulns.ts @@ -1,38 +1,27 @@ import * as fs from 'fs' import { task } from 'gulp' import * as path from 'path' -import * as crypto from 'crypto' import debug from 'debug' -const memoize = require('fast-memoize') - import config from '../../../config' import sh from '../sh' const { paths } = config -const SCAN_RESULTS_DIR_PREFIX = '.vuln-scans' +const SCAN_RESULTS_DIR_NAME = '.vuln-scans' const log = message => debug.log(message) log.success = message => debug.log(`✔ ${message}`) -const computeHash = filePath => { - const sha256 = crypto.createHash('sha256') - sha256.update(fs.readFileSync(filePath)) - - return sha256.digest('base64') -} - const ensureDirExists = path => { if (!fs.existsSync(path)) { sh(`mkdir -p ${path}`) } } -const getScanResultsDirPath = memoize(() => { - const yarnLockHash = computeHash(paths.base('yarn.lock')) - return paths.base(`${SCAN_RESULTS_DIR_PREFIX}-${yarnLockHash}`) -}) +const getScanResultsDirPath = () => { + return paths.base(SCAN_RESULTS_DIR_NAME) +} const getTodayScanFilePath = () => { const now = new Date() @@ -45,7 +34,6 @@ const getTodayScanFilePath = () => { const recentlyChecked = () => { const recentCheckFilePath = getTodayScanFilePath() - console.warn('recent check file path is', recentCheckFilePath) return fs.existsSync(recentCheckFilePath) } From ba7494432aa67a2dc66975d1402d1bf42a4dbacc Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 13:49:13 +0100 Subject: [PATCH 11/19] try --- build/gulp/tasks/test-vulns.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/gulp/tasks/test-vulns.ts b/build/gulp/tasks/test-vulns.ts index 5cc9aa94a0..a8da8b4f65 100644 --- a/build/gulp/tasks/test-vulns.ts +++ b/build/gulp/tasks/test-vulns.ts @@ -34,14 +34,15 @@ const getTodayScanFilePath = () => { const recentlyChecked = () => { const recentCheckFilePath = getTodayScanFilePath() + console.warn('checking of file exists:', recentCheckFilePath) return fs.existsSync(recentCheckFilePath) } const registerRecentSucessfulScan = async () => { ensureDirExists(getScanResultsDirPath()) - const recentScanFilePath = getTodayScanFilePath() - await sh(`touch ${recentScanFilePath}`) + // const recentScanFilePath = getTodayScanFilePath() + await sh(`touch aha`) // ${recentScanFilePath}`) } /** From 6c3861c740c175ab4c291f4d3eb9ae94008a21ce Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 13:50:37 +0100 Subject: [PATCH 12/19] try --- .circleci/config.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f12f1301ab..d39c4a8f95 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,22 +21,6 @@ jobs: echo 'export PATH="${PATH}:${HOME}/.yarn/bin"' >> $BASH_ENV - checkout # because we don't invoke npm (we use yarn) we need to add npm bin to PATH manually - - run: - name: Add npm bin to PATH - command: echo 'export PATH="${PATH}:$(npm bin)"' >> $BASH_ENV - - restore_cache: - keys: - - v1-dependencies-{{ checksum "yarn.lock" }} - - v1-dependencies - - run: - name: Install Dependencies - command: yarn - - save_cache: - key: v1-dependencies-{{ checksum "yarn.lock" }} - paths: - - ~/.cache/yarn - - .yarn-cache - - node_modules - restore_cache: key: v1-vuln-scans-{{ checksum "yarn.lock" }} From 19922c9eca2726b22d4caa56c6352c22ebca44ba Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 13:51:31 +0100 Subject: [PATCH 13/19] try --- .circleci/config.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index d39c4a8f95..f12f1301ab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,6 +21,22 @@ jobs: echo 'export PATH="${PATH}:${HOME}/.yarn/bin"' >> $BASH_ENV - checkout # because we don't invoke npm (we use yarn) we need to add npm bin to PATH manually + - run: + name: Add npm bin to PATH + command: echo 'export PATH="${PATH}:$(npm bin)"' >> $BASH_ENV + - restore_cache: + keys: + - v1-dependencies-{{ checksum "yarn.lock" }} + - v1-dependencies + - run: + name: Install Dependencies + command: yarn + - save_cache: + key: v1-dependencies-{{ checksum "yarn.lock" }} + paths: + - ~/.cache/yarn + - .yarn-cache + - node_modules - restore_cache: key: v1-vuln-scans-{{ checksum "yarn.lock" }} From b0ce4b06271b907f6ce601662228c3b3f6526402 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 13:58:33 +0100 Subject: [PATCH 14/19] try epoch --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f12f1301ab..ac1c1d5b98 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,7 +44,7 @@ jobs: name: Vulnerability Tests command: yarn test:vulns - save_cache: - key: v1-vuln-scans-{{ checksum "yarn.lock" }} + key: v1-vuln-scans-{{ checksum "yarn.lock" }}-{{ epoch }} paths: - .vuln-scans From 63adf2e60a080526fde09a664448d62ca9c75b37 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 14:03:06 +0100 Subject: [PATCH 15/19] create file on scan --- build/gulp/tasks/test-vulns.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build/gulp/tasks/test-vulns.ts b/build/gulp/tasks/test-vulns.ts index a8da8b4f65..5cc9aa94a0 100644 --- a/build/gulp/tasks/test-vulns.ts +++ b/build/gulp/tasks/test-vulns.ts @@ -34,15 +34,14 @@ const getTodayScanFilePath = () => { const recentlyChecked = () => { const recentCheckFilePath = getTodayScanFilePath() - console.warn('checking of file exists:', recentCheckFilePath) return fs.existsSync(recentCheckFilePath) } const registerRecentSucessfulScan = async () => { ensureDirExists(getScanResultsDirPath()) - // const recentScanFilePath = getTodayScanFilePath() - await sh(`touch aha`) // ${recentScanFilePath}`) + const recentScanFilePath = getTodayScanFilePath() + await sh(`touch ${recentScanFilePath}`) } /** From 30d805ee1e2c636cf081500cd84e9c4308652209 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Mon, 17 Dec 2018 14:06:00 +0100 Subject: [PATCH 16/19] return lint and test steps --- .circleci/config.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index ac1c1d5b98..4394caa657 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,6 +37,18 @@ jobs: - ~/.cache/yarn - .yarn-cache - node_modules + - run: + name: Lint + command: yarn lint + - run: + name: Prettier + command: yarn prettier + - run: + name: Unit Tests + command: yarn test --strict --maxWorkers=4 + - run: + name: Report coverage + command: bash <(curl -s https://codecov.io/bash) - restore_cache: key: v1-vuln-scans-{{ checksum "yarn.lock" }} From 4537020f5e4b0f6f9251b8929ed1fc9b71842b05 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Tue, 18 Dec 2018 11:32:50 +0100 Subject: [PATCH 17/19] introduce comment for the caching approach taken --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4394caa657..25f0d08b77 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -55,6 +55,7 @@ jobs: - run: name: Vulnerability Tests command: yarn test:vulns + # https://discuss.circleci.com/t/add-mechanism-to-update-existing-cache-key/9014/12 - save_cache: key: v1-vuln-scans-{{ checksum "yarn.lock" }}-{{ epoch }} paths: From 29e1e639c275864998e73bd31c6909a14cdc6767 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Tue, 18 Dec 2018 11:46:07 +0100 Subject: [PATCH 18/19] remove unnecessary function --- build/gulp/tasks/test-vulns.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/build/gulp/tasks/test-vulns.ts b/build/gulp/tasks/test-vulns.ts index 5cc9aa94a0..f728365928 100644 --- a/build/gulp/tasks/test-vulns.ts +++ b/build/gulp/tasks/test-vulns.ts @@ -9,6 +9,7 @@ import sh from '../sh' const { paths } = config const SCAN_RESULTS_DIR_NAME = '.vuln-scans' +const SCAN_RESULTS_DIR_PATH = paths.base(SCAN_RESULTS_DIR_NAME) const log = message => debug.log(message) log.success = message => debug.log(`✔ ${message}`) @@ -19,17 +20,13 @@ const ensureDirExists = path => { } } -const getScanResultsDirPath = () => { - return paths.base(SCAN_RESULTS_DIR_NAME) -} - const getTodayScanFilePath = () => { const now = new Date() const fileName = `snyk-scanned-${now.getUTCFullYear()}-${now.getUTCMonth() + 1}-${now.getUTCDate()}` - return path.resolve(getScanResultsDirPath(), fileName) + return path.resolve(SCAN_RESULTS_DIR_PATH, fileName) } const recentlyChecked = () => { @@ -38,7 +35,7 @@ const recentlyChecked = () => { } const registerRecentSucessfulScan = async () => { - ensureDirExists(getScanResultsDirPath()) + ensureDirExists(SCAN_RESULTS_DIR_PATH) const recentScanFilePath = getTodayScanFilePath() await sh(`touch ${recentScanFilePath}`) From 67ce5d40225f87c1b2e9836178fcaa3a91867089 Mon Sep 17 00:00:00 2001 From: kuzhelov Date: Tue, 18 Dec 2018 11:50:22 +0100 Subject: [PATCH 19/19] simplify expression for marker file name --- build/gulp/tasks/test-vulns.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build/gulp/tasks/test-vulns.ts b/build/gulp/tasks/test-vulns.ts index f728365928..b20351292e 100644 --- a/build/gulp/tasks/test-vulns.ts +++ b/build/gulp/tasks/test-vulns.ts @@ -23,8 +23,11 @@ const ensureDirExists = path => { const getTodayScanFilePath = () => { const now = new Date() - const fileName = `snyk-scanned-${now.getUTCFullYear()}-${now.getUTCMonth() + - 1}-${now.getUTCDate()}` + const year = now.getUTCFullYear() + const month = now.getUTCMonth() + 1 + const date = now.getUTCDate() + + const fileName = `snyk-scanned-${year}-${month}-${date}` return path.resolve(SCAN_RESULTS_DIR_PATH, fileName) }