Skip to content

Commit

Permalink
skip running copy-shared-files if shared files not changed and no new…
Browse files Browse the repository at this point in the history
… samples added (temporalio#134)

* skip running copy-shared-files if shared files not changed and no new samples added

Fix temporalio#45

* prettier

* add list-of-samples to prettierignore
  • Loading branch information
vkarpov15 authored Apr 20, 2022
1 parent 5275d91 commit 0016862
Show file tree
Hide file tree
Showing 29 changed files with 91 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ lib
.next
.vscode
protobufs/protos/json-module.js
protobufs/protos/root.d.ts
protobufs/protos/root.d.ts
.scripts/list-of-samples.json
35 changes: 29 additions & 6 deletions .scripts/copy-shared-files.mjs
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
34 changes: 34 additions & 0 deletions .scripts/list-of-samples.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
2 changes: 1 addition & 1 deletion .shared/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion activities-cancellation-heartbeating/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion activities-dependency-injection/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion activities-examples/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion activities-sticky-queues/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion child-workflows/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion continue-as-new/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion cron-workflows/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion dsl-interpreter/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion ejson/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion encryption/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion expense/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion grpc-calls/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion hello-world-mtls/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion hello-world/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion interceptors-opentelemetry/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion logging-sinks/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion patching-api/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion production/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion query-subscriptions/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion replay-history/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion search-attributes/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion signals-queries/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion timer-examples/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion timer-progress/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]),
],
},
},
Expand Down

0 comments on commit 0016862

Please sign in to comment.