{"id":16125143,"url":"https://github.com/emmeowzing/gitlabci-lint-pre-commit-hook","last_synced_at":"2026-03-10T11:02:56.703Z","repository":{"id":58961321,"uuid":"534687814","full_name":"emmeowzing/gitlabci-lint-pre-commit-hook","owner":"emmeowzing","description":"A pre-commit hook that lints Gitlab CI configurations","archived":false,"fork":false,"pushed_at":"2024-09-11T16:35:31.000Z","size":4017,"stargazers_count":16,"open_issues_count":16,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-15T16:24:58.145Z","etag":null,"topics":["git","gitlab","lint","pre-commit"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pre-commit-gitlabci-lint/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emmeowzing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"bjd2385"}},"created_at":"2022-09-09T14:57:37.000Z","updated_at":"2024-09-03T22:08:29.000Z","dependencies_parsed_at":"2023-01-22T07:45:15.529Z","dependency_job_id":"ffc37cad-37a1-4a02-a8d5-f68bd212031d","html_url":"https://github.com/emmeowzing/gitlabci-lint-pre-commit-hook","commit_stats":null,"previous_names":["bjd2385/pre-commit-gitlabci-lint","emmeowzing/gitlabci-lint-pre-commit-hook","bjd2385/gitlabci-lint-pre-commit-hook"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmeowzing%2Fgitlabci-lint-pre-commit-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmeowzing%2Fgitlabci-lint-pre-commit-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmeowzing%2Fgitlabci-lint-pre-commit-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmeowzing%2Fgitlabci-lint-pre-commit-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emmeowzing","download_url":"https://codeload.github.com/emmeowzing/gitlabci-lint-pre-commit-hook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243809865,"owners_count":20351403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","gitlab","lint","pre-commit"],"created_at":"2024-10-09T21:26:02.002Z","updated_at":"2026-03-10T11:02:56.662Z","avatar_url":"https://github.com/emmeowzing.png","language":"Python","funding_links":["https://ko-fi.com/bjd2385"],"categories":[],"sub_categories":[],"readme":"# `gitlabci-lint` pre-commit hook\n\n[![PyPI version](https://img.shields.io/pypi/v/pre-commit-gitlabci-lint.svg?logo=pypi\u0026style=flat-square)](https://pypi.org/project/pre-commit-gitlabci-lint/)\n[![PyPI downloads](https://img.shields.io/pypi/dm/pre-commit-gitlabci-lint?style=flat-square)](https://pypistats.org/packages/pre-commit-gitlabci-lint)\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/emmeowzing/gitlabci-lint-pre-commit-hook/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/emmeowzing/gitlabci-lint-pre-commit-hook/tree/main)\n\nThis is a [pre-commit](https://pre-commit.com/) hook that uses GitLab's `/api/v4/ci/lint` linting endpoint to validate the contents of `.gitlab-ci.yml` files. This is similar to CircleCI pre-commit hooks that validate that product's configuration files.\n\n```text\n$ gitlabci-lint --help\nusage: gitlabci-lint [-h] [-c CONFIGS] [-C GITLABCI_LINT_CONFIG] [-b [BASE_URL]] [-p PROJECT_ID] [--version] [-q]\n\nValidate your GitLab CI with GitLab's API endpoint.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -c CONFIGS, --configs CONFIGS\n                        CI Config files to check. (default: .gitlab-ci.yml)\n  -C GITLABCI_LINT_CONFIG, --gitlabci-lint-config GITLABCI_LINT_CONFIG\n                        Pass parameters via config file. Looks first at '.gitlabci-lint.toml', then '$HOME/.config/gitlabci-lint/config.toml', unless otherwise specified.\n  -b [BASE_URL], -B [BASE_URL], --base-url [BASE_URL]\n                        Base GitLab URL. (default: https://gitlab.com/)\n  -p PROJECT_ID, -P PROJECT_ID, --project-id PROJECT_ID\n                        Project ID to use with the lint API.\n  --version             show program's version number and exit\n  -q, -Q, --quiet       Silently fail and pass, without output, unless improperly configured. (default: False)\n```\n\n## Install\n\n```shell\npip install pre-commit-gitlabci-lint\n```\n\n## Use\n\n### Setup\n\n1. [Create an access token](https://gitlab.com/-/profile/personal_access_tokens) with `api` scope.\n2. Set access token value in an environment variable named `GITLAB_TOKEN` or `GITLABCI_LINT_TOKEN`.\n3. Add the projectId for your gitlab project as a command line argument, or set it in the config file.\n4. Ensure the virtualenv Python version is 3.8 or later.\n\n### Configuration\n\nA configuration file is not required for use. However, if you'd rather specify settings in a file that is checked into your project's VCS, you may create a config file located at `/root/of/repo/.gitlabci-lint.toml`, or `$HOME/.config/.gitlabci-lint/config.toml`, such as the following.\n\n```toml\n[gitlabci-lint]\nquiet = false\nbase-url = \"https://gitlab.com\"\nproject-id = \"12345678\"\nconfigs = [ \".gitlab-ci.yml\" ]\ntoken = \"$GITLAB_TOKEN\"\n```\n\n## Examples\n\n### Shell\n\n```console\n$ export GITLAB_TOKEN=\"$(pass show gitlab-api-key)\"\n$ gitlabci-lint -p \u003cproject_id\u003e\nConfig file at '.gitlab-ci.yml' is valid.\n```\n\n### pre-commit\n\nAn example `.pre-commit-config.yaml`:\n\n```yaml\n---\nrepos:\n  - repo: https://github.com/bjd2385/pre-commit-gitlabci-lint\n    rev: \u003clatest release\u003e\n    hooks:\n      - id: gitlabci-lint\n      # args: [-b, 'https://custom.gitlab.host.com', '-p', '12345678']\n```\n\n### GitLab CI\n\nHere is an example Gitlab CI job that lints all GitLab CI files in a project on merge requests with naming conventions matching the regex `.*.gitlab-ci.yml`.\n\n```yaml\ngitlab-ci-lint:\n  stage: test\n  image: cimg/base:2023.12\n  variables:\n    GITLAB_CI_LINT_VERSION: \u003cversion\u003e\n    YQ_VERSION: 4.40.5\n  before_script:\n    - set -eo pipefail\n    - sudo apt update \u0026\u0026 sudo apt install -y python3-pip\n    - pip install -q --disable-pip-version-check --no-python-version-warning pre-commit-gitlabci-lint==\"$GITLAB_CI_LINT_VERSION\"\n    - |\n      wget https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_amd64 -O yq\n      sudo install yq /usr/local/bin/yq\n  script:\n    - |+\n      mapfile -t _TEMPLATES \u003c \u003c(find . -type f -regex \".*.gitlab-ci.yml\")\n\n      for template in \"${_TEMPLATES[@]}\"; do\n          printf \"INFO: Considering \\\"%s\\\"\\\\n\" \"$template\"\n\n          # Count the number of jobs present in a GitLab CI template. Job templates aren't counted as jobs.\n          _JOB_COUNT=\"$(yq '... comments=\"\" | to_entries | filter(.key != \"include\" and .key != \"default\" and .key != \"stages\" and .key != \"variables\" and .key != \"workflow\" and (.key != \".*\") and .key != \"cache\") | from_entries | length' \"$template\")\"\n\n          if [ \"$_JOB_COUNT\" -ne \"0\" ]; then\n              printf \"INFO: Linting \\\"%s\\\"\\\\n\" \"$template\"\n              gitlabci-lint -p \"$CI_PROJECT_ID\" -b https://\"$CI_SERVER_HOST\" -c \"$template\"\n          else\n              printf \"INFO: Skipping \\\"%s\\\": no defined jobs.\\\\n\" \"$template\"\n          fi\n      done\n  tags:\n    - small\n  rules:\n    - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(develop|main)$/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmeowzing%2Fgitlabci-lint-pre-commit-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femmeowzing%2Fgitlabci-lint-pre-commit-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmeowzing%2Fgitlabci-lint-pre-commit-hook/lists"}