Remove husky (#24887)

* feat(NA): remove husky dependency and implement a git hooks registering mechanism.

* fix(NA): apply executable chmod to the created kbn git hook script.

* fix(NA): run npm script on the git pre commit hook silently.

* refact(NA): apply changes according the PR review.

* refact(NA): apply changes according PR review.
This commit is contained in:
Tiago Costa 2018-11-15 01:34:45 +00:00 committed by GitHub
parent 53f5f50b71
commit 1155b81b4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 162 additions and 17 deletions

View file

@ -55,7 +55,7 @@
"uiFramework:documentComponent": "cd packages/kbn-ui-framework && yarn documentComponent",
"kbn:watch": "node scripts/kibana --dev --logging.json=false",
"build:types": "tsc --p tsconfig.types.json",
"kbn:bootstrap": "yarn build:types"
"kbn:bootstrap": "yarn build:types && node scripts/register_git_hook"
},
"repository": {
"type": "git",
@ -329,7 +329,6 @@
"gulp-babel": "^7.0.1",
"gulp-sourcemaps": "1.7.3",
"has-ansi": "^3.0.0",
"husky": "^0.14.3",
"image-diff": "1.6.0",
"intl-messageformat-parser": "^1.4.0",
"istanbul-instrumenter-loader": "3.0.0",

View file

@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
require('../src/setup_node_env');
require('../src/dev/run_register_git_hook');

View file

@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export { registerPrecommitGitHook } from './register_git_hook';

View file

@ -0,0 +1,90 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import chalk from 'chalk';
import { chmod, unlink, writeFile } from 'fs';
import dedent from 'dedent';
import { resolve } from 'path';
import { promisify } from 'util';
import { REPO_ROOT } from '../constants';
const chmodAsync = promisify(chmod);
const unlinkAsync = promisify(unlink);
const writeFileAsync = promisify(writeFile);
const PRECOMMIT_GIT_HOOK_SCRIPT_PATH = resolve(REPO_ROOT, '.git/hooks/pre-commit');
function getKbnPrecommitGitHookScript(rootPath) {
return dedent(`
#!/usr/bin/env bash
#
# ** THIS IS AN AUTO-GENERATED FILE **
# ** PLEASE DO NOT CHANGE IT MANUALLY **
#
# GENERATED BY ${__dirname}
# IF YOU WANNA CHANGE SOMETHING INTO THIS SCRIPT
# PLEASE RE-RUN 'yarn kbn bootstrap' or 'node scripts/register_git_hook' IN THE ROOT
# OF THE CURRENT PROJECT ${rootPath}
set -euo pipefail
# Export Git hook params
export GIT_PARAMS="$*"
has_node() {
command -v node >/dev/null 2>&1
}
# Check if we have node js bin in path
has_node || { echo "Can't found node bin in the PATH. Please update the PATH to proceed"; exit 1; }
npm run --silent precommit || { echo "Pre-commit hook failed (add --no-verify to bypass)"; exit 1; }
exit 0
`);
}
export async function registerPrecommitGitHook(log) {
log.write(
chalk.bold(
`Registering Kibana pre-commit git hook...\n`
)
);
try {
await writeGitHook(
PRECOMMIT_GIT_HOOK_SCRIPT_PATH,
getKbnPrecommitGitHookScript(REPO_ROOT)
);
} catch (e) {
log.write(`${chalk.red('fail')} Kibana pre-commit git hook was not installed as an error occur.\n`);
throw e;
}
log.write(`${chalk.green('success')} Kibana pre-commit git hook was installed successfully.\n`);
}
async function writeGitHook(gitHookScriptPath, kbnHookScriptSource) {
try {
await unlinkAsync(gitHookScriptPath);
} catch (e) { /* no-op */ }
await writeFileAsync(gitHookScriptPath, kbnHookScriptSource);
await chmodAsync(gitHookScriptPath, 0o755);
}

View file

@ -17,4 +17,4 @@
* under the License.
*/
export function createFailError(msg: string, exitCode: number): Error;
export function createFailError(msg: string, exitCode?: number): Error;

View file

@ -0,0 +1,29 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { run, createFailError } from './run';
import { registerPrecommitGitHook } from './register_git_hook';
run(async ({ log }) => {
try {
await registerPrecommitGitHook(log);
} catch (error) {
throw createFailError(error);
}
});

View file

@ -10867,15 +10867,6 @@ humps@2.0.1:
resolved "https://registry.yarnpkg.com/humps/-/humps-2.0.1.tgz#dd02ea6081bd0568dc5d073184463957ba9ef9aa"
integrity sha1-3QLqYIG9BWjcXQcxhEY5V7qe+ao=
husky@^0.14.3:
version "0.14.3"
resolved "https://registry.yarnpkg.com/husky/-/husky-0.14.3.tgz#c69ed74e2d2779769a17ba8399b54ce0b63c12c3"
integrity sha512-e21wivqHpstpoiWA/Yi8eFti8E+sQDSS53cpJsPptPs295QTOQR0ZwnHo2TXy1XOpZFD9rPOd3NpmqTK6uMLJA==
dependencies:
is-ci "^1.0.10"
normalize-path "^1.0.0"
strip-indent "^2.0.0"
icalendar@0.7.1:
version "0.7.1"
resolved "https://registry.yarnpkg.com/icalendar/-/icalendar-0.7.1.tgz#d0d3486795f8f1c5cf4f8cafac081b4b4e7a32ae"
@ -15054,11 +15045,6 @@ normalize-package-data@^2.0.0, normalize-package-data@^2.3.2, normalize-package-
semver "2 || 3 || 4 || 5"
validate-npm-package-license "^3.0.1"
normalize-path@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-1.0.0.tgz#32d0e472f91ff345701c15a8311018d3b0a90379"
integrity sha1-MtDkcvkf80VwHBWoMRAY07CpA3k=
normalize-path@^2.0.0, normalize-path@^2.0.1, normalize-path@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9"