Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions buildkite/scripts/monorepo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

show_help() {
cat << EOF
Usage: $(basename "$0") [OPTIONS]

Options:
--selection-mode MODE Selection mode (Triaged or Full)
--is-included-in-tag BOOL Is included in tag (True/False)
--is-included-in-scope BOOL Is included in scope (True/False)
--job-name NAME STRING Job name
--jobs-filter FILTER STRING Jobs filter
--scope-filter FILTER STRING Scope filter
--dirty-when PATTERN STRING Pattern for dirty check
--trigger CMD STRING Trigger command
-h, --help Show this help message
EOF
}

# Default values
SELECTION_MODE=""
IS_INCLUDED_IN_TAG=""
IS_INCLUDED_IN_SCOPE=""
JOB_NAME=""
JOBS_FILTER=""
SCOPE_FILTER=""
DIRTY_WHEN=""


# Parse
while [[ $# -gt 0 ]]; do
case "$1" in
--selection-mode)
SELECTION_MODE="$2"; shift 2;;
--is-included-in-tag)
IS_INCLUDED_IN_TAG="$2"; shift 2;;
--is-included-in-scope)
IS_INCLUDED_IN_SCOPE="$2"; shift 2;;
--job-name)
JOB_NAME="$2"; shift 2;;
--job-path)
JOB_PATH="$2"; shift 2;;
--jobs-filter)
JOBS_FILTER="$2"; shift 2;;
--scope-filter)
SCOPE_FILTER="$2"; shift 2;;
--dirty-when)
DIRTY_WHEN="$2"; shift 2;;
-h|--help)
show_help; exit 0;;
*)
echo "Unknown option: $1"; show_help; exit 1;;
esac
done

if [[ -z "$SELECTION_MODE" ]]; then
echo "Error: --selection-mode is required"; show_help; exit 1
fi

should_trigger=false

if [[ "$SELECTION_MODE" == "Triaged" ]]; then
if [[ "$IS_INCLUDED_IN_TAG" == "False" ]]; then
echo "Skipping $JOB_NAME because this job is not falling under $JOBS_FILTER filter "
elif [[ "$IS_INCLUDED_IN_SCOPE" == "False" ]]; then
echo "Skipping $JOB_NAME because this job is not falling under $SCOPE_FILTER stage"
elif grep -E -q "$DIRTY_WHEN" _computed_diff.txt; then
echo "Triggering $JOB_NAME for reason:"
grep -E "$DIRTY_WHEN" _computed_diff.txt
should_trigger=true
else
echo "Skipping $JOB_NAME because is irrelevant to PR changes"
fi
elif [[ "$SELECTION_MODE" == "Full" ]]; then
if [[ "$IS_INCLUDED_IN_TAG" == "False" ]]; then
echo "Skipping $JOB_NAME because this job is not falling under $JOBS_FILTER filter "
elif [[ "$IS_INCLUDED_IN_SCOPE" == "False" ]]; then
echo "Skipping $JOB_NAME because this job is not falling under $SCOPE_FILTER stage"
else
echo "Triggering $JOB_NAME because this is a stable buildkite run"
should_trigger=true
fi
else
echo "Unknown selection mode: $SELECTION_MODE"; show_help; exit 1
fi

if [[ "$should_trigger" == "true" ]]; then
dhall-to-yaml --quoted <<< "(./buildkite/src/Jobs/${JOB_PATH}/${JOB_NAME}.dhall).pipeline" | buildkite-agent pipeline upload
fi
46 changes: 12 additions & 34 deletions buildkite/src/Monorepo.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ let PipelineScopeFilter = ./Pipeline/ScopeFilter.dhall

let Size = ./Command/Size.dhall

let triggerCommand = ./Pipeline/TriggerCommand.dhall

let jobs
: List JobSpec.Type
= List/map
Expand Down Expand Up @@ -77,38 +75,18 @@ let commands

let dirtyWhen = SelectFiles.compile job.dirtyWhen

let trigger =
triggerCommand "src/Jobs/${job.path}/${job.name}.dhall"

let pipelineHandlers =
{ Triaged =
''
if [ "${isIncludedInTag}" == "False" ]; then
echo "Skipping ${job.name} because this job is not falling under ${jobsFilter} filter "
elif [ "${isIncludedInScope}" == "False" ]; then
echo "Skipping ${job.name} because this is job is not falling under ${scopeFilter} stage"
elif (cat _computed_diff.txt | egrep -q '${dirtyWhen}'); then
echo "Triggering ${job.name} for reason:"
cat _computed_diff.txt | egrep '${dirtyWhen}'
${Cmd.format trigger}
else
echo "Skipping ${job.name} because is irrelevant to PR changes"
fi
''
, Full =
''
if [ "${isIncludedInTag}" == "False" ]; then
echo "Skipping ${job.name} because this job is not falling under ${jobsFilter} filter "
elif [ "${isIncludedInScope}" == "False" ]; then
echo "Skipping ${job.name} because this is job is not falling under ${scopeFilter} stage"
else
echo "Triggering ${job.name} because this is a stable buildkite run"
${Cmd.format trigger}
fi
''
}

in Cmd.quietly (merge pipelineHandlers selection)
in Cmd.run
( "./buildkite/scripts/monorepo.sh "
++ "--selection-mode ${PipelineJobSelection.capitalName
selection} "
++ "--job-name ${job.name} "
++ "--job-path ${job.path} "
++ "--jobs-filter \"${jobsFilter}\" "
++ "--is-included-in-tag ${isIncludedInTag} "
++ "--scope-filter \"${scopeFilter}\" "
++ "--is-included-in-scope ${isIncludedInScope} "
++ "--dirty-when '${dirtyWhen}' "
)
)
jobs

Expand Down
7 changes: 0 additions & 7 deletions buildkite/src/Pipeline/TriggerCommand.dhall

This file was deleted.