Skip to content

Commit

Permalink
docs: document CI Lint usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nejch authored and JohnVillalovos committed Jul 5, 2022
1 parent 3f67c4b commit d5de4b1
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 43 deletions.
1 change: 1 addition & 0 deletions docs/api-objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ API examples
gl_objects/branches
gl_objects/clusters
gl_objects/messages
gl_objects/ci_lint
gl_objects/commits
gl_objects/deploy_keys
gl_objects/deploy_tokens
Expand Down
42 changes: 42 additions & 0 deletions docs/cli-examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,48 @@ CLI examples

For a complete list of objects and actions available, see :doc:`/cli-objects`.

CI Lint
-------

Lint a CI YAML configuration from a string:

.. note::

To see output, you will need to use the ``-v``/``--verbose`` flag.

.. code-block:: console
$ gitlab --verbose ci-lint create --content \
"---
test:
script:
- echo hello
"
Lint a CI YAML configuration from a file (see :ref:`cli_from_files`):

.. code-block:: console
$ gitlab --verbose ci-lint create --content @.gitlab-ci.yml
Lint a project's CI YAML configuration:

.. code-block:: console
$ gitlab --verbose project-ci-lint create --project-id group/my-project --content @.gitlab-ci.yml
Lint a project's current CI YAML configuration:

.. code-block:: console
$ gitlab --verbose project-ci-lint get --project-id group/my-project
Lint a project's current CI YAML configuration on a specific branch:

.. code-block:: console
$ gitlab --verbose project-ci-lint get --project-id group/my-project --ref my-branch
Projects
--------

Expand Down
2 changes: 2 additions & 0 deletions docs/cli-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ Example:
$ gitlab -o yaml -f id,permissions -g elsewhere -c /tmp/gl.cfg project list
.. _cli_from_files:

Reading values from files
-------------------------

Expand Down
53 changes: 53 additions & 0 deletions docs/gl_objects/ci_lint.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#######
CI Lint
#######

Reference
---------

* v4 API:

+ :class:`gitlab.v4.objects.CiLint`
+ :class:`gitlab.v4.objects.CiLintManager`
+ :attr:`gitlab.Gitlab.ci_lint`
+ :class:`gitlab.v4.objects.ProjectCiLint`
+ :class:`gitlab.v4.objects.ProjectCiLintManager`
+ :attr:`gitlab.v4.objects.Project.ci_lint`

* GitLab API: https://docs.gitlab.com/ee/api/lint.html

Examples
---------

Validate a CI YAML configuration::

gitlab_ci_yml = """.api_test:
rules:
- if: $CI_PIPELINE_SOURCE=="merge_request_event"
changes:
- src/api/*
deploy:
extends:
- .api_test
rules:
- when: manual
allow_failure: true
script:
- echo "hello world"
"""
lint_result = gl.ci_lint.create({"content": gitlab_ci_yml})

print(lint_result.status) # Print the status of the CI YAML
print(lint_result.merged_yaml) # Print the merged YAML file

Validate a project's CI configuration::

lint_result = project.ci_lint.get()
assert lint_result.valid is True # Test that the .gitlab-ci.yml is valid
print(lint_result.merged_yaml) # Print the merged YAML file

Validate a CI YAML configuration with a namespace::

lint_result = project.ci_lint.create({"content": gitlab_ci_yml})
assert lint_result.valid is True # Test that the .gitlab-ci.yml is valid
print(lint_result.merged_yaml) # Print the merged YAML file
43 changes: 0 additions & 43 deletions docs/gl_objects/projects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -819,49 +819,6 @@ Get total fetches in last 30 days of a project::

total_fetches = project.additionalstatistics.get().fetches['total']

Project CI Lint
=============================

Reference
---------

* v4 API:

+ :class:`gitlab.v4.objects.ProjectCiLint`
+ :class:`gitlab.v4.objects.ProjectCiLintManager`
+ :attr:`gitlab.v4.objects.Project.ci_lint`

* GitLab API: https://docs.gitlab.com/ee/api/lint.html

Examples
---------

Validate a project's CI configuration::

lint_result = project.ci_lint.get()
assert lint_result.valid is True # Test that the .gitlab-ci.yml is valid
print(lint_result.merged_yaml) # Print the merged YAML file

Validate a CI YAML configuration with a namespace::

gitlab_ci_yml = """.api_test:
rules:
- if: $CI_PIPELINE_SOURCE=="merge_request_event"
changes:
- src/api/*
deploy:
extends:
- .api_test
rules:
- when: manual
allow_failure: true
script:
- echo "hello world"
"""
lint_result = project.ci_lint.create({"content": gitlab_ci_yml})
assert lint_result.valid is True # Test that the .gitlab-ci.yml is valid
print(lint_result.merged_yaml) # Print the merged YAML file

Project storage
=============================

Expand Down

0 comments on commit d5de4b1

Please sign in to comment.