Skip to content

Commit a6aa7c1

Browse files
committed
move monorepo logic to script
1 parent e280868 commit a6aa7c1

File tree

3 files changed

+101
-41
lines changed

3 files changed

+101
-41
lines changed

buildkite/scripts/monorepo.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
3+
show_help() {
4+
cat << EOF
5+
Usage: $(basename "$0") [OPTIONS]
6+
7+
Options:
8+
--selection-mode MODE Selection mode (Triaged or Full)
9+
--is-included-in-tag BOOL Is included in tag (True/False)
10+
--is-included-in-scope BOOL Is included in scope (True/False)
11+
--job-name NAME STRING Job name
12+
--jobs-filter FILTER STRING Jobs filter
13+
--scope-filter FILTER STRING Scope filter
14+
--dirty-when PATTERN STRING Pattern for dirty check
15+
--trigger CMD STRING Trigger command
16+
-h, --help Show this help message
17+
EOF
18+
}
19+
20+
# Default values
21+
SELECTION_MODE=""
22+
IS_INCLUDED_IN_TAG=""
23+
IS_INCLUDED_IN_SCOPE=""
24+
JOB_NAME=""
25+
JOBS_FILTER=""
26+
SCOPE_FILTER=""
27+
DIRTY_WHEN=""
28+
29+
30+
# Parse
31+
while [[ $# -gt 0 ]]; do
32+
case "$1" in
33+
--selection-mode)
34+
SELECTION_MODE="$2"; shift 2;;
35+
--is-included-in-tag)
36+
IS_INCLUDED_IN_TAG="$2"; shift 2;;
37+
--is-included-in-scope)
38+
IS_INCLUDED_IN_SCOPE="$2"; shift 2;;
39+
--job-name)
40+
JOB_NAME="$2"; shift 2;;
41+
--job-path)
42+
JOB_PATH="$2"; shift 2;;
43+
--jobs-filter)
44+
JOBS_FILTER="$2"; shift 2;;
45+
--scope-filter)
46+
SCOPE_FILTER="$2"; shift 2;;
47+
--dirty-when)
48+
DIRTY_WHEN="$2"; shift 2;;
49+
-h|--help)
50+
show_help; exit 0;;
51+
*)
52+
echo "Unknown option: $1"; show_help; exit 1;;
53+
esac
54+
done
55+
56+
if [[ -z "$SELECTION_MODE" ]]; then
57+
echo "Error: --selection-mode is required"; show_help; exit 1
58+
fi
59+
60+
should_trigger=false
61+
62+
if [[ "$SELECTION_MODE" == "Triaged" ]]; then
63+
if [[ "$IS_INCLUDED_IN_TAG" == "False" ]]; then
64+
echo "Skipping $JOB_NAME because this job is not falling under $JOBS_FILTER filter "
65+
elif [[ "$IS_INCLUDED_IN_SCOPE" == "False" ]]; then
66+
echo "Skipping $JOB_NAME because this job is not falling under $SCOPE_FILTER stage"
67+
elif grep -E -q "$DIRTY_WHEN" _computed_diff.txt; then
68+
echo "Triggering $JOB_NAME for reason:"
69+
grep -E "$DIRTY_WHEN" _computed_diff.txt
70+
should_trigger=true
71+
else
72+
echo "Skipping $JOB_NAME because is irrelevant to PR changes"
73+
fi
74+
elif [[ "$SELECTION_MODE" == "Full" ]]; then
75+
if [[ "$IS_INCLUDED_IN_TAG" == "False" ]]; then
76+
echo "Skipping $JOB_NAME because this job is not falling under $JOBS_FILTER filter "
77+
elif [[ "$IS_INCLUDED_IN_SCOPE" == "False" ]]; then
78+
echo "Skipping $JOB_NAME because this job is not falling under $SCOPE_FILTER stage"
79+
else
80+
echo "Triggering $JOB_NAME because this is a stable buildkite run"
81+
should_trigger=true
82+
fi
83+
else
84+
echo "Unknown selection mode: $SELECTION_MODE"; show_help; exit 1
85+
fi
86+
87+
if [[ "$should_trigger" == "true" ]]; then
88+
dhall-to-yaml --quoted <<< "(./buildkite/src/Jobs/${JOB_PATH}/${JOB_NAME}.dhall).pipeline" | buildkite-agent pipeline upload
89+
fi

buildkite/src/Monorepo.dhall

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ let PipelineScopeFilter = ./Pipeline/ScopeFilter.dhall
2828

2929
let Size = ./Command/Size.dhall
3030

31-
let triggerCommand = ./Pipeline/TriggerCommand.dhall
32-
3331
let jobs
3432
: List JobSpec.Type
3533
= List/map
@@ -77,38 +75,18 @@ let commands
7775

7876
let dirtyWhen = SelectFiles.compile job.dirtyWhen
7977

80-
let trigger =
81-
triggerCommand "src/Jobs/${job.path}/${job.name}.dhall"
82-
83-
let pipelineHandlers =
84-
{ Triaged =
85-
''
86-
if [ "${isIncludedInTag}" == "False" ]; then
87-
echo "Skipping ${job.name} because this job is not falling under ${jobsFilter} filter "
88-
elif [ "${isIncludedInScope}" == "False" ]; then
89-
echo "Skipping ${job.name} because this is job is not falling under ${scopeFilter} stage"
90-
elif (cat _computed_diff.txt | egrep -q '${dirtyWhen}'); then
91-
echo "Triggering ${job.name} for reason:"
92-
cat _computed_diff.txt | egrep '${dirtyWhen}'
93-
${Cmd.format trigger}
94-
else
95-
echo "Skipping ${job.name} because is irrelevant to PR changes"
96-
fi
97-
''
98-
, Full =
99-
''
100-
if [ "${isIncludedInTag}" == "False" ]; then
101-
echo "Skipping ${job.name} because this job is not falling under ${jobsFilter} filter "
102-
elif [ "${isIncludedInScope}" == "False" ]; then
103-
echo "Skipping ${job.name} because this is job is not falling under ${scopeFilter} stage"
104-
else
105-
echo "Triggering ${job.name} because this is a stable buildkite run"
106-
${Cmd.format trigger}
107-
fi
108-
''
109-
}
110-
111-
in Cmd.quietly (merge pipelineHandlers selection)
78+
in Cmd.run
79+
( "./buildkite/scripts/monorepo.sh "
80+
++ "--selection-mode ${PipelineJobSelection.capitalName
81+
selection} "
82+
++ "--job-name ${job.name} "
83+
++ "--job-path ${job.path} "
84+
++ "--jobs-filter \"${jobsFilter}\" "
85+
++ "--is-included-in-tag ${isIncludedInTag} "
86+
++ "--scope-filter \"${scopeFilter}\" "
87+
++ "--is-included-in-scope ${isIncludedInScope} "
88+
++ "--dirty-when '${dirtyWhen}' "
89+
)
11290
)
11391
jobs
11492

buildkite/src/Pipeline/TriggerCommand.dhall

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)