Skip to content

Commit 5e84805

Browse files
authored
Rollup merge of #65724 - pietroalbini:ci-remove-template-parameter, r=alexcrichton
ci: refactor pr tools job skipping 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. This PR also extracts the skipping logic into a script. r? @alexcrichton
2 parents 0d755ff + 95ad6c3 commit 5e84805

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
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

+2-20
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
@@ -26,21 +21,8 @@ steps:
2621
- checkout: self
2722
fetchDepth: 2
2823

29-
# Set the SKIP_JOB environment variable if this job is supposed to only run
30-
# when submodules are updated and they were not. The following time consuming
31-
# 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
24+
- bash: src/ci/scripts/should-skip-this.sh
25+
displayName: Decide whether to run this job
4426

4527
# Spawn a background process to collect CPU usage statistics which we'll upload
4628
# 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 --quiet "^index .* 160000"; 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)