Skip to content

Commit 4fb8a9a

Browse files
committed
ci: extract job skipping logic into a script
1 parent 53be272 commit 4fb8a9a

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/ci/azure-pipelines/steps/run.yml

+1-14
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,8 @@ steps:
2121
- checkout: self
2222
fetchDepth: 2
2323

24-
# Set the SKIP_JOB environment variable if this job is supposed to only run
25-
# when submodules are updated and they were not. The following time consuming
26-
# tasks will be skipped when the environment variable is present.
27-
- bash: |
28-
set -e
29-
# Submodules pseudo-files inside git have the 160000 permissions, so when
30-
# those files are present in the diff a submodule was updated.
31-
if git diff HEAD^ | grep "^index .* 160000" >/dev/null 2>&1; then
32-
echo "Executing the job since submodules are updated"
33-
else
34-
echo "Not executing this job since no submodules were updated"
35-
echo "##vso[task.setvariable variable=SKIP_JOB;]1"
36-
fi
24+
- bash: src/ci/scripts/should-skip-this.sh
3725
displayName: Decide whether to run this job
38-
condition: and(succeeded(), variables.CI_ONLY_WHEN_SUBMODULES_CHANGED)
3926

4027
# Spawn a background process to collect CPU usage statistics which we'll upload
4128
# at the end of the build. See the comments in the script here for more

src/ci/scripts/should-skip-this.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
# Set the SKIP_JOB environment variable if this job is supposed to only run
3+
# when submodules are updated and they were not. The following time consuming
4+
# tasks will be skipped when the environment variable is present.
5+
6+
set -euo pipefail
7+
IFS=$'\n\t'
8+
9+
source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
10+
11+
if [[ -z "${CI_ONLY_WHEN_SUBMODULES_CHANGED+x}" ]]; then
12+
echo "Executing the job since there is no skip rule in effect"
13+
elif git diff HEAD^ | grep "^index .* 160000" >/dev/null 2>&1; then
14+
# Submodules pseudo-files inside git have the 160000 permissions, so when
15+
# those files are present in the diff a submodule was updated.
16+
echo "Executing the job since submodules are updated"
17+
else
18+
echo "Not executing this job since no submodules were updated"
19+
ciCommandSetEnv SKIP_JOB 1
20+
fi

0 commit comments

Comments
 (0)