From 3abda6ba0efadd161db64dae7aa39a2b282df6b5 Mon Sep 17 00:00:00 2001 From: dkijania Date: Tue, 2 Dec 2025 16:18:22 +0100 Subject: [PATCH] move monorepo logic to script --- buildkite/scripts/monorepo.sh | 89 +++++++++++++++++++++ buildkite/src/Monorepo.dhall | 46 +++-------- buildkite/src/Pipeline/TriggerCommand.dhall | 7 -- 3 files changed, 101 insertions(+), 41 deletions(-) create mode 100755 buildkite/scripts/monorepo.sh delete mode 100644 buildkite/src/Pipeline/TriggerCommand.dhall diff --git a/buildkite/scripts/monorepo.sh b/buildkite/scripts/monorepo.sh new file mode 100755 index 000000000000..f8dc2ba3b270 --- /dev/null +++ b/buildkite/scripts/monorepo.sh @@ -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 diff --git a/buildkite/src/Monorepo.dhall b/buildkite/src/Monorepo.dhall index 61d0d77c0270..38a61ffbb941 100644 --- a/buildkite/src/Monorepo.dhall +++ b/buildkite/src/Monorepo.dhall @@ -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 @@ -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 diff --git a/buildkite/src/Pipeline/TriggerCommand.dhall b/buildkite/src/Pipeline/TriggerCommand.dhall deleted file mode 100644 index 37bcd389ebc3..000000000000 --- a/buildkite/src/Pipeline/TriggerCommand.dhall +++ /dev/null @@ -1,7 +0,0 @@ -let Cmd = ../Lib/Cmds.dhall - -in ( \(dhallPipelineRelativeToBuildKiteDir : Text) - -> Cmd.quietly - "dhall-to-yaml --quoted <<< '(./buildkite/${dhallPipelineRelativeToBuildKiteDir}).pipeline' | buildkite-agent pipeline upload" - ) - : Text -> Cmd.Type