Skip to content
  • Thomas Haller's avatar
    ci-fairy: add "ci_fairy.hashfiles()" function to global Jinja2 environment · 766e3d77
    Thomas Haller authored
    
    
    We build the containers by running an 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 a checksum
    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_fairy.hashfiles('.gitlab-ci/' + distro.name + '-install.sh') }}
       {% endfor %}
    
    which results in
    
       FEDORA_EXEC: 'bash .gitlab-ci/fedora-install.sh' # db512ed0d3f6880a01ab29cba42abc233f56a7eab1f8ee9a83031f9244b84288
       UBUNTU_EXEC: 'bash .gitlab-ci/ubuntu-install.sh' # 6e35a936aba079f4d91eece147f77d3f65cdc562308a680018a2035a6efdbf2e
    
    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_fairy.hashfiles('.gitlab-ci/config.yml',
                               '.gitlab-ci/ci.template',
                               '.gitlab-ci/' + distro.name + '-install.sh'))[0:12]
         }}'
       {% endfor %}
    
    which results in
    
       FEDORA_TAG:  '2020-11-10.0-b137473ad957'
       UBUNTU_TAG:  '2020-11-10.0-542ace328cfb'
    
    Signed-off-by: default avatarThomas Haller <thaller@redhat.com>
    766e3d77