Skip to content

ci-fairy: add "ci.hash" and "ci.readfile" functions to global Jinja2 environment

We build the containers by running a install script. When the script changes, we usually want to re-generate the containers.

That is easy to miss. We could improve that by embedding the SHA sum of the file as a comment in ".gitlab-ci.yml"

   {% for distro in distributions %}
     {{"%-13s"| format(distro.name.upper() + '_EXEC:')}}'bash .gitlab-ci/{{distro.name}}-install.sh' # {{ ci.hash('sha1', ci.readfile('.gitlab-ci/' + distro.name + '-install.sh')) }}
   {% endfor %}

which results in

   FEDORA_EXEC: 'bash .gitlab-ci/fedora-install.sh' # b036066c81711ab2528347a0ef5aab344d4d76f6
   UBUNTU_EXEC: 'bash .gitlab-ci/ubuntu-install.sh' # 8b84263baa60a36e4f612e3e94d23b4a9725cf7b

As we have a test that compares ".gitlab-ci.yml" to the output of ci-fairy generate-template, the comment would be a reminder that we should bump the tag and re-generate ".gitlab-ci.yml".

Alternatively, we could make the hash part of the distro-tag

   {% for distro in distributions %}
     {{"%-13s"| format(distro.name.upper() + '_TAG:')}}'{{distro.tag}}-{{
       (ci.hash('sha1',
         ci.readfile('.gitlab-ci/config.yml'),
         ci.readfile('.gitlab-ci/ci.template'),
         ci.readfile('.gitlab-ci/' + distro.name + '-install.sh')))[1:12]
     }}'
   {% endfor %}

which results in

   FEDORA_TAG:  '2020-11-10.0-137473ad957'
   UBUNTU_TAG:  '2020-11-10.0-42ace328cfb'
Edited by Thomas Haller

Merge request reports

Loading