python-jsonschema / python-jsonschema/check-jsonschema

Support loading of GitLab `!reference` data during validation

Open
#274 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement gitlab-reference-support
Dominant language
Python
Stars
341
Forks
71
Avg merge
15d 20h
Merged PRs (30d)
4

Description

Preface

GitLab !reference support was added in https://github.com/python-jsonschema/check-jsonschema/issues/112 but there are still some edge cases.

How I verified that there are no duplicate issues in the issue tracker

I searched for the "reference" word between open and closed issues and I found only closed https://github.com/python-jsonschema/check-jsonschema/issues/112.

.pre-commit-config.yaml

  - repo: https://github.com/python-jsonschema/check-jsonschema
    rev: 0.23.1
    hooks:
      - id: check-gitlab-ci
        args: ["--data-transform", "gitlab-ci"]

Valid .gitlab-ci.yml

include:
  - project: "myproject/mynamespace/backend/repositoryname"
    ref: v1.1.22
    file: ".gitlab-ci-common.yml"

test:
  stage: test
  services:
    - name: mongo:6.0.6
      command: ["/bin/sh", "-c", "mongod --logpath /dev/null --bind_ip_all --replSet 'rs0' "]
    - !reference [.common_services_for_test_job, services]
  before_script:
    - echo "Hello"

check-gitlab-ci output

Validate GitLab CI config................................................
Failed
- hook id: check-gitlab-ci
- exit code: 1
Schema validation errors were encountered.
  .gitlab-ci.yml::$.test.services[1]: ['.common_services_for_test_job', 'services'] is not valid under any of the given schemas
  Underlying errors caused this.
  Best Match:
    $.test.services[1]: ['.common_services_for_test_job', 'services'] is not of type 'string'

Expected result

Accept the mentioned YAML syntax.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with the check-gitlab-ci hook and --data-transform gitlab-ci against the YAML example in the issue. Trace the validation path for the services entry and determine how GitLab !reference values are represented during loading. Done means the shown syntax is accepted without the schema validation error and existing validation still passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, yaml
Domain
ci-cd, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.