From 4fb8a9a73cb5c42543e02ce1d797a6d028f6068f Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Wed, 23 Oct 2019 16:07:13 +0200 Subject: ci: extract job skipping logic into a script --- src/ci/scripts/should-skip-this.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 src/ci/scripts/should-skip-this.sh (limited to 'src/ci/scripts') diff --git a/src/ci/scripts/should-skip-this.sh b/src/ci/scripts/should-skip-this.sh new file mode 100755 index 00000000000..a38099a2db7 --- /dev/null +++ b/src/ci/scripts/should-skip-this.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Set the SKIP_JOB environment variable if this job is supposed to only run +# when submodules are updated and they were not. The following time consuming +# tasks will be skipped when the environment variable is present. + +set -euo pipefail +IFS=$'\n\t' + +source "$(cd "$(dirname "$0")" && pwd)/../shared.sh" + +if [[ -z "${CI_ONLY_WHEN_SUBMODULES_CHANGED+x}" ]]; then + echo "Executing the job since there is no skip rule in effect" +elif git diff HEAD^ | grep "^index .* 160000" >/dev/null 2>&1; then + # Submodules pseudo-files inside git have the 160000 permissions, so when + # those files are present in the diff a submodule was updated. + echo "Executing the job since submodules are updated" +else + echo "Not executing this job since no submodules were updated" + ciCommandSetEnv SKIP_JOB 1 +fi -- cgit 1.4.1-3-g733a5