From 521cf2fe0619d08dedbbb81777ece10c414bb017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Mon, 15 Apr 2024 18:58:05 +0100 Subject: gitlab: use 'cirrus-vars' tool for generating build file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The giant 'sed' command that is used to generate a Cirrus CI build YAML file has a hardcoded list of environment variable substitutions it can perform. For most projects this list is overkill and for some projects it is insufficient. Now that the 'cirrus-run' container has the 'cirrus-vars' command, we can invoke that to dynamically perform the substitutions. Since the 'vars' files don't export the shell variables they declare, we must add 'set -o allexport' to force all vars to be implicitly exported. Note that when updating projects across this commit, their 'build.yml' file will need changing for the special handling of '$PATH' that used to be done by sed, and must now be done in the 'build.yml' directly: - PATH: "@PATH@" + PATH: "@PATH_EXTRA@:$PATH" Signed-off-by: Daniel P. Berrangé --- lcitool/gitlab.py | 22 +++------------------- .../manifest/out/ci/gitlab/build-templates.yml | 22 +++------------------- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/lcitool/gitlab.py b/lcitool/gitlab.py index 277ac12..e5e2142 100644 --- a/lcitool/gitlab.py +++ b/lcitool/gitlab.py @@ -339,26 +339,10 @@ def cirrus_template(cidir): interruptible: true needs: [] script: + - set -o allexport - source {cidir}/cirrus/$NAME.vars - - sed -e "s|[@]CI_REPOSITORY_URL@|$CI_REPOSITORY_URL|g" - -e "s|[@]CI_COMMIT_REF_NAME@|$CI_COMMIT_REF_NAME|g" - -e "s|[@]CI_MERGE_REQUEST_REF_PATH@|$CI_MERGE_REQUEST_REF_PATH|g" - -e "s|[@]CI_COMMIT_SHA@|$CI_COMMIT_SHA|g" - -e "s|[@]CIRRUS_VM_INSTANCE_TYPE@|$CIRRUS_VM_INSTANCE_TYPE|g" - -e "s|[@]CIRRUS_VM_IMAGE_SELECTOR@|$CIRRUS_VM_IMAGE_SELECTOR|g" - -e "s|[@]CIRRUS_VM_IMAGE_NAME@|$CIRRUS_VM_IMAGE_NAME|g" - -e "s|[@]UPDATE_COMMAND@|$UPDATE_COMMAND|g" - -e "s|[@]UPGRADE_COMMAND@|$UPGRADE_COMMAND|g" - -e "s|[@]INSTALL_COMMAND@|$INSTALL_COMMAND|g" - -e "s|[@]PATH@|$PATH_EXTRA${{PATH_EXTRA:+:}}\\$PATH|g" - -e "s|[@]PKG_CONFIG_PATH@|$PKG_CONFIG_PATH|g" - -e "s|[@]PKGS@|$PKGS|g" - -e "s|[@]MAKE@|$MAKE|g" - -e "s|[@]PYTHON@|$PYTHON|g" - -e "s|[@]PIP3@|$PIP3|g" - -e "s|[@]PYPI_PKGS@|$PYPI_PKGS|g" - -e "s|[@]XML_CATALOG_FILES@|$XML_CATALOG_FILES|g" - <{cidir}/cirrus/build.yml >{cidir}/cirrus/$NAME.yml + - set +o allexport + - cirrus-vars <{cidir}/cirrus/build.yml >{cidir}/cirrus/$NAME.yml - cat {cidir}/cirrus/$NAME.yml - cirrus-run -v --show-build-log always {cidir}/cirrus/$NAME.yml rules: diff --git a/tests/data/manifest/out/ci/gitlab/build-templates.yml b/tests/data/manifest/out/ci/gitlab/build-templates.yml index 0b3eeb4..9aa81a1 100644 --- a/tests/data/manifest/out/ci/gitlab/build-templates.yml +++ b/tests/data/manifest/out/ci/gitlab/build-templates.yml @@ -276,26 +276,10 @@ interruptible: true needs: [] script: + - set -o allexport - source ci/cirrus/$NAME.vars - - sed -e "s|[@]CI_REPOSITORY_URL@|$CI_REPOSITORY_URL|g" - -e "s|[@]CI_COMMIT_REF_NAME@|$CI_COMMIT_REF_NAME|g" - -e "s|[@]CI_MERGE_REQUEST_REF_PATH@|$CI_MERGE_REQUEST_REF_PATH|g" - -e "s|[@]CI_COMMIT_SHA@|$CI_COMMIT_SHA|g" - -e "s|[@]CIRRUS_VM_INSTANCE_TYPE@|$CIRRUS_VM_INSTANCE_TYPE|g" - -e "s|[@]CIRRUS_VM_IMAGE_SELECTOR@|$CIRRUS_VM_IMAGE_SELECTOR|g" - -e "s|[@]CIRRUS_VM_IMAGE_NAME@|$CIRRUS_VM_IMAGE_NAME|g" - -e "s|[@]UPDATE_COMMAND@|$UPDATE_COMMAND|g" - -e "s|[@]UPGRADE_COMMAND@|$UPGRADE_COMMAND|g" - -e "s|[@]INSTALL_COMMAND@|$INSTALL_COMMAND|g" - -e "s|[@]PATH@|$PATH_EXTRA${PATH_EXTRA:+:}\$PATH|g" - -e "s|[@]PKG_CONFIG_PATH@|$PKG_CONFIG_PATH|g" - -e "s|[@]PKGS@|$PKGS|g" - -e "s|[@]MAKE@|$MAKE|g" - -e "s|[@]PYTHON@|$PYTHON|g" - -e "s|[@]PIP3@|$PIP3|g" - -e "s|[@]PYPI_PKGS@|$PYPI_PKGS|g" - -e "s|[@]XML_CATALOG_FILES@|$XML_CATALOG_FILES|g" - ci/cirrus/$NAME.yml + - set +o allexport + - cirrus-vars ci/cirrus/$NAME.yml - cat ci/cirrus/$NAME.yml - cirrus-run -v --show-build-log always ci/cirrus/$NAME.yml rules: -- cgit v1.1