From 004b1e4b4ae752339447bcf5f713403c1fd411ef Mon Sep 17 00:00:00 2001 From: shellscape Date: Fri, 18 Oct 2019 18:48:01 -0400 Subject: [PATCH 1/7] chore: print envars --- packages/beep/test/test.js | 2 ++ scripts/run-changed.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/beep/test/test.js b/packages/beep/test/test.js index b3056d43c..77ff4ab28 100644 --- a/packages/beep/test/test.js +++ b/packages/beep/test/test.js @@ -18,3 +18,5 @@ test('error', async (t) => { const { stderr } = await t.throwsAsync(throws); t.truthy(stderr.indexOf('\x07')); }); + +console.log('foo'); diff --git a/scripts/run-changed.js b/scripts/run-changed.js index 69d7f5fc0..e8d98b4e1 100755 --- a/scripts/run-changed.js +++ b/scripts/run-changed.js @@ -12,6 +12,8 @@ const [, , task] = process.argv; const { log } = console; const sha = process.env.CIRCLE_SHA1 || 'HEAD'; +log(process.env); + (async () => { const rePkg = /(packages\/([\w\-_]+))\/?/; const { stdout: diff } = await execa('git', ['diff', `master...${sha}`, '--name-only']); From a57537208308b44f131e3d66be19e3e2bd5f652b Mon Sep 17 00:00:00 2001 From: shellscape Date: Sat, 19 Oct 2019 09:37:42 -0400 Subject: [PATCH 2/7] chore: update diff alogrithm --- package.json | 3 ++- pnpm-lock.yaml | 39 ++++++++++++++++++++++++++++++++++----- scripts/run-changed.js | 38 ++++++++++++++++++++++++++++++++------ 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index cd547d321..47d52b0f1 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "rollup": "^1.20.1", "tslib": "^1.10.0", "tslint": "^5.19.0", - "typescript": "^3.4.3" + "typescript": "^3.4.3", + "yaml": "^1.7.2" }, "ava": { "files": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5e9ae3c4f..37e71b744 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,10 +11,11 @@ importers: pre-commit: 1.2.2 prettier: 1.18.2 prettier-plugin-package: 0.3.1_prettier@1.18.2 - rollup: 1.24.0 + rollup: 1.25.0 tslib: 1.10.0 tslint: 5.20.0_typescript@3.6.4 typescript: 3.6.4 + yaml: 1.7.2 specifiers: ava: ^2.2.0 chalk: ^2.4.2 @@ -30,6 +31,7 @@ importers: tslib: ^1.10.0 tslint: ^5.19.0 typescript: ^3.4.3 + yaml: ^1.7.2 packages/beep: devDependencies: rollup: 1.24.0 @@ -309,6 +311,12 @@ packages: '@babel/core': ^7.0.0-0 resolution: integrity: sha512-Ma93Ix95PNSEngqomy5LSBMAQvYKVe3dy+JlVJSHEXZR5ASL9lQBedMiCyVtmTLraIDVRE3ZjTZvmXXD2Ozw3g== + /@babel/runtime/7.6.3: + dependencies: + regenerator-runtime: 0.13.3 + dev: true + resolution: + integrity: sha512-kq6anf9JGjW8Nt5rYfEuGRaEAaH1mkv3Bbu6rYvLOpPh/RusSJXuKPEAoZ7L7gybZkchE8+NV5g9vKF4AGAtsA== /@babel/template/7.6.0: dependencies: '@babel/code-frame': 7.5.5 @@ -581,7 +589,7 @@ packages: /array-includes/3.0.3: dependencies: define-properties: 1.1.3 - es-abstract: 1.15.0 + es-abstract: 1.16.0 dev: true engines: node: '>= 0.4' @@ -1461,7 +1469,7 @@ packages: dev: true resolution: integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g== - /es-abstract/1.15.0: + /es-abstract/1.16.0: dependencies: es-to-primitive: 1.2.0 function-bind: 1.1.1 @@ -1477,7 +1485,7 @@ packages: engines: node: '>= 0.4' resolution: - integrity: sha512-bhkEqWJ2t2lMeaJDuk7okMkJWI/yqgH/EoGwpcvv0XW9RWQsRspI4wt6xuyuvMvvQE3gg/D9HXppgk21w78GyQ== + integrity: sha512-xdQnfykZ9JMEiasTAJZJdMWCQ1Vm00NBw79/AWi7ELfZuuPCSOMDZbT9mkOfSctVtfhb+sAAzrm+j//GjjLHLg== /es-to-primitive/1.2.0: dependencies: is-callable: 1.1.4 @@ -3122,7 +3130,7 @@ packages: /object.values/1.1.0: dependencies: define-properties: 1.1.3 - es-abstract: 1.15.0 + es-abstract: 1.16.0 function-bind: 1.1.1 has: 1.0.3 dev: true @@ -3704,6 +3712,10 @@ packages: dev: true resolution: integrity: sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg== + /regenerator-runtime/0.13.3: + dev: true + resolution: + integrity: sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw== /regexp.prototype.flags/1.2.0: dependencies: define-properties: 1.1.3 @@ -3888,6 +3900,15 @@ packages: hasBin: true resolution: integrity: sha512-PiFETY/rPwodQ8TTC52Nz2DSCYUATznGh/ChnxActCr8rV5FIk3afBUb3uxNritQW/Jpbdn3kq1Rwh1HHYMwdQ== + /rollup/1.25.0: + dependencies: + '@types/estree': 0.0.39 + '@types/node': 12.11.1 + acorn: 7.1.0 + dev: true + hasBin: true + resolution: + integrity: sha512-tcf5ThhnhOUaNrxBSABvaaX9uC8hNxgyJpJmDIXaCkKHq/nPocaDz/4F/KBDiUpOt/ThvUxFrUq3XkyWiyXQiQ== /run-async/2.3.0: dependencies: is-promise: 2.1.0 @@ -4687,6 +4708,14 @@ packages: dev: true resolution: integrity: sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI= + /yaml/1.7.2: + dependencies: + '@babel/runtime': 7.6.3 + dev: true + engines: + node: '>= 6' + resolution: + integrity: sha512-qXROVp90sb83XtAoqE8bP9RwAkTTZbugRUTm5YeFCBfNRPEp2YzTeqWiz7m5OORHzEvrA/qcGS8hp/E+MMROYw== /yargs-parser/10.1.0: dependencies: camelcase: 4.1.0 diff --git a/scripts/run-changed.js b/scripts/run-changed.js index e8d98b4e1..6550ea1d5 100755 --- a/scripts/run-changed.js +++ b/scripts/run-changed.js @@ -2,21 +2,47 @@ /* eslint-disable import/no-extraneous-dependencies */ -const { existsSync } = require('fs'); -const { join } = require('path'); +const { existsSync, readFileSync } = require('fs'); +const { join, sep } = require('path'); const chalk = require('chalk'); const execa = require('execa'); +const yaml = require('yaml'); const [, , task] = process.argv; const { log } = console; -const sha = process.env.CIRCLE_SHA1 || 'HEAD'; -log(process.env); +const getDiff = async () => { + const { CIRCLE_SHA1, CIRCLE_COMPARE_URL, GITHUB_SHA, GITHUB_BASE_REF } = process.env; + let baseRef = 'master'; + let sha = 'HEAD'; + + if (CIRCLE_SHA1) { + if (CIRCLE_COMPARE_URL) { + const reCompare = /compare\/([0-9a-z]+)\.\.\.([0-9a-z]+)$/; + const [, from, to] = CIRCLE_COMPARE_URL.match(reCompare); + baseRef = from || 'master'; + sha = to || 'HEAD'; + } else { + sha = CIRCLE_SHA1; + } + } + + if (GITHUB_SHA) { + sha = GITHUB_SHA; + baseRef = GITHUB_BASE_REF || 'master'; + } + + const { stdout } = await execa('git', ['diff', `${baseRef}...${sha}`, '--name-only']); + return stdout; +}; (async () => { - const rePkg = /(packages\/([\w\-_]+))\/?/; - const { stdout: diff } = await execa('git', ['diff', `master...${sha}`, '--name-only']); + const workspace = readFileSync(join(__dirname, '..', 'pnpm-workspace.yaml'), 'utf-8'); + const { packages } = yaml.parse(workspace); + const roots = packages.map((item) => item.split(sep)[0]).join('|'); + const rePkg = new RegExp(`(${roots}/([\\w\\-_]+))/?`); + const diff = await getDiff(); const filters = diff .split('\n') .filter((line) => rePkg.test(line) && existsSync(join(__dirname, '..', line))) From be6f6c68fe5ef676b6b2ecf6d726ea1b813728a7 Mon Sep 17 00:00:00 2001 From: shellscape Date: Sat, 19 Oct 2019 09:49:07 -0400 Subject: [PATCH 3/7] chore: kick a plugin --- packages/beep/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/beep/test/test.js b/packages/beep/test/test.js index 77ff4ab28..2ff77ea4f 100644 --- a/packages/beep/test/test.js +++ b/packages/beep/test/test.js @@ -19,4 +19,4 @@ test('error', async (t) => { t.truthy(stderr.indexOf('\x07')); }); -console.log('foo'); +console.log('bar'); From d520424cef4e36a28488eb65239dac6e0a2e4cf9 Mon Sep 17 00:00:00 2001 From: shellscape Date: Sat, 19 Oct 2019 09:54:08 -0400 Subject: [PATCH 4/7] chore: add diff info to console output --- scripts/run-changed.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/run-changed.js b/scripts/run-changed.js index 6550ea1d5..5d332b4e9 100755 --- a/scripts/run-changed.js +++ b/scripts/run-changed.js @@ -33,6 +33,8 @@ const getDiff = async () => { baseRef = GITHUB_BASE_REF || 'master'; } + log(chalk`{blue Comparing ${baseRef}...${sha}}`); + const { stdout } = await execa('git', ['diff', `${baseRef}...${sha}`, '--name-only']); return stdout; }; From a35d79ccd0a3a45c41e7b916e0bc52e597d5b8b8 Mon Sep 17 00:00:00 2001 From: shellscape Date: Sat, 19 Oct 2019 09:58:51 -0400 Subject: [PATCH 5/7] chore: use circle sha --- scripts/run-changed.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/run-changed.js b/scripts/run-changed.js index 5d332b4e9..b5ffcf095 100755 --- a/scripts/run-changed.js +++ b/scripts/run-changed.js @@ -20,12 +20,10 @@ const getDiff = async () => { if (CIRCLE_SHA1) { if (CIRCLE_COMPARE_URL) { const reCompare = /compare\/([0-9a-z]+)\.\.\.([0-9a-z]+)$/; - const [, from, to] = CIRCLE_COMPARE_URL.match(reCompare); + const [, from] = CIRCLE_COMPARE_URL.match(reCompare); baseRef = from || 'master'; - sha = to || 'HEAD'; - } else { - sha = CIRCLE_SHA1; } + sha = CIRCLE_SHA1; } if (GITHUB_SHA) { From 1216120e8deeb5b054333bf4ffaad54890cb87c4 Mon Sep 17 00:00:00 2001 From: shellscape Date: Sat, 19 Oct 2019 10:11:40 -0400 Subject: [PATCH 6/7] chore: only use compare_url base on master --- scripts/run-changed.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/run-changed.js b/scripts/run-changed.js index b5ffcf095..438a262a0 100755 --- a/scripts/run-changed.js +++ b/scripts/run-changed.js @@ -13,12 +13,18 @@ const [, , task] = process.argv; const { log } = console; const getDiff = async () => { - const { CIRCLE_SHA1, CIRCLE_COMPARE_URL, GITHUB_SHA, GITHUB_BASE_REF } = process.env; + const { + CIRCLE_BRANCH, + CIRCLE_SHA1, + CIRCLE_COMPARE_URL, + GITHUB_SHA, + GITHUB_BASE_REF + } = process.env; let baseRef = 'master'; let sha = 'HEAD'; if (CIRCLE_SHA1) { - if (CIRCLE_COMPARE_URL) { + if (CIRCLE_BRANCH === 'master' && CIRCLE_COMPARE_URL) { const reCompare = /compare\/([0-9a-z]+)\.\.\.([0-9a-z]+)$/; const [, from] = CIRCLE_COMPARE_URL.match(reCompare); baseRef = from || 'master'; From ac84ee73f3ae281f9ffa6d0b34bc4afb89a64004 Mon Sep 17 00:00:00 2001 From: shellscape Date: Sat, 19 Oct 2019 10:19:23 -0400 Subject: [PATCH 7/7] chore: clean up changed package --- packages/beep/test/test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/beep/test/test.js b/packages/beep/test/test.js index 2ff77ea4f..b3056d43c 100644 --- a/packages/beep/test/test.js +++ b/packages/beep/test/test.js @@ -18,5 +18,3 @@ test('error', async (t) => { const { stderr } = await t.throwsAsync(throws); t.truthy(stderr.indexOf('\x07')); }); - -console.log('bar');