Skip to content

Calculate and use sha for CI config variables cache

What does this MR do and why?

Related to #381233 (closed)

Today, we are receiving "ref" from a client and calculating config variables according to it. We also use this "ref" to decide the cache key. However, "ref" is not a good candidate for a cache key because the name is static but that branch can be changed.

In this MR, we are starting to calculate and use "sha" of the "ref" for the cache key.

Here, we are also renaming the "sha" parameter to "ref" because we are actually receiving "ref" from client.

As a follow-up, we should deprecate the parameter name sha and introduce ref instead in both app/controllers/projects/pipelines_controller.rb and app/graphql/types/project_type.rb. #389065 (closed)

Screenshots or screen recordings

Before this MR

Let's say we have this config initially;

test-job:
  script: exit 0
  1. When we open the "Run pipeline" page, the config-variables endpoint returns null initially;

Screenshot_2023-01-23_at_15.25.56

It means that the reactive cache is empty and it's being calculated.

  1. When we refresh the page again, we'll see that the endpoint returns [];

(we won't have to refresh the page after the frontend part of #381233 (closed) is implemented)

Screenshot_2023-01-23_at_15.26.04

  1. Let's update the config YAML with this;
variables:
  VAR1:
    description: Hello VAR1

test-job:
  script: exit 0
  1. When we refresh the "Run pipeline" page again, we'll see that the endpoint still returns [];

Screenshot_2023-01-23_at_15.26.21

That's because the cache is calculated with the branch name.

After this MR

Let's say we have this config initially;

test-job:
  script: exit 0
  1. When we open the "Run pipeline" page, the config-variables endpoint returns null initially;

Screenshot_2023-01-23_at_15.23.45

It means that the reactive cache is empty and it's being calculated.

  1. When we refresh the page again, we'll see that the endpoint returns [];

(we won't have to refresh the page after the frontend part of #381233 (closed) is implemented)

Screenshot_2023-01-23_at_15.23.57

  1. Let's update the config YAML with this;
variables:
  VAR1:
    description: Hello VAR1

test-job:
  script: exit 0
  1. When we refresh the "Run pipeline" page again, we'll see that the endpoint returns null;

Screenshot_2023-01-23_at_15.24.14

It means that the reactive cache is empty and it's being calculated.

  1. When we refresh the page again, we'll see that the endpoint returns prefill variables as expected;

(we won't have to refresh the page after the frontend part of #381233 (closed) is implemented)

Screenshot_2023-01-23_at_15.24.23

That's because the cache is calculated with sha.

MR acceptance checklist

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

Edited by Furkan Ayhan

Merge request reports