Skip to content

Support CI include:components version `~latest` for all projects

Leaminn Ma requested to merge ci-components-latest-for-all-projects into master

What does this MR do and why?

In !115756 (merged), we introduced the version keyword ~latest when including components in a Ci config. This keyword was limited to projects that were marked as Catalog Resources only. In this MR, we are enabling its use for all projects regardless of the project type.

The ~latest version is defined as: a special moving target version that points to the most recent released tag.

Note that when the project does not have a release, it displays a "content not found" error (similar to when any target version does not exist).

Solves: Components support ~latest in all project (#413595 - closed)

How to set up and validate locally

  1. Enable the feature flag: Feature.enable(:ci_include_components)
  2. Create a project with a component.

Path: /components/component-1/template.yml

template.yml:

component-1:
    script: echo
  1. Create a new branch named branch-v0.1 with the following content in /components/component-1/template.yml:
component-1-v0.1:
    script: echo
  1. Create a new branch named branch-v0.2 with the following content in /components/component-1/template.yml:
component-1-v0.2:
    script: echo
  1. Create two tags:
  • Create a tag named v0.1 for branch branch-v0.1
  • Create a tag named v0.2 for branch branch-v0.2
Screenshot Screenshot_2023-03-27_at_11.28.04_AM
  1. Create a new release for tag v0.1 for the current date.
Screenshot Screenshot_2023-03-27_at_11.29.14_AM
  1. Update your .gitlab-ci.yml file with the following content (adjusting the component path as needed):
include:
  - component: gdk.test:3000/group-a/project-components-1/components/component-1@~latest
  1. Observe that there is no validation error.

Screenshot_2023-03-27_at_11.31.47_AM

And the merged yaml/full configuration content shows component-1-v0.1. Notice that it only retrieved the latest released tagged branch.

Screenshot_2023-06-16_at_5.22.10_PM

  1. Commit the change and run the pipeline. It should succeed.

  2. (Optional) You can experiment with changing the release date to ensure that the @~latest keyword only retrieves the latest release tag. Screenshot_2023-03-27_at_11.37.34_AM

  3. (Optional) You can also observe that if you mark the project as a catalog resource, the result is the same.

::Ci::Catalog::Resource.create(project: Project.find(<project_id>))

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #413595 (closed)

Edited by Leaminn Ma

Merge request reports