Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(NA): removes auto install of pre-commit hook #83566

Merged
merged 50 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5f4728d
chore(NA): remove kibana pre-commit hook installation from bootstrap
mistic Oct 26, 2020
0acaf8a
Merge remote-tracking branch 'upstream/master' into remove-pre-commit…
mistic Nov 13, 2020
4447424
Merge branch 'master' into remove-pre-commit-hook
mistic Nov 16, 2020
ccd6253
Merge branch 'master' into remove-pre-commit-hook
mistic Nov 16, 2020
be00e76
chore(NA): add support for git ref flag on run precommit hook script
mistic Nov 16, 2020
7498f90
chore(NA): integrate quick commit checks within the CI
mistic Nov 16, 2020
28b39b6
Merge remote-tracking branch 'upstream/master' into remove-pre-commit…
mistic Nov 17, 2020
fa20bbe
chore(NA): introduce logging trap to warn about quick commit checks f…
mistic Nov 17, 2020
da12083
chore(NA): update quick commit checks message
mistic Nov 17, 2020
62584fa
fix(NA): quick commit checks function def
mistic Nov 17, 2020
8a8776b
chore(NA): fix quick commit checks message quotes
mistic Nov 17, 2020
2bdd5ed
chore(NA): fix functional call
mistic Nov 17, 2020
2b743be
chore(NA): fix script to run
mistic Nov 17, 2020
671ac17
chore(NA): add unexpected debugger statement to test quick commit checks
mistic Nov 17, 2020
1d2be91
chore(NA): update message to log before quick commit checks
mistic Nov 17, 2020
3580b0f
chore(NA): remove extra debugger statement
mistic Nov 17, 2020
c89f849
Merge branch 'master' into remove-pre-commit-hook
kibanamachine Nov 17, 2020
fd7eaff
Merge remote-tracking branch 'upstream/master' into remove-pre-commit…
mistic Nov 17, 2020
b37e0de
Merge branch 'remove-pre-commit-hook' of github.com:mistic/kibana int…
mistic Nov 17, 2020
59cefd7
chore(NA): add echo message inline with script execution
mistic Nov 17, 2020
7d7cfe7
chore(NA): add unexpected debugger statement to test quick commit checks
mistic Nov 17, 2020
c0ab684
chore(NA): remove extra usage of debug statement
mistic Nov 17, 2020
d0a574c
chore(NA): wrapping quick commit checks in a func
mistic Nov 18, 2020
513e581
chore(NA): export function to use later
mistic Nov 18, 2020
c9934ea
chore(NA): export function to use later
mistic Nov 18, 2020
57dabc2
chore(NA): use child bash script on github checks reporter
mistic Nov 18, 2020
8a40ccd
chore(NA): define dir context for commit_check_runner.sh
mistic Nov 18, 2020
b2f58b6
fix(NA): permissions for commit_check_runner.sh
mistic Nov 18, 2020
c9bf289
fix(NA): permissions for commit.sh
mistic Nov 18, 2020
18e8ae0
chore(NA): format message to log
mistic Nov 18, 2020
efa491a
chore(NA): add unexpected debugger statement to test quick commit checks
mistic Nov 18, 2020
8511c69
chore(NA): remove extra usage of debug statement
mistic Nov 18, 2020
9e75ec6
chore(NA): format runner message
mistic Nov 18, 2020
a58a1a5
chore(NA): replace log.info by log.warning
mistic Nov 18, 2020
9e8e9cc
Merge remote-tracking branch 'upstream/master' into remove-pre-commit…
mistic Nov 18, 2020
4ea0f7c
Merge branch 'master' into remove-pre-commit-hook
kibanamachine Nov 19, 2020
9e66d71
Merge branch 'master' into remove-pre-commit-hook
kibanamachine Nov 22, 2020
f693494
Merge remote-tracking branch 'upstream/master' into remove-pre-commit…
mistic Nov 22, 2020
caf6d6d
Merge branch 'master' into remove-pre-commit-hook
kibanamachine Nov 24, 2020
f69476c
Merge remote-tracking branch 'upstream/master' into remove-pre-commit…
mistic Nov 24, 2020
35004d5
Merge branch 'master' into remove-pre-commit-hook
mistic Nov 25, 2020
de35263
Merge remote-tracking branch 'upstream/master' into remove-pre-commit…
mistic Nov 26, 2020
911c668
Merge branch 'master' into remove-pre-commit-hook
kibanamachine Nov 30, 2020
e8fc4e1
Merge branch 'master' into remove-pre-commit-hook
kibanamachine Dec 2, 2020
6e04211
Merge branch 'master' into remove-pre-commit-hook
kibanamachine Dec 3, 2020
96eb6d9
docs(NA): include docs for removing the pre-commit hook auto installa…
mistic Dec 3, 2020
553f78e
Merge branch 'remove-pre-commit-hook' of github.com:mistic/kibana int…
mistic Dec 3, 2020
c117403
Merge branch 'master' into remove-pre-commit-hook
kibanamachine Dec 3, 2020
90535b6
Merge branch 'master' into remove-pre-commit-hook
kibanamachine Dec 4, 2020
e6f26ea
Merge branch 'master' into remove-pre-commit-hook
kibanamachine Dec 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/developer/getting-started/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ View all available options by running `yarn start --help`

Read about more advanced options for <<running-kibana-advanced>>.

[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!

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/dev/precommit_hook/get_files_for_commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array<File>>}
*/
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
Expand Down
23 changes: 20 additions & 3 deletions src/dev/run_precommit_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,30 @@
* 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';

run(
async ({ log, flags }) => {
const files = await getFilesForCommit();
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.warning(
`--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) {
Expand All @@ -52,15 +66,18 @@ 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: ['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 <commit_sha>) instead of running against staged ones
`,
},
}
Expand Down
11 changes: 11 additions & 0 deletions test/scripts/checks/commit/commit.sh
Original file line number Diff line number Diff line change
@@ -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" \
"$(dirname "${0}")/commit_check_runner.sh"
13 changes: 13 additions & 0 deletions test/scripts/checks/commit/commit_check_runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/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
1 change: 1 addition & 0 deletions vars/tasks.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def call(List<Closure> closures) {

def check() {
tasks([
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 Jest Configs', 'test/scripts/checks/jest_configs.sh'),
Expand Down