Skip to content

Support `@~latest` version when including components

Leaminn Ma requested to merge 390839-include-latest-component into master

What does this MR do and why?

This MR adds support to allow the version to be specified as ~latest when including components. The ~latest version is defined as: a special moving target version that points to the most recent released tag. The target project must be an explicit catalog resource.

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: Backend: Support `@~latest` version when includ... (#390839 - 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. Mark the project as a catalog resource in the Rails console.
::Ci::Catalog::Resource.create(project: Project.find(<project_id>))
  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. Go to Repository > 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. Go to Deployments > Releases. Create a new release for tag v0.1 for the current date.
Screenshot Screenshot_2023-03-27_at_11.29.14_AM
  1. Now go to CI/CD > Editor and update the content with the following YAML (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 "View merged YAML" content shows component-1-v0.1. Notice that it only retrieved the latest released tagged branch.

Screenshot_2023-03-27_at_11.33.20_AM

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

  2. You can experiment with changing the release date to ensure that the @~latest keyword only retrieves the latest release tag. Also observe that if you remove all the releases or if the project is not a catalog resource, the following "content not found" error is displayed:

Screenshot_2023-03-27_at_11.37.34_AM

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 #390839 (closed)

Edited by Leaminn Ma

Merge request reports