Skip to content

Commit 53be272

Browse files
committed
ci: enable "run when submodule changes" with environment variables
We have a job in our CI (PR's x86_64-gnu-tools) that's supposed to run only when a submodule is changed in the PR, and it works by having a task at the start of the build that skips all the following tasks if the condition isn't met. Before this commit that task was gated with template parameters, which is a unique feature of Azure Pipelines. To make our CI more generic this commit switches the gate to use a simple environment variable plus a condition, which should be supported on more CI providers.
1 parent 2dd4e73 commit 53be272

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

src/ci/azure-pipelines/pr.yml

+3-11
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ jobs:
2222
IMAGE: x86_64-gnu-llvm-6.0
2323
mingw-check:
2424
IMAGE: mingw-check
25-
26-
- job: LinuxTools
27-
timeoutInMinutes: 600
28-
pool:
29-
vmImage: ubuntu-16.04
30-
steps:
31-
- template: steps/run.yml
32-
parameters:
33-
only_on_updated_submodules: 'yes'
34-
variables:
35-
IMAGE: x86_64-gnu-tools
25+
x86_64-gnu-tools:
26+
IMAGE: x86_64-gnu-tools
27+
CI_ONLY_WHEN_SUBMODULES_CHANGED: 1

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

+12-17
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
#
77
# Check travis config for `gdb --batch` command to print all crash logs
88

9-
parameters:
10-
# When this parameter is set to anything other than an empty string the tests
11-
# will only be executed when the commit updates submodules
12-
only_on_updated_submodules: ''
13-
149
steps:
1510

1611
# Disable automatic line ending conversion, which is enabled by default on
@@ -29,18 +24,18 @@ steps:
2924
# Set the SKIP_JOB environment variable if this job is supposed to only run
3025
# when submodules are updated and they were not. The following time consuming
3126
# tasks will be skipped when the environment variable is present.
32-
- ${{ if parameters.only_on_updated_submodules }}:
33-
- bash: |
34-
set -e
35-
# Submodules pseudo-files inside git have the 160000 permissions, so when
36-
# those files are present in the diff a submodule was updated.
37-
if git diff HEAD^ | grep "^index .* 160000" >/dev/null 2>&1; then
38-
echo "Executing the job since submodules are updated"
39-
else
40-
echo "Not executing this job since no submodules were updated"
41-
echo "##vso[task.setvariable variable=SKIP_JOB;]1"
42-
fi
43-
displayName: Decide whether to run this job
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
37+
displayName: Decide whether to run this job
38+
condition: and(succeeded(), variables.CI_ONLY_WHEN_SUBMODULES_CHANGED)
4439

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

0 commit comments

Comments
 (0)