forked from broadinstitute/warp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.sh
executable file
·95 lines (83 loc) · 3.08 KB
/
common.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
declare -r REPO_ROOT=$(git rev-parse --show-toplevel)
declare -r -a ENVIRONMENTS=(dev rc prod)
declare -r ENV_DEV=${ENVIRONMENTS[0]}
declare -r ENV_RC=${ENVIRONMENTS[1]}
declare -r ENV_PROD=${ENVIRONMENTS[2]}
function stderr() {
>&2 echo "$@"
}
function get_version_from_changelog() {
local -r changelog=${1}
echo $(grep -m1 '^#' ${changelog} | cut -f 2 -d ' ')
}
function get_dependencies_for_wdl() {
local -r wdl=${1}
local -a wdlImports=($(grep '^import ".*$' ${wdl} | cut -d ' ' -f 2 | sed 's|\.\.\/||g' | xargs -n1))
local -a subWorkflowImports=()
for import in ${wdlImports[@]}; do
subWorkflowImports=("${subWorkflowImports[@]}" $(get_dependencies_for_wdl ${import}))
done
echo ${wdlImports[@]} ${subWorkflowImports[@]}
}
function get_pipeline_dependencies() {
local -r pipeline=${1}
local -a basenameDependencies=()
local -r dependencies=($(get_dependencies_for_wdl ${pipeline}))
for dependency in ${dependencies[@]}; do
basenameDependencies+=($(basename ${dependency}))
done
echo ${basenameDependencies[@]} | tr ' ' '\n' | sort -u | tr '\n' ' '
}
function get_versioned_pipelines() {
local -r -a pipelines=($(find ${REPO_ROOT}/pipelines -type f -name '*.wdl'))
echo ${pipelines[@]}
}
function get_modified_pipelines() {
local -r commitToCompare=${1}
local -r -a pipelines=($(get_versioned_pipelines))
local -r -a changedWdls=($(git diff --name-only HEAD ${commitToCompare} | grep -E '.*\.wdl' | xargs -n1 basename))
local -a modifiedPipelines=()
for pipeline in ${pipelines[@]}; do
if [[ " ${changedWdls[@]}" =~ " $(basename ${pipeline})" ]]; then
modifiedPipelines+=(${pipeline})
else
dependencies=($(get_pipeline_dependencies ${pipeline}))
for changedWdl in ${changedWdls[@]}; do
if [[ " ${dependencies[@]}" =~ " ${changedWdl}" ]]; then
modifiedPipelines+=(${pipeline})
break
fi
done
fi
done
echo ${modifiedPipelines[@]}
}
function get_pipelines_to_test() {
local -r commitToCompare=${1}
local -r -a pipelines=($(get_versioned_pipelines))
local -r -a changedFiles=($(git diff --name-only HEAD ${commitToCompare}))
local -a pipelinesToTest=()
if [[ "${changedFiles[@]}" == *"verification/"* || \
"${changedFiles[@]}" == *"tests/broad"* ]]; then
pipelinesToTest+=(${pipelines[@]})
else
local -a modifiedPipelines=($(get_modified_pipelines ${commitToCompare}))
for pipeline in ${pipelines[@]}; do
# Name comparison includes a leading space to avoid discovering pipelines named with substrings of other pipeline names, i.e. "Arrays" and "MutilSampleArrays"
if [[ " ${modifiedPipelines[@]}" =~ " ${pipeline}" ]]; then
pipelinesToTest+=(${pipeline})
else
pipelineDirectory=$(dirname ${pipeline})
pipelineHomeDir=${pipelineDirectory/${REPO_ROOT}\//}
for changedFile in ${changedFiles[@]}; do
if [[ "$(dirname ${changedFile})" == "${pipelineHomeDir}"* ]]; then
pipelinesToTest+=(${pipeline})
break
fi
done
fi
done
fi
echo ${pipelinesToTest[@]}
}