From d2358ee4d66d8a836710591dab7b96e102e950c5 Mon Sep 17 00:00:00 2001 From: Furkan Ayhan Date: Mon, 28 Nov 2022 17:31:07 +0100 Subject: [PATCH 1/5] Add documentation and CI schema for hooks:pre_get_sources_script --- app/assets/javascripts/editor/schema/ci.json | 41 +++++++++++++++- doc/ci/yaml/index.md | 47 +++++++++++++++++++ .../editor/schema/ci/ci_schema_spec.js | 6 +++ .../hooks/invalid_hook_type.yml | 5 ++ .../negative_tests/hooks/wrong_hook_usage.yml | 4 ++ .../ci/yaml_tests/positive_tests/hooks.yml | 10 ++++ 6 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 spec/frontend/editor/schema/ci/yaml_tests/negative_tests/hooks/invalid_hook_type.yml create mode 100644 spec/frontend/editor/schema/ci/yaml_tests/negative_tests/hooks/wrong_hook_usage.yml create mode 100644 spec/frontend/editor/schema/ci/yaml_tests/positive_tests/hooks.yml diff --git a/app/assets/javascripts/editor/schema/ci.json b/app/assets/javascripts/editor/schema/ci.json index 4c4ad81fed7350..3d8458fe149fe5 100644 --- a/app/assets/javascripts/editor/schema/ci.json +++ b/app/assets/javascripts/editor/schema/ci.json @@ -41,6 +41,9 @@ "before_script": { "$ref": "#/definitions/before_script" }, + "hooks": { + "$ref": "#/definitions/hooks" + }, "cache": { "$ref": "#/definitions/cache" }, @@ -1230,6 +1233,9 @@ "after_script": { "$ref": "#/definitions/after_script" }, + "hooks": { + "$ref": "#/definitions/hooks" + }, "rules": { "$ref": "#/definitions/rules" }, @@ -1894,6 +1900,39 @@ } ] } + }, + "hooks": { + "type": "object", + "markdownDescription": "Specifes lists of commands that will be executed on Runner before/after some events. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#hooks).", + "properties": { + "pre_get_sources_script": { + "markdownDescription": "Specifes a list of commands that will be executed on Runner before updating the Git repository and updating submodules. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#hookspre_get_sources_script).", + "oneOf": [ + { + "type": "string", + "minLength": 1 + }, + { + "type": "array", + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "minItems": 1 + } + ] + } + }, + "additionalProperties": false } } -} \ No newline at end of file +} diff --git a/doc/ci/yaml/index.md b/doc/ci/yaml/index.md index 3f5e11129f95cd..75475b33280557 100644 --- a/doc/ci/yaml/index.md +++ b/doc/ci/yaml/index.md @@ -86,6 +86,7 @@ of the listed keywords use the value defined in the `default` section. - [`artifacts`](#artifacts) - [`before_script`](#before_script) - [`cache`](#cache) +- [`hooks`](#hooks) - [`image`](#image) - [`interruptible`](#interruptible) - [`retry`](#retry) @@ -1862,6 +1863,52 @@ rspec: - [Reuse configuration sections by using `extends`](yaml_optimization.md#use-extends-to-reuse-configuration-sections). - Use `extends` to reuse configuration from [included configuration files](yaml_optimization.md#use-extends-and-include-together). +### `hooks` + +> Introduced in GitLab 15.6 [with a flag](../../administration/feature_flags.md) named `ci_hooks_pre_get_sources_script`. Disabled by default. + +FLAG: +On self-managed GitLab, by default this feature is not available. To make it available, +ask an administrator to [enable the feature flag](../../administration/feature_flags.md) named `ci_hooks_pre_get_sources_script`. +The feature is not ready for production use. + +Use `hooks` to specify lists of commands that will be executed on Runner +before/after some events such as `clone` and `build-script`. + +**Keyword type**: Job keyword. You can use it only as part of a job or in the +[`default` section](#default). + +**Possible inputs**: + +- A hash of hooks and their commands. +- Available hooks: `pre_get_sources_script`. + +#### `hooks:pre_get_sources_script` + +Use `hooks:pre_get_sources_script` to specify a list of commands that will be executed on Runner +before updating the Git repository and updating submodules +Use it to adjust the Git client configuration first, for example. + + + + + +**Example of `hooks:pre_get_sources_script`**: + +```yaml +job1: + hooks: + pre_get_sources_script: + - echo 'hello job1 pre_get_sources_script' + script: echo 'hello job1 script' +``` + + + ### `image` Use `image` to specify a Docker image that the job runs in. diff --git a/spec/frontend/editor/schema/ci/ci_schema_spec.js b/spec/frontend/editor/schema/ci/ci_schema_spec.js index 9c622d49db98a0..9e8bee14e5a35c 100644 --- a/spec/frontend/editor/schema/ci/ci_schema_spec.js +++ b/spec/frontend/editor/schema/ci/ci_schema_spec.js @@ -31,6 +31,7 @@ import ProjectPathYaml from './yaml_tests/positive_tests/project_path.yml'; import VariablesYaml from './yaml_tests/positive_tests/variables.yml'; import JobWhenYaml from './yaml_tests/positive_tests/job_when.yml'; import IdTokensYaml from './yaml_tests/positive_tests/id_tokens.yml'; +import HooksYaml from './yaml_tests/positive_tests/hooks.yml'; // YAML NEGATIVE TEST import ArtifactsNegativeYaml from './yaml_tests/negative_tests/artifacts.yml'; @@ -47,6 +48,8 @@ import TriggerNegative from './yaml_tests/negative_tests/trigger.yml'; import VariablesInvalidSyntaxDescYaml from './yaml_tests/negative_tests/variables/invalid_syntax_desc.yml'; import VariablesWrongSyntaxUsageExpand from './yaml_tests/negative_tests/variables/wrong_syntax_usage_expand.yml'; import IdTokensNegativeYaml from './yaml_tests/negative_tests/id_tokens.yml'; +import HooksInvalidHookType from './yaml_tests/negative_tests/hooks/invalid_hook_type.yml'; +import HooksWrongHookUsage from './yaml_tests/negative_tests/hooks/wrong_hook_usage.yml'; const ajv = new Ajv({ strictTypes: false, @@ -79,6 +82,7 @@ describe('positive tests', () => { FilterYaml, IncludeYaml, JobWhenYaml, + HooksYaml, RulesYaml, VariablesYaml, ProjectPathYaml, @@ -118,6 +122,8 @@ describe('negative tests', () => { ProjectPathIncludeNoSlashYaml, ProjectPathIncludeTailSlashYaml, TriggerNegative, + HooksInvalidHookType, + HooksWrongHookUsage, }), )('schema validates %s', (_, input) => { // We construct a new "JSON" from each main key that is inside a diff --git a/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/hooks/invalid_hook_type.yml b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/hooks/invalid_hook_type.yml new file mode 100644 index 00000000000000..7af712e33be958 --- /dev/null +++ b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/hooks/invalid_hook_type.yml @@ -0,0 +1,5 @@ +job1: + hooks: + invalid_script: + - echo 'hello job1 invalid_script' + script: echo 'hello job1 script' diff --git a/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/hooks/wrong_hook_usage.yml b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/hooks/wrong_hook_usage.yml new file mode 100644 index 00000000000000..4d37af2563e4af --- /dev/null +++ b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/hooks/wrong_hook_usage.yml @@ -0,0 +1,4 @@ +job1: + hooks: + pre_get_sources_script: true + script: echo 'hello job1 script' diff --git a/spec/frontend/editor/schema/ci/yaml_tests/positive_tests/hooks.yml b/spec/frontend/editor/schema/ci/yaml_tests/positive_tests/hooks.yml new file mode 100644 index 00000000000000..4d45c5528eaad3 --- /dev/null +++ b/spec/frontend/editor/schema/ci/yaml_tests/positive_tests/hooks.yml @@ -0,0 +1,10 @@ +default: + hooks: + pre_get_sources_script: + - echo 'hello default pre_get_sources_script' + +job1: + hooks: + pre_get_sources_script: + - echo 'hello job1 pre_get_sources_script' + script: echo 'hello job1 script' -- GitLab From 37f671d0a26501db3a0c9214119afb1e3b059679 Mon Sep 17 00:00:00 2001 From: Furkan Ayhan Date: Thu, 1 Dec 2022 13:55:15 +0000 Subject: [PATCH 2/5] Apply 4 suggestion(s) to 2 file(s) --- app/assets/javascripts/editor/schema/ci.json | 4 ++-- doc/ci/yaml/index.md | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/editor/schema/ci.json b/app/assets/javascripts/editor/schema/ci.json index 3d8458fe149fe5..c2873be8237be9 100644 --- a/app/assets/javascripts/editor/schema/ci.json +++ b/app/assets/javascripts/editor/schema/ci.json @@ -1903,10 +1903,10 @@ }, "hooks": { "type": "object", - "markdownDescription": "Specifes lists of commands that will be executed on Runner before/after some events. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#hooks).", + "markdownDescription": "Specifies lists of commands to execute on the runner at certain stages in job execution. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#hooks).", "properties": { "pre_get_sources_script": { - "markdownDescription": "Specifes a list of commands that will be executed on Runner before updating the Git repository and updating submodules. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#hookspre_get_sources_script).", + "markdownDescription": "Specifies a list of commands to execute on the runner before updating the Git repository and any submodules. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#hookspre_get_sources_script).", "oneOf": [ { "type": "string", diff --git a/doc/ci/yaml/index.md b/doc/ci/yaml/index.md index 75475b33280557..b34e6b3dcbadf8 100644 --- a/doc/ci/yaml/index.md +++ b/doc/ci/yaml/index.md @@ -1885,9 +1885,11 @@ before/after some events such as `clone` and `build-script`. #### `hooks:pre_get_sources_script` -Use `hooks:pre_get_sources_script` to specify a list of commands that will be executed on Runner -before updating the Git repository and updating submodules -Use it to adjust the Git client configuration first, for example. +> Introduced in GitLab 15.6 [with a flag](../../administration/feature_flags.md) named `ci_hooks_pre_get_sources_script`. Disabled by default. + +Use `hooks:pre_get_sources_script` to specify a list of commands to execute on the runner +before retrieving the Git repository and any submodules. You can use it +to adjust the Git client configuration first, for example. +**Related topics**: - +- [GitLab Runner configuration](https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section) **Example of `hooks:pre_get_sources_script`**: @@ -1909,8 +1905,6 @@ job1: script: echo 'hello job1 script' ``` - - ### `image` Use `image` to specify a Docker image that the job runs in. -- GitLab From 36fd1edd9f1ac5ffe548a1e84437e9d33ae7602e Mon Sep 17 00:00:00 2001 From: Marcel Amirault Date: Fri, 2 Dec 2022 09:43:21 +0000 Subject: [PATCH 5/5] Apply 3 suggestion(s) to 2 file(s) --- app/assets/javascripts/editor/schema/ci.json | 2 +- doc/ci/yaml/index.md | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/editor/schema/ci.json b/app/assets/javascripts/editor/schema/ci.json index c2873be8237be9..fee858f7b5d5d8 100644 --- a/app/assets/javascripts/editor/schema/ci.json +++ b/app/assets/javascripts/editor/schema/ci.json @@ -1903,7 +1903,7 @@ }, "hooks": { "type": "object", - "markdownDescription": "Specifies lists of commands to execute on the runner at certain stages in job execution. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#hooks).", + "markdownDescription": "Specifies lists of commands to execute on the runner at certain stages of job execution. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#hooks).", "properties": { "pre_get_sources_script": { "markdownDescription": "Specifies a list of commands to execute on the runner before updating the Git repository and any submodules. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#hookspre_get_sources_script).", diff --git a/doc/ci/yaml/index.md b/doc/ci/yaml/index.md index 8b6e74d1875577..52422cba111bea 100644 --- a/doc/ci/yaml/index.md +++ b/doc/ci/yaml/index.md @@ -1872,16 +1872,15 @@ On self-managed GitLab, by default this feature is not available. To make it ava ask an administrator to [enable the feature flag](../../administration/feature_flags.md) named `ci_hooks_pre_get_sources_script`. The feature is not ready for production use. -Use `hooks` to specify lists of commands that will be executed on Runner -before/after some events such as `clone` and `build-script`. +Use `hooks` to specify lists of commands to execute on the runner +at certain stages of job execution, like before retrieving the Git repository. **Keyword type**: Job keyword. You can use it only as part of a job or in the [`default` section](#default). **Possible inputs**: -- A hash of hooks and their commands. -- Available hooks: `pre_get_sources_script`. +- A hash of hooks and their commands. Available hooks: `pre_get_sources_script`. #### `hooks:pre_get_sources_script` -- GitLab