From 5f4728d16a3c8976be7e22a9d1ddd8fb18463b5a Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Mon, 26 Oct 2020 19:29:21 +0000 Subject: [PATCH 01/28] chore(NA): remove kibana pre-commit hook installation from bootstrap --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3a2d13fd5ef3b..7ab6544fc03cf 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "kbn:watch": "node scripts/kibana --dev --logging.json=false", "build:types": "rm -rf ./target/types && tsc --p tsconfig.types.json", "docs:acceptApiChanges": "node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept", - "kbn:bootstrap": "node scripts/build_ts_refs && node scripts/register_git_hook", + "kbn:bootstrap": "node scripts/build_ts_refs", "spec_to_console": "node scripts/spec_to_console", "backport-skip-ci": "backport --prDescription \"[skip-ci]\"", "storybook": "node scripts/storybook", From be00e76f3d3192fa805d80dee1c6620d5d1c1e95 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Mon, 16 Nov 2020 19:02:09 +0000 Subject: [PATCH 02/28] chore(NA): add support for git ref flag on run precommit hook script --- src/dev/precommit_hook/get_files_for_commit.js | 8 ++++---- src/dev/run_precommit_hook.js | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/dev/precommit_hook/get_files_for_commit.js b/src/dev/precommit_hook/get_files_for_commit.js index e700b58782174..d8812894d559f 100644 --- a/src/dev/precommit_hook/get_files_for_commit.js +++ b/src/dev/precommit_hook/get_files_for_commit.js @@ -27,13 +27,13 @@ import { File } from '../file'; * Get the files that are staged for commit (excluding deleted files) * as `File` objects that are aware of their commit status. * - * @param {String} repoPath + * @param {String} gitRef * @return {Promise>} */ -export async function getFilesForCommit() { +export async function getFilesForCommit(gitRef) { const simpleGit = new SimpleGit(REPO_ROOT); - - const output = await fcb((cb) => simpleGit.diff(['--name-status', '--cached'], cb)); + const gitRefForDiff = gitRef ? gitRef : '--cached'; + const output = await fcb((cb) => simpleGit.diff(['--name-status', gitRefForDiff], cb)); return ( output diff --git a/src/dev/run_precommit_hook.js b/src/dev/run_precommit_hook.js index 455fe65e56d16..75c8c0c19cdda 100644 --- a/src/dev/run_precommit_hook.js +++ b/src/dev/run_precommit_hook.js @@ -24,7 +24,7 @@ import { getFilesForCommit, checkFileCasing } from './precommit_hook'; run( async ({ log, flags }) => { - const files = await getFilesForCommit(); + const files = await getFilesForCommit(flags.ref); const errors = []; try { @@ -52,15 +52,17 @@ run( }, { description: ` - Run checks on files that are staged for commit + Run checks on files that are staged for commit by default `, flags: { boolean: ['fix'], + string: ['ref'], default: { fix: false, }, help: ` --fix Execute eslint in --fix mode + --ref Run checks against any git ref files (example HEAD or ) instead of running against staged ones `, }, } From 7498f904353680f8cda4a6440d894b071948628e Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Mon, 16 Nov 2020 19:39:03 +0000 Subject: [PATCH 03/28] chore(NA): integrate quick commit checks within the CI --- src/dev/run_precommit_hook.js | 19 +++++++++++++++++-- test/scripts/checks/commit.sh | 14 ++++++++++++++ vars/tasks.groovy | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 test/scripts/checks/commit.sh diff --git a/src/dev/run_precommit_hook.js b/src/dev/run_precommit_hook.js index 75c8c0c19cdda..d7ea55e0c6b4e 100644 --- a/src/dev/run_precommit_hook.js +++ b/src/dev/run_precommit_hook.js @@ -17,7 +17,7 @@ * under the License. */ -import { run, combineErrors } from '@kbn/dev-utils'; +import { run, combineErrors, createFlagError } from '@kbn/dev-utils'; import * as Eslint from './eslint'; import * as Sasslint from './sasslint'; import { getFilesForCommit, checkFileCasing } from './precommit_hook'; @@ -27,6 +27,20 @@ run( const files = await getFilesForCommit(flags.ref); const errors = []; + const maxFilesCount = flags['max-files'] + ? Number.parseInt(String(flags['max-files']), 10) + : undefined; + if (maxFilesCount !== undefined && (!Number.isFinite(maxFilesCount) || maxFilesCount < 1)) { + throw createFlagError('expected --max-files to be a number greater than 0'); + } + + if (maxFilesCount && files.length > maxFilesCount) { + log.info( + `--max-files is set to ${maxFilesCount} and ${files.length} were discovered. The current script execution will be skipped.` + ); + return; + } + try { await checkFileCasing(log, files); } catch (error) { @@ -56,12 +70,13 @@ run( `, flags: { boolean: ['fix'], - string: ['ref'], + string: ['max-files', 'ref'], default: { fix: false, }, help: ` --fix Execute eslint in --fix mode + --max-files Max files number to check against. If exceeded the script will skip the execution --ref Run checks against any git ref files (example HEAD or ) instead of running against staged ones `, }, diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh new file mode 100644 index 0000000000000..50c9f5e3813e2 --- /dev/null +++ b/test/scripts/checks/commit.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +source src/dev/ci_setup/setup_env.sh + +# Runs pre-commit hook script for the files touched in the last commit. +# That way we can ensure a set of quick commit checks earlier as we removed +# the pre-commit hook installation by default. +# If files are more than 200 we will skip it and just use +# the further ci steps that already check linting and file casing for the entire repo. +checks-reporter-with-killswitch "Quick commit checks" \ + node scripts/precommit_hook.js \ + --ref HEAD~1..HEAD \ + --max-files 200 + --verbose diff --git a/vars/tasks.groovy b/vars/tasks.groovy index 5a8161ebd3608..983bd91b40b50 100644 --- a/vars/tasks.groovy +++ b/vars/tasks.groovy @@ -4,6 +4,7 @@ def call(List closures) { def check() { tasks([ + kibanaPipeline.scriptTask('Quick Commit Checks', 'test/scripts/checks/commit.sh'), kibanaPipeline.scriptTask('Check Telemetry Schema', 'test/scripts/checks/telemetry.sh'), kibanaPipeline.scriptTask('Check TypeScript Projects', 'test/scripts/checks/ts_projects.sh'), kibanaPipeline.scriptTask('Check Doc API Changes', 'test/scripts/checks/doc_api_changes.sh'), From fa20bbe62f6103212ae76d11c5eb273b657e809d Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 17 Nov 2020 17:02:23 +0000 Subject: [PATCH 04/28] chore(NA): introduce logging trap to warn about quick commit checks failure and how to reproduce it --- test/scripts/checks/commit.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh index 50c9f5e3813e2..16c27f2cbf108 100644 --- a/test/scripts/checks/commit.sh +++ b/test/scripts/checks/commit.sh @@ -2,13 +2,21 @@ source src/dev/ci_setup/setup_env.sh +run_quick_commit_checks() { + node scripts/precommit_hook.js \ + --ref HEAD~1..HEAD \ + --max-files 200 \ + --verbose || return 1 +} + # Runs pre-commit hook script for the files touched in the last commit. # That way we can ensure a set of quick commit checks earlier as we removed # the pre-commit hook installation by default. # If files are more than 200 we will skip it and just use # the further ci steps that already check linting and file casing for the entire repo. checks-reporter-with-killswitch "Quick commit checks" \ - node scripts/precommit_hook.js \ - --ref HEAD~1..HEAD \ - --max-files 200 - --verbose + run_quick_commit_checks || { + echo "Quick commit checks failed."; + echo "You reproduce that locally by running `node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200`"; + exit 1; +} From da120837304247c19db42c1ef7fa36b71c20c398 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 17 Nov 2020 17:33:03 +0000 Subject: [PATCH 05/28] chore(NA): update quick commit checks message --- test/scripts/checks/commit.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh index 16c27f2cbf108..f4fc2c760c5e8 100644 --- a/test/scripts/checks/commit.sh +++ b/test/scripts/checks/commit.sh @@ -18,5 +18,10 @@ checks-reporter-with-killswitch "Quick commit checks" \ run_quick_commit_checks || { echo "Quick commit checks failed."; echo "You reproduce that locally by running `node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200`"; + + echo "!!!!!!!! ATTENTION !!!!!!!!" + echo "That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook."; + echo "If you want, you can still manually install the pre-commit hook locally by running `node scripts/register_git_hook locally`"; + exit 1; } From 62584fa3d92e0b85d0edccd2d6bfac50804db0fb Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 17 Nov 2020 17:47:29 +0000 Subject: [PATCH 06/28] fix(NA): quick commit checks function def --- test/scripts/checks/commit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh index f4fc2c760c5e8..2047a08e538a5 100644 --- a/test/scripts/checks/commit.sh +++ b/test/scripts/checks/commit.sh @@ -2,7 +2,7 @@ source src/dev/ci_setup/setup_env.sh -run_quick_commit_checks() { +function run_quick_commit_checks() { node scripts/precommit_hook.js \ --ref HEAD~1..HEAD \ --max-files 200 \ From 8a8776be692943180ab7671fd0d1b61b42bffbd3 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 17 Nov 2020 18:26:35 +0000 Subject: [PATCH 07/28] chore(NA): fix quick commit checks message quotes --- test/scripts/checks/commit.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh index 2047a08e538a5..a0a7038450db1 100644 --- a/test/scripts/checks/commit.sh +++ b/test/scripts/checks/commit.sh @@ -17,11 +17,11 @@ function run_quick_commit_checks() { checks-reporter-with-killswitch "Quick commit checks" \ run_quick_commit_checks || { echo "Quick commit checks failed."; - echo "You reproduce that locally by running `node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200`"; + echo "You reproduce that locally by running 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200'"; echo "!!!!!!!! ATTENTION !!!!!!!!" echo "That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook."; - echo "If you want, you can still manually install the pre-commit hook locally by running `node scripts/register_git_hook locally`"; + echo "If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally'"; exit 1; } From 2bdd5edb2344415bf6ea0dbeee072b48a1b8f48d Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 17 Nov 2020 18:50:27 +0000 Subject: [PATCH 08/28] chore(NA): fix functional call --- test/scripts/checks/commit.sh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh index a0a7038450db1..39b4781eaae90 100644 --- a/test/scripts/checks/commit.sh +++ b/test/scripts/checks/commit.sh @@ -2,7 +2,7 @@ source src/dev/ci_setup/setup_env.sh -function run_quick_commit_checks() { +run_quick_commit_checks() { node scripts/precommit_hook.js \ --ref HEAD~1..HEAD \ --max-files 200 \ @@ -15,13 +15,14 @@ function run_quick_commit_checks() { # If files are more than 200 we will skip it and just use # the further ci steps that already check linting and file casing for the entire repo. checks-reporter-with-killswitch "Quick commit checks" \ - run_quick_commit_checks || { - echo "Quick commit checks failed."; - echo "You reproduce that locally by running 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200'"; - - echo "!!!!!!!! ATTENTION !!!!!!!!" - echo "That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook."; - echo "If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally'"; - - exit 1; -} + run_quick_commit_checks +# run_quick_commit_checks || { +# echo "Quick commit checks failed."; +# echo "You reproduce that locally by running 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200'"; +# +# echo "!!!!!!!! ATTENTION !!!!!!!!" +# echo "That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook."; +# echo "If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally'"; +# +# exit 1; +# } From 2b743beb327eb3eb2044af2401fcdec9c699601b Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 17 Nov 2020 19:12:25 +0000 Subject: [PATCH 09/28] chore(NA): fix script to run --- test/scripts/checks/commit.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh index 39b4781eaae90..5ee15e8057df2 100644 --- a/test/scripts/checks/commit.sh +++ b/test/scripts/checks/commit.sh @@ -15,7 +15,17 @@ run_quick_commit_checks() { # If files are more than 200 we will skip it and just use # the further ci steps that already check linting and file casing for the entire repo. checks-reporter-with-killswitch "Quick commit checks" \ - run_quick_commit_checks + node scripts/precommit_hook.js \ + --ref HEAD~1..HEAD \ + --max-files 200 \ + --verbose || { \ + echo "Quick commit checks failed."; \ + echo "You reproduce that locally by running 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200'"; \ + echo "!!!!!!!! ATTENTION !!!!!!!!"; \ + echo "That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook."; \ + echo "If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally'"; \ + exit 1; \ + } \ # run_quick_commit_checks || { # echo "Quick commit checks failed."; # echo "You reproduce that locally by running 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200'"; From 671ac1787bdd85137a13007afc6df898b077c38c Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 17 Nov 2020 19:45:05 +0000 Subject: [PATCH 10/28] chore(NA): add unexpected debugger statement to test quick commit checks --- src/dev/run_precommit_hook.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dev/run_precommit_hook.js b/src/dev/run_precommit_hook.js index d7ea55e0c6b4e..d8e373ac64660 100644 --- a/src/dev/run_precommit_hook.js +++ b/src/dev/run_precommit_hook.js @@ -27,6 +27,8 @@ run( const files = await getFilesForCommit(flags.ref); const errors = []; + debugger; + const maxFilesCount = flags['max-files'] ? Number.parseInt(String(flags['max-files']), 10) : undefined; From 1d2be917e2018623ea5a0bba41f26e41b13b0d96 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 17 Nov 2020 20:14:07 +0000 Subject: [PATCH 11/28] chore(NA): update message to log before quick commit checks --- test/scripts/checks/commit.sh | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh index 5ee15e8057df2..6f35952ea3bf1 100644 --- a/test/scripts/checks/commit.sh +++ b/test/scripts/checks/commit.sh @@ -2,12 +2,10 @@ source src/dev/ci_setup/setup_env.sh -run_quick_commit_checks() { - node scripts/precommit_hook.js \ - --ref HEAD~1..HEAD \ - --max-files 200 \ - --verbose || return 1 -} +echo "!!!!!!!! ATTENTION !!!!!!!!"; \ +echo "That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook."; +echo "If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally'"; +echo "!!!!!!!!!!!!!!!!!! !!!!!!!!"; \ # Runs pre-commit hook script for the files touched in the last commit. # That way we can ensure a set of quick commit checks earlier as we removed @@ -18,21 +16,4 @@ checks-reporter-with-killswitch "Quick commit checks" \ node scripts/precommit_hook.js \ --ref HEAD~1..HEAD \ --max-files 200 \ - --verbose || { \ - echo "Quick commit checks failed."; \ - echo "You reproduce that locally by running 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200'"; \ - echo "!!!!!!!! ATTENTION !!!!!!!!"; \ - echo "That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook."; \ - echo "If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally'"; \ - exit 1; \ - } \ -# run_quick_commit_checks || { -# echo "Quick commit checks failed."; -# echo "You reproduce that locally by running 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200'"; -# -# echo "!!!!!!!! ATTENTION !!!!!!!!" -# echo "That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook."; -# echo "If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally'"; -# -# exit 1; -# } + --verbose From 3580b0f1013706ad8ee62c79225cb55bdf0b3973 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 17 Nov 2020 20:14:53 +0000 Subject: [PATCH 12/28] chore(NA): remove extra debugger statement --- src/dev/run_precommit_hook.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/dev/run_precommit_hook.js b/src/dev/run_precommit_hook.js index d8e373ac64660..d7ea55e0c6b4e 100644 --- a/src/dev/run_precommit_hook.js +++ b/src/dev/run_precommit_hook.js @@ -27,8 +27,6 @@ run( const files = await getFilesForCommit(flags.ref); const errors = []; - debugger; - const maxFilesCount = flags['max-files'] ? Number.parseInt(String(flags['max-files']), 10) : undefined; From 59cefd732c20144c1b19b1c5f9944b2c906a80cf Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 17 Nov 2020 23:12:05 +0000 Subject: [PATCH 13/28] chore(NA): add echo message inline with script execution --- test/scripts/checks/commit.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh index 6f35952ea3bf1..66448a122c061 100644 --- a/test/scripts/checks/commit.sh +++ b/test/scripts/checks/commit.sh @@ -2,17 +2,16 @@ source src/dev/ci_setup/setup_env.sh -echo "!!!!!!!! ATTENTION !!!!!!!!"; \ -echo "That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook."; -echo "If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally'"; -echo "!!!!!!!!!!!!!!!!!! !!!!!!!!"; \ - # Runs pre-commit hook script for the files touched in the last commit. # That way we can ensure a set of quick commit checks earlier as we removed # the pre-commit hook installation by default. # If files are more than 200 we will skip it and just use # the further ci steps that already check linting and file casing for the entire repo. checks-reporter-with-killswitch "Quick commit checks" \ + echo "!!!!!!!! ATTENTION !!!!!!!! +That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook. +If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally' +!!!!!!!!!!!!!!!!!! !!!!!!!!" && \ node scripts/precommit_hook.js \ --ref HEAD~1..HEAD \ --max-files 200 \ From 7d7cfe740365338398e0f8a97ea96651e6f8e61e Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 17 Nov 2020 23:13:20 +0000 Subject: [PATCH 14/28] chore(NA): add unexpected debugger statement to test quick commit checks --- src/dev/run_precommit_hook.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dev/run_precommit_hook.js b/src/dev/run_precommit_hook.js index d7ea55e0c6b4e..d8e373ac64660 100644 --- a/src/dev/run_precommit_hook.js +++ b/src/dev/run_precommit_hook.js @@ -27,6 +27,8 @@ run( const files = await getFilesForCommit(flags.ref); const errors = []; + debugger; + const maxFilesCount = flags['max-files'] ? Number.parseInt(String(flags['max-files']), 10) : undefined; From c0ab68409b07f34bf1a9bd3dcfd484ff1f31cb13 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 17 Nov 2020 23:14:59 +0000 Subject: [PATCH 15/28] chore(NA): remove extra usage of debug statement --- src/dev/run_precommit_hook.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/dev/run_precommit_hook.js b/src/dev/run_precommit_hook.js index d8e373ac64660..d7ea55e0c6b4e 100644 --- a/src/dev/run_precommit_hook.js +++ b/src/dev/run_precommit_hook.js @@ -27,8 +27,6 @@ run( const files = await getFilesForCommit(flags.ref); const errors = []; - debugger; - const maxFilesCount = flags['max-files'] ? Number.parseInt(String(flags['max-files']), 10) : undefined; From d0a574c741d5ec76cef9647f75040a42e1283802 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 18 Nov 2020 00:08:23 +0000 Subject: [PATCH 16/28] chore(NA): wrapping quick commit checks in a func --- test/scripts/checks/commit.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh index 66448a122c061..236c7c69da614 100644 --- a/test/scripts/checks/commit.sh +++ b/test/scripts/checks/commit.sh @@ -2,17 +2,19 @@ source src/dev/ci_setup/setup_env.sh +run_quick_commit_checks() { + echo "!!!!!!!! ATTENTION !!!!!!!! +That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook. +If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally' +!!!!!!!!!!!!!!!!!! !!!!!!!!" + + node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200 --verbose +} + # Runs pre-commit hook script for the files touched in the last commit. # That way we can ensure a set of quick commit checks earlier as we removed # the pre-commit hook installation by default. # If files are more than 200 we will skip it and just use # the further ci steps that already check linting and file casing for the entire repo. checks-reporter-with-killswitch "Quick commit checks" \ - echo "!!!!!!!! ATTENTION !!!!!!!! -That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook. -If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally' -!!!!!!!!!!!!!!!!!! !!!!!!!!" && \ - node scripts/precommit_hook.js \ - --ref HEAD~1..HEAD \ - --max-files 200 \ - --verbose + run_quick_commit_checks From 513e5813d51f53816ac5e6543abf3bb047722425 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 18 Nov 2020 00:23:10 +0000 Subject: [PATCH 17/28] chore(NA): export function to use later --- test/scripts/checks/commit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh index 236c7c69da614..e4d05c843af43 100644 --- a/test/scripts/checks/commit.sh +++ b/test/scripts/checks/commit.sh @@ -2,7 +2,7 @@ source src/dev/ci_setup/setup_env.sh -run_quick_commit_checks() { +export run_quick_commit_checks() { echo "!!!!!!!! ATTENTION !!!!!!!! That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook. If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally' From c9934ea180cc567a4dc25a16fcdec32f2b4d4ba7 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 18 Nov 2020 00:51:05 +0000 Subject: [PATCH 18/28] chore(NA): export function to use later --- test/scripts/checks/commit.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh index e4d05c843af43..f95637730a0bc 100644 --- a/test/scripts/checks/commit.sh +++ b/test/scripts/checks/commit.sh @@ -2,7 +2,7 @@ source src/dev/ci_setup/setup_env.sh -export run_quick_commit_checks() { +function run_quick_commit_checks() { echo "!!!!!!!! ATTENTION !!!!!!!! That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook. If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally' @@ -11,6 +11,8 @@ If you want, you can still manually install the pre-commit hook locally by runni node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200 --verbose } +export -f run_quick_commit_checks + # Runs pre-commit hook script for the files touched in the last commit. # That way we can ensure a set of quick commit checks earlier as we removed # the pre-commit hook installation by default. From 57dabc2c42e56e66398b01bb7e99773d2877e6fa Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 18 Nov 2020 02:34:52 +0000 Subject: [PATCH 19/28] chore(NA): use child bash script on github checks reporter --- test/scripts/checks/commit.sh | 22 ------------------- test/scripts/checks/commit/commit.sh | 11 ++++++++++ .../checks/commit/commit_check_runner.sh | 12 ++++++++++ vars/tasks.groovy | 2 +- 4 files changed, 24 insertions(+), 23 deletions(-) delete mode 100644 test/scripts/checks/commit.sh create mode 100644 test/scripts/checks/commit/commit.sh create mode 100644 test/scripts/checks/commit/commit_check_runner.sh diff --git a/test/scripts/checks/commit.sh b/test/scripts/checks/commit.sh deleted file mode 100644 index f95637730a0bc..0000000000000 --- a/test/scripts/checks/commit.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - -source src/dev/ci_setup/setup_env.sh - -function run_quick_commit_checks() { - echo "!!!!!!!! ATTENTION !!!!!!!! -That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook. -If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally' -!!!!!!!!!!!!!!!!!! !!!!!!!!" - - node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200 --verbose -} - -export -f run_quick_commit_checks - -# Runs pre-commit hook script for the files touched in the last commit. -# That way we can ensure a set of quick commit checks earlier as we removed -# the pre-commit hook installation by default. -# If files are more than 200 we will skip it and just use -# the further ci steps that already check linting and file casing for the entire repo. -checks-reporter-with-killswitch "Quick commit checks" \ - run_quick_commit_checks diff --git a/test/scripts/checks/commit/commit.sh b/test/scripts/checks/commit/commit.sh new file mode 100644 index 0000000000000..b7ccf688139b0 --- /dev/null +++ b/test/scripts/checks/commit/commit.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +source src/dev/ci_setup/setup_env.sh + +# Runs pre-commit hook script for the files touched in the last commit. +# That way we can ensure a set of quick commit checks earlier as we removed +# the pre-commit hook installation by default. +# If files are more than 200 we will skip it and just use +# the further ci steps that already check linting and file casing for the entire repo. +checks-reporter-with-killswitch "Quick commit checks" \ + commit_check_runner.sh diff --git a/test/scripts/checks/commit/commit_check_runner.sh b/test/scripts/checks/commit/commit_check_runner.sh new file mode 100644 index 0000000000000..4bbcc13f78c16 --- /dev/null +++ b/test/scripts/checks/commit/commit_check_runner.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +run_quick_commit_checks() { + echo "!!!!!!!! ATTENTION !!!!!!!! +That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook. +If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally' +!!!!!!!!!!!!!!!!!! !!!!!!!!" + + node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200 --verbose +} + +run_quick_commit_checks diff --git a/vars/tasks.groovy b/vars/tasks.groovy index 983bd91b40b50..fb8e9e3eced24 100644 --- a/vars/tasks.groovy +++ b/vars/tasks.groovy @@ -4,7 +4,7 @@ def call(List closures) { def check() { tasks([ - kibanaPipeline.scriptTask('Quick Commit Checks', 'test/scripts/checks/commit.sh'), + kibanaPipeline.scriptTask('Quick Commit Checks', 'test/scripts/checks/commit/commit.sh'), kibanaPipeline.scriptTask('Check Telemetry Schema', 'test/scripts/checks/telemetry.sh'), kibanaPipeline.scriptTask('Check TypeScript Projects', 'test/scripts/checks/ts_projects.sh'), kibanaPipeline.scriptTask('Check Doc API Changes', 'test/scripts/checks/doc_api_changes.sh'), From 8a40ccd0c70e8c4caef4296e686dd62874b4115a Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 18 Nov 2020 03:00:12 +0000 Subject: [PATCH 20/28] chore(NA): define dir context for commit_check_runner.sh --- test/scripts/checks/commit/commit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scripts/checks/commit/commit.sh b/test/scripts/checks/commit/commit.sh index b7ccf688139b0..5d300468a65e3 100644 --- a/test/scripts/checks/commit/commit.sh +++ b/test/scripts/checks/commit/commit.sh @@ -8,4 +8,4 @@ source src/dev/ci_setup/setup_env.sh # If files are more than 200 we will skip it and just use # the further ci steps that already check linting and file casing for the entire repo. checks-reporter-with-killswitch "Quick commit checks" \ - commit_check_runner.sh + "$(dirname "${0}")/commit_check_runner.sh" From b2f58b64fc183fd1916e3d3bd8ebb86d03c1a3f9 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 18 Nov 2020 03:20:29 +0000 Subject: [PATCH 21/28] fix(NA): permissions for commit_check_runner.sh --- test/scripts/checks/commit/commit_check_runner.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 test/scripts/checks/commit/commit_check_runner.sh diff --git a/test/scripts/checks/commit/commit_check_runner.sh b/test/scripts/checks/commit/commit_check_runner.sh old mode 100644 new mode 100755 From c9bf28985987b6f87c69a15122be07afb9cb7f23 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 18 Nov 2020 03:22:20 +0000 Subject: [PATCH 22/28] fix(NA): permissions for commit.sh --- test/scripts/checks/commit/commit.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 test/scripts/checks/commit/commit.sh diff --git a/test/scripts/checks/commit/commit.sh b/test/scripts/checks/commit/commit.sh old mode 100644 new mode 100755 From 18e8ae07bdd5c0c7958ec7ad520087fcefa79e73 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 18 Nov 2020 03:40:28 +0000 Subject: [PATCH 23/28] chore(NA): format message to log --- test/scripts/checks/commit/commit_check_runner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scripts/checks/commit/commit_check_runner.sh b/test/scripts/checks/commit/commit_check_runner.sh index 4bbcc13f78c16..7a0a0ae353be9 100755 --- a/test/scripts/checks/commit/commit_check_runner.sh +++ b/test/scripts/checks/commit/commit_check_runner.sh @@ -4,7 +4,7 @@ run_quick_commit_checks() { echo "!!!!!!!! ATTENTION !!!!!!!! That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook. If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally' -!!!!!!!!!!!!!!!!!! !!!!!!!!" +!!!!!!!!!!!!!!!!!! !!!!!!!!\n" node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200 --verbose } From efa491a368fc8fc0994b0dc53296f7a914eba4ea Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 18 Nov 2020 03:41:24 +0000 Subject: [PATCH 24/28] chore(NA): add unexpected debugger statement to test quick commit checks --- src/dev/run_precommit_hook.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dev/run_precommit_hook.js b/src/dev/run_precommit_hook.js index d7ea55e0c6b4e..d8e373ac64660 100644 --- a/src/dev/run_precommit_hook.js +++ b/src/dev/run_precommit_hook.js @@ -27,6 +27,8 @@ run( const files = await getFilesForCommit(flags.ref); const errors = []; + debugger; + const maxFilesCount = flags['max-files'] ? Number.parseInt(String(flags['max-files']), 10) : undefined; From 8511c6988e8de49aaf4944d507525744c0a53804 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 18 Nov 2020 03:43:31 +0000 Subject: [PATCH 25/28] chore(NA): remove extra usage of debug statement --- src/dev/run_precommit_hook.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/dev/run_precommit_hook.js b/src/dev/run_precommit_hook.js index d8e373ac64660..d7ea55e0c6b4e 100644 --- a/src/dev/run_precommit_hook.js +++ b/src/dev/run_precommit_hook.js @@ -27,8 +27,6 @@ run( const files = await getFilesForCommit(flags.ref); const errors = []; - debugger; - const maxFilesCount = flags['max-files'] ? Number.parseInt(String(flags['max-files']), 10) : undefined; From 9e75ec68738e8e868cc1fb21b3f76064a9acf9a5 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 18 Nov 2020 04:21:19 +0000 Subject: [PATCH 26/28] chore(NA): format runner message --- test/scripts/checks/commit/commit_check_runner.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/scripts/checks/commit/commit_check_runner.sh b/test/scripts/checks/commit/commit_check_runner.sh index 7a0a0ae353be9..8d35c3698f3e1 100755 --- a/test/scripts/checks/commit/commit_check_runner.sh +++ b/test/scripts/checks/commit/commit_check_runner.sh @@ -4,7 +4,8 @@ run_quick_commit_checks() { echo "!!!!!!!! ATTENTION !!!!!!!! That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook. If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally' -!!!!!!!!!!!!!!!!!! !!!!!!!!\n" +!!!!!!!!!!!!!!!!!!!!!!!!!!! +" node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200 --verbose } From a58a1a5b7b6abc89acf081515c1315488951027b Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 18 Nov 2020 21:53:23 +0000 Subject: [PATCH 27/28] chore(NA): replace log.info by log.warning --- src/dev/run_precommit_hook.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dev/run_precommit_hook.js b/src/dev/run_precommit_hook.js index d7ea55e0c6b4e..59b9ccc486031 100644 --- a/src/dev/run_precommit_hook.js +++ b/src/dev/run_precommit_hook.js @@ -35,7 +35,7 @@ run( } if (maxFilesCount && files.length > maxFilesCount) { - log.info( + log.warning( `--max-files is set to ${maxFilesCount} and ${files.length} were discovered. The current script execution will be skipped.` ); return; From 96eb6d97b0ed350cff35379d3ffedffbc2365b4b Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Thu, 3 Dec 2020 23:29:32 +0000 Subject: [PATCH 28/28] docs(NA): include docs for removing the pre-commit hook auto installation --- docs/developer/getting-started/index.asciidoc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/developer/getting-started/index.asciidoc b/docs/developer/getting-started/index.asciidoc index 9b334a55c4203..1f07850909565 100644 --- a/docs/developer/getting-started/index.asciidoc +++ b/docs/developer/getting-started/index.asciidoc @@ -110,6 +110,20 @@ View all available options by running `yarn start --help` Read about more advanced options for <>. +[discrete] +=== Install pre-commit hook (optional) + +In case you want to run a couple of checks like linting or check the file casing of the files to commit, we provide +a way to install a pre-commit hook. To configure it you just need to run the following: + +[source,bash] +---- +node scripts/register_git_hook +---- + +After the script completes the pre-commit hook will be created within the file `.git/hooks/pre-commit`. +If you choose to not install it, don't worry, we still run a quick ci check to provide feedback earliest as we can about the same checks. + [discrete] === Code away!