From 001686261c960a414f0b98394f321d1d5c08da84 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Wed, 20 Apr 2022 11:29:34 -0700 Subject: [PATCH] skip running copy-shared-files if shared files not changed and no new samples added (#134) * skip running copy-shared-files if shared files not changed and no new samples added Fix #45 * prettier * add list-of-samples to prettierignore --- .prettierignore | 3 +- .scripts/copy-shared-files.mjs | 35 +++++++++++++++---- .scripts/list-of-samples.json | 34 ++++++++++++++++++ .shared/.eslintrc.js | 2 +- .../.eslintrc.js | 2 +- activities-dependency-injection/.eslintrc.js | 2 +- activities-examples/.eslintrc.js | 2 +- activities-sticky-queues/.eslintrc.js | 2 +- child-workflows/.eslintrc.js | 2 +- continue-as-new/.eslintrc.js | 2 +- cron-workflows/.eslintrc.js | 2 +- dsl-interpreter/.eslintrc.js | 2 +- ejson/.eslintrc.js | 2 +- encryption/.eslintrc.js | 2 +- expense/.eslintrc.js | 2 +- grpc-calls/.eslintrc.js | 2 +- hello-world-mtls/.eslintrc.js | 2 +- hello-world/.eslintrc.js | 2 +- instrumentation/.eslintrc.js | 2 +- interceptors-opentelemetry/.eslintrc.js | 2 +- logging-sinks/.eslintrc.js | 2 +- patching-api/.eslintrc.js | 2 +- production/.eslintrc.js | 2 +- query-subscriptions/.eslintrc.js | 2 +- replay-history/.eslintrc.js | 2 +- search-attributes/.eslintrc.js | 2 +- signals-queries/.eslintrc.js | 2 +- timer-examples/.eslintrc.js | 2 +- timer-progress/.eslintrc.js | 2 +- 29 files changed, 91 insertions(+), 33 deletions(-) create mode 100644 .scripts/list-of-samples.json diff --git a/.prettierignore b/.prettierignore index 0b40c553..8e270d98 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,4 +6,5 @@ lib .next .vscode protobufs/protos/json-module.js -protobufs/protos/root.d.ts \ No newline at end of file +protobufs/protos/root.d.ts +.scripts/list-of-samples.json \ No newline at end of file diff --git a/.scripts/copy-shared-files.mjs b/.scripts/copy-shared-files.mjs index 8799b35b..61433454 100644 --- a/.scripts/copy-shared-files.mjs +++ b/.scripts/copy-shared-files.mjs @@ -1,4 +1,5 @@ // Run with https://github.com/google/zx +const STORED_SAMPLES = new Set(require('./list-of-samples.json').samples); const NON_SAMPLES = ['node_modules']; const ADDITIONAL_SAMPLES = []; @@ -29,8 +30,36 @@ const POST_CREATE_EXCLUDE = [ 'activities-cancellation-heartbeating', ]; +const FILES = [ + '.shared/tsconfig.json', + '.shared/.gitignore', + '.shared/.eslintrc.js', + '.shared/.post-create', + '.shared/.eslintignore', + '.shared/.npmrc', + '.shared/.nvmrc', +]; // By default, zx logs all commands spawned $.verbose = false; +let numSharedFilesChanged = 0; +for (let i = 0; i < FILES.length; i++) { + const checkForFiles = await $`git diff --shortstat ${FILES[i]}`; + if (checkForFiles.stdout) { + ++numSharedFilesChanged; + } +} + +const dirents = await fs.readdir('.', { withFileTypes: true }); +const samples = dirents + .filter((dirent) => dirent.isDirectory() && !NON_SAMPLES.includes(dirent.name) && dirent.name[0] !== '.') + .map(({ name }) => name) + .concat(ADDITIONAL_SAMPLES); + +const hasNewSamples = samples.find((sample) => !STORED_SAMPLES.has(sample)); +await fs.writeFile('./.scripts/list-of-samples.json', JSON.stringify({ samples }, null, ' ')); +if (numSharedFilesChanged === 0 && !hasNewSamples) { + process.exit(0); +} let [answer] = await question( `Running pre-commit hook. @@ -43,12 +72,6 @@ if ((answer ?? 'y').toUpperCase() !== 'Y') { process.exit(1); } -const dirents = await fs.readdir('.', { withFileTypes: true }); -const samples = dirents - .filter((dirent) => dirent.isDirectory() && !NON_SAMPLES.includes(dirent.name) && dirent.name[0] !== '.') - .map(({ name }) => name) - .concat(ADDITIONAL_SAMPLES); - process.stdout.write('Copying config files from .shared/ to samples...'); for (const sample of samples) { diff --git a/.scripts/list-of-samples.json b/.scripts/list-of-samples.json new file mode 100644 index 00000000..96ff9b66 --- /dev/null +++ b/.scripts/list-of-samples.json @@ -0,0 +1,34 @@ +{ + "samples": [ + "activities-cancellation-heartbeating", + "activities-dependency-injection", + "activities-examples", + "activities-sticky-queues", + "child-workflows", + "continue-as-new", + "cron-workflows", + "dsl-interpreter", + "ejson", + "encryption", + "expense", + "fetch-esm", + "grpc-calls", + "hello-world", + "hello-world-js", + "hello-world-mtls", + "instrumentation", + "interceptors-opentelemetry", + "logging-sinks", + "monorepo-folders", + "nextjs-ecommerce-oneclick", + "patching-api", + "production", + "protobufs", + "query-subscriptions", + "replay-history", + "search-attributes", + "signals-queries", + "timer-examples", + "timer-progress" + ] +} \ No newline at end of file diff --git a/.shared/.eslintrc.js b/.shared/.eslintrc.js index e0b95571..b8251a06 100644 --- a/.shared/.eslintrc.js +++ b/.shared/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/activities-cancellation-heartbeating/.eslintrc.js b/activities-cancellation-heartbeating/.eslintrc.js index e0b95571..b8251a06 100644 --- a/activities-cancellation-heartbeating/.eslintrc.js +++ b/activities-cancellation-heartbeating/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/activities-dependency-injection/.eslintrc.js b/activities-dependency-injection/.eslintrc.js index e0b95571..b8251a06 100644 --- a/activities-dependency-injection/.eslintrc.js +++ b/activities-dependency-injection/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/activities-examples/.eslintrc.js b/activities-examples/.eslintrc.js index e0b95571..b8251a06 100644 --- a/activities-examples/.eslintrc.js +++ b/activities-examples/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/activities-sticky-queues/.eslintrc.js b/activities-sticky-queues/.eslintrc.js index e0b95571..b8251a06 100644 --- a/activities-sticky-queues/.eslintrc.js +++ b/activities-sticky-queues/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/child-workflows/.eslintrc.js b/child-workflows/.eslintrc.js index e0b95571..b8251a06 100644 --- a/child-workflows/.eslintrc.js +++ b/child-workflows/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/continue-as-new/.eslintrc.js b/continue-as-new/.eslintrc.js index e0b95571..b8251a06 100644 --- a/continue-as-new/.eslintrc.js +++ b/continue-as-new/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/cron-workflows/.eslintrc.js b/cron-workflows/.eslintrc.js index e0b95571..b8251a06 100644 --- a/cron-workflows/.eslintrc.js +++ b/cron-workflows/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/dsl-interpreter/.eslintrc.js b/dsl-interpreter/.eslintrc.js index e0b95571..b8251a06 100644 --- a/dsl-interpreter/.eslintrc.js +++ b/dsl-interpreter/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/ejson/.eslintrc.js b/ejson/.eslintrc.js index e0b95571..b8251a06 100644 --- a/ejson/.eslintrc.js +++ b/ejson/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/encryption/.eslintrc.js b/encryption/.eslintrc.js index e0b95571..b8251a06 100644 --- a/encryption/.eslintrc.js +++ b/encryption/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/expense/.eslintrc.js b/expense/.eslintrc.js index e0b95571..b8251a06 100644 --- a/expense/.eslintrc.js +++ b/expense/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/grpc-calls/.eslintrc.js b/grpc-calls/.eslintrc.js index e0b95571..b8251a06 100644 --- a/grpc-calls/.eslintrc.js +++ b/grpc-calls/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/hello-world-mtls/.eslintrc.js b/hello-world-mtls/.eslintrc.js index e0b95571..b8251a06 100644 --- a/hello-world-mtls/.eslintrc.js +++ b/hello-world-mtls/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/hello-world/.eslintrc.js b/hello-world/.eslintrc.js index e0b95571..b8251a06 100644 --- a/hello-world/.eslintrc.js +++ b/hello-world/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/instrumentation/.eslintrc.js b/instrumentation/.eslintrc.js index e0b95571..b8251a06 100644 --- a/instrumentation/.eslintrc.js +++ b/instrumentation/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/interceptors-opentelemetry/.eslintrc.js b/interceptors-opentelemetry/.eslintrc.js index e0b95571..b8251a06 100644 --- a/interceptors-opentelemetry/.eslintrc.js +++ b/interceptors-opentelemetry/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/logging-sinks/.eslintrc.js b/logging-sinks/.eslintrc.js index e0b95571..b8251a06 100644 --- a/logging-sinks/.eslintrc.js +++ b/logging-sinks/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/patching-api/.eslintrc.js b/patching-api/.eslintrc.js index e0b95571..b8251a06 100644 --- a/patching-api/.eslintrc.js +++ b/patching-api/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/production/.eslintrc.js b/production/.eslintrc.js index e0b95571..b8251a06 100644 --- a/production/.eslintrc.js +++ b/production/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/query-subscriptions/.eslintrc.js b/query-subscriptions/.eslintrc.js index e0b95571..b8251a06 100644 --- a/query-subscriptions/.eslintrc.js +++ b/query-subscriptions/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/replay-history/.eslintrc.js b/replay-history/.eslintrc.js index e0b95571..b8251a06 100644 --- a/replay-history/.eslintrc.js +++ b/replay-history/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/search-attributes/.eslintrc.js b/search-attributes/.eslintrc.js index e0b95571..b8251a06 100644 --- a/search-attributes/.eslintrc.js +++ b/search-attributes/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/signals-queries/.eslintrc.js b/signals-queries/.eslintrc.js index e0b95571..b8251a06 100644 --- a/signals-queries/.eslintrc.js +++ b/signals-queries/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/timer-examples/.eslintrc.js b/timer-examples/.eslintrc.js index e0b95571..b8251a06 100644 --- a/timer-examples/.eslintrc.js +++ b/timer-examples/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, }, diff --git a/timer-progress/.eslintrc.js b/timer-progress/.eslintrc.js index e0b95571..b8251a06 100644 --- a/timer-progress/.eslintrc.js +++ b/timer-progress/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { rules: { 'no-restricted-imports': [ 'error', - ...builtinModules.filter(m => !ALLOWED_NODE_BUILTINS.has(m)).flatMap(m => [m, `node:${m}`]) + ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), ], }, },