Move calculation of gitlab templates version out of *show-ci-variables

Created on 11 April 2025, about 1 month ago

Problem/Motivation

The reusable code snippet .show-ci-variables does more than just "show" the variables, it executes a curl on scripts/extract-version.php then runs that script. If this snippet is used in another job, eg custom after_script, with the intention of displaying the Templates version, then it is not only wasting resources to get the script and execute it, but it can cause errors and/or not run correctly, and give confusing infomation in the log.

Proposed resolution

It would be preferable to move the curl and execution of the script into a different code reference, say something like .extract-version, and leave the .show-ci-variables to just do the printing. Then the latter can be called in other places too, without the problem of doing the curl and executing the script.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Component

gitlab-ci

Created by

🇬🇧United Kingdom jonathan1055

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @jonathan1055
  • Pipeline finished with Success
    19 days ago
    Total: 378s
    #482118
  • 🇬🇧United Kingdom jonathan1055

    Here are two "before" examples of the problem. First running .show-ci-variables in a composer after_script fails, because we are trying to curl the file without the _CURL_TEMPLATES_REPO and REF being set.

    Second, adding .show-ci-variables in another job after_script works, but is confusing and wasteful because we are downloading and executing the script again

  • Pipeline finished with Success
    18 days ago
    Total: 48s
    #482531
  • Pipeline finished with Success
    18 days ago
    Total: 47s
    #482735
  • Pipeline finished with Success
    16 days ago
    #483702
  • Pipeline finished with Success
    16 days ago
    #483725
  • 🇬🇧United Kingdom jonathan1055

    Downstream pipelines for D10 and D7 show the Gitlab Templates version as required.

    Here's a test, where the reference is using in cspell after_script

    cspell:
      after_script:
        - !reference [ .show-ci-variables ]
        - echo "=== GITLAB_TEMPLATES_VERSION=$GITLAB_TEMPLATES_VERSION"
        - echo "=== VERSION_USING_PUTENV=$VERSION_USING_PUTENV"
        - echo "=== GITLAB_TEMPLATES_VERSION2=$GITLAB_TEMPLATES_VERSION2"
        - echo "=== VERSION_USING_PUTENV2=$VERSION_USING_PUTENV2"
        - source build.env
        - echo "GITLAB_TEMPLATES_VERSION=$GITLAB_TEMPLATES_VERSION"
        - echo "GITLAB_TEMPLATES_VERSION2=$GITLAB_TEMPLATES_VERSION2"
    

    The value is displayed, but annoyingly it also shows the quotes, as they are written to build.env. But when an extra source build.env is added the variables do not have the quotes. This does not really matter, as the default display in Composer is clean. It is just unusual that the values read from build.env a second time appear to behave better than the initial read.
    https://git.drupalcode.org/issue/scheduler-3445052/-/jobs/5085925

  • 🇪🇸Spain fjgarlin

    I made a couple of comments in the MR, one of them around the quotes, in case it makes a difference.

  • Pipeline finished with Success
    14 days ago
    Total: 51s
    #485492
  • Pipeline finished with Success
    13 days ago
    Total: 11120s
    #486528
  • Pipeline finished with Success
    13 days ago
    Total: 236s
    #486620
  • 🇬🇧United Kingdom jonathan1055

    I've tidied up the try-out code, renamed the script as requested, and removed the quotes. All runs ok in the latest downstream pipeline (the previous failure was before I rebased, and phpunit failed due to the quotes around project type, that was fixed yestterday)

    Here's a test where cspell after_script calls !reference [ .show-ci-variables ] and it works cleanly
    https://git.drupalcode.org/issue/scheduler-3445052/-/pipelines/486624

    This is ready for review.

  • 🇪🇸Spain fjgarlin

    This looks good to me. Thanks for addressing the feedback. RTBC.

  • Pipeline finished with Skipped
    12 days ago
    #487171
  • 🇬🇧United Kingdom jonathan1055

    Just for the record, the build.env file is read automatically and the variables with spaces and without quotes are loaded correctly in all script sections of the subsequent jobs that follow a composer job. The only place where the variables created in composer: script: are automatically available is in a custom composer: after_script: and this is where source build.env used to work, but now fails due to having a variable with spaces in. But the same can be achieved using the slightly more complicated version IFS=$'\n' && export $(<build.env) && unset IFS

    An example of this is https://git.drupalcode.org/issue/scheduler-3445052/-/jobs/5132987#L1122

Production build 0.71.5 2024