mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
ci: extract job skipping logic into a script
This commit is contained in:
parent
53be272415
commit
4fb8a9a73c
@ -21,21 +21,8 @@ steps:
|
||||
- checkout: self
|
||||
fetchDepth: 2
|
||||
|
||||
# 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.
|
||||
- bash: |
|
||||
set -e
|
||||
# Submodules pseudo-files inside git have the 160000 permissions, so when
|
||||
# those files are present in the diff a submodule was updated.
|
||||
if git diff HEAD^ | grep "^index .* 160000" >/dev/null 2>&1; then
|
||||
echo "Executing the job since submodules are updated"
|
||||
else
|
||||
echo "Not executing this job since no submodules were updated"
|
||||
echo "##vso[task.setvariable variable=SKIP_JOB;]1"
|
||||
fi
|
||||
- bash: src/ci/scripts/should-skip-this.sh
|
||||
displayName: Decide whether to run this job
|
||||
condition: and(succeeded(), variables.CI_ONLY_WHEN_SUBMODULES_CHANGED)
|
||||
|
||||
# Spawn a background process to collect CPU usage statistics which we'll upload
|
||||
# at the end of the build. See the comments in the script here for more
|
||||
|
20
src/ci/scripts/should-skip-this.sh
Executable file
20
src/ci/scripts/should-skip-this.sh
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user