refactor: factor Gerrit metadata generation into templates
Since the addition of the `expand_template` utility function to our Bash
utilities, we can expand Bash expressions in arbitrary files. In
particular, this allows us to generate YAML expressions within our LAVA
job templates, and begin reducing the amount of external script-based
templating we do.
This change begins with the Gerrit metadata section shared by both of
the FVP LAVA job templates, by removing the template-specific scripts
which generate the relevant YAML, and integrating it directly into the
templates.
Change-Id: I1e28791069e8194f967cb5b0df12a19db2a0f590
Signed-off-by: Chris Kay <chris.kay@arm.com>
diff --git a/fvp_utils.sh b/fvp_utils.sh
index 8985846..7854081 100644
--- a/fvp_utils.sh
+++ b/fvp_utils.sh
@@ -284,15 +284,33 @@
fi
}
+# Generates the template for YAML-based LAVA job definitions from a file
+# corresponding to the currently-selected payload, e.g.:
+#
+# - `lava-templates/fvp-linux.yaml`
+# - `lava-templates/fvp-tftf.yaml`
+#
+# The job definition template is itself expanded with visibility of all
+# variables that are available from within the function, including those with
+# local scope.
+#
+# TODO: Move the Gerrit metadata generation to to the main YAML generation phase
+# so that we can template the file in one phase.
gen_fvp_yaml_template() {
- local yaml_template_file="$workspace/fvp_template.yaml"
+ if [ -n "${GERRIT_CHANGE_NUMBER}" ]; then
+ local gerrit_url="https://review.trustedfirmware.org/c/${GERRIT_CHANGE_NUMBER}/${GERRIT_PATCHSET_NUMBER}"
+ elif [ -n "${GERRIT_REFSPEC}" ]; then
+ local gerrit_url=$(echo ${GERRIT_REFSPEC} |
+ awk -F/ '{print "https://review.trustedfirmware.org/c/" $4 "/" $5}')
+ fi
- # must parameters for yaml generation
- local payload_type="${payload_type:?}"
+ local yaml_template_file="${workspace}/fvp_template.yaml"
- "$ci_root/script/gen_fvp_${payload_type}_yaml.sh" > "$yaml_template_file"
+ pushd "${ci_root}/script/lava-templates"
+ expand_template "fvp-${payload_type:?}.yaml" > "$yaml_template_file"
+ popd
- archive_file "$yaml_template_file"
+ archive_file "${yaml_template_file}"
}
gen_fvp_yaml() {