Skip to content

Add PublishToCatalog command

Furkan Ayhan requested to merge fa-publish-catalog-api into master

What does this MR do and why?

I am a newbie in the Go world and I can accept all the feedback


In this change, we are moving the logic of publishing CI components into release-cli. (gitlab#442785 (closed))

With this new command;

release-cli publish-to-catalog --version 3.0.0

release-cli will fetch the components from the current project, parses the component names and their specs, and sends a request to the /api/v4/projects/:PID/catalog/publish with a body.

How it works

  1. If a CI job has the release keyword, GitLab adds a release script to the job when sending it to Runner.
  2. If the project is not a Catalog resource, the script only consists of release-cli create --name=abc tag_name=1.0.0 ....
  3. If the project is a Catalog resource, the script also has release-cli publish-to-catalog --version=1.0.0.
  4. When the job runs, it's required that the job environment has the release-cli. (Runner generally fetches registry.gitlab.com/gitlab-org/release-cli:latest)
  5. release-cli first creates a "release" with the tag "1.0.0" (POST /projects/:id/releases).
  6. Then, it publishes the version to the CI Catalog (POST /projects/:id/catalog/publish).

Reproduce

  1. We need gitlab!167883 (merged) and the feature flag ci_release_cli_catalog_publish_option enabled in our local development environment.

  2. An example .gitlab-ci.yml for a component project;

create-release:
  rules:
    - if: $CI_COMMIT_TAG =~ /\d+/
  script: echo "Creating release $CI_COMMIT_TAG"
  release:
    tag_name: $CI_COMMIT_TAG
    description: "Release $CI_COMMIT_TAG of components repository $CI_PROJECT_PATH"
  1. An example component template YAML file;

Screenshot_2024-10-02_at_11.06.04

  1. Run a pipeline and see the result;

Screenshot_2024-10-02_at_11.05.41

Screenshot_2024-10-02_at_11.05.52

Checklist

  • I added tests
  • Green pipeline
  • Assign to reviewer
Edited by Furkan Ayhan

Merge request reports

Loading