From 67e0e10c85e87e9934162390abe62eb075a6b2bd Mon Sep 17 00:00:00 2001 From: TJian Date: Mon, 11 May 2026 07:53:27 +0800 Subject: [PATCH] [ROCm] [CI] Add the same skip ci logic as CUDA CI (#3482) Signed-off-by: tjtanaa --- .buildkite/bootstrap-amd-omni.sh | 109 ++++++++++++++---- .../scripts/upload_pipeline_with_skip_ci.sh | 2 +- 2 files changed, 88 insertions(+), 23 deletions(-) diff --git a/.buildkite/bootstrap-amd-omni.sh b/.buildkite/bootstrap-amd-omni.sh index 9e7021493..284fd371a 100755 --- a/.buildkite/bootstrap-amd-omni.sh +++ b/.buildkite/bootstrap-amd-omni.sh @@ -56,6 +56,88 @@ check_run_all_label() { fi } +is_docs_only_change() { + local file_path + local has_any=0 + + while IFS= read -r file_path; do + [[ -z "${file_path}" ]] && continue + has_any=1 + + if [[ "${file_path}" == docs/* ]]; then + continue + fi + if [[ "${file_path}" == *.md ]]; then + continue + fi + if [[ "${file_path}" == "mkdocs.yml" ]]; then + continue + fi + return 1 + done + + [[ "${has_any}" -eq 1 ]] +} + +resolve_skip_ci() { + local is_pr_build=0 + local files + local base_branch base_ref + + if [[ "${BUILDKITE_PULL_REQUEST:-false}" != "false" && -n "${BUILDKITE_PULL_REQUEST:-}" ]]; then + is_pr_build=1 + fi + + if [[ "${is_pr_build}" -eq 1 ]]; then + base_branch="${BUILDKITE_PULL_REQUEST_BASE_BRANCH:-main}" + if ! git rev-parse --verify "origin/${base_branch}" >/dev/null 2>&1; then + echo "resolve_skip_ci: origin/${base_branch} not found locally; trying fetch" >&2 + git fetch --depth=200 origin "${base_branch}" >/dev/null 2>&1 || true + fi + + base_ref="" + if git rev-parse --verify "origin/${base_branch}" >/dev/null 2>&1; then + base_ref="origin/${base_branch}" + elif git rev-parse --verify "${base_branch}" >/dev/null 2>&1; then + base_ref="${base_branch}" + else + echo "resolve_skip_ci: cannot resolve PR base ${base_branch}; skip-ci=0" >&2 + echo -n 0 + return 0 + fi + + if ! files="$(git diff --name-only "${base_ref}...${BUILDKITE_COMMIT}" 2>/dev/null)"; then + echo "resolve_skip_ci: failed to compute PR changed files; skip-ci=0" >&2 + echo -n 0 + return 0 + fi + elif [[ "${BUILDKITE_BRANCH:-}" == "main" ]]; then + if ! git rev-parse --verify "${BUILDKITE_COMMIT}^" >/dev/null 2>&1; then + echo "resolve_skip_ci: commit has no parent on main; skip-ci=0" >&2 + echo -n 0 + return 0 + fi + if ! files="$(git diff --name-only "${BUILDKITE_COMMIT}^..${BUILDKITE_COMMIT}" 2>/dev/null)"; then + echo "resolve_skip_ci: failed to compute main changed files; skip-ci=0" >&2 + echo -n 0 + return 0 + fi + else + echo "resolve_skip_ci: not PR/main build; skip-ci=0" >&2 + echo -n 0 + return 0 + fi + + if is_docs_only_change <<< "${files}"; then + echo "resolve_skip_ci: docs-only change detected; skip-ci=1" >&2 + echo -n 1 + return 0 + fi + + echo "resolve_skip_ci: non-doc changes detected; skip-ci=0" >&2 + echo -n 0 +} + if [[ -z "${COV_ENABLED:-}" ]]; then COV_ENABLED=0 fi @@ -140,30 +222,13 @@ fi # Early exit start: skip pipeline if conditions are met # ---------------------------------------------------------------------- -# skip pipeline if all changed files are under docs/ +# Match CUDA Buildkite skip-ci behavior for docs/markdown-only changes. if [[ "${DOCS_ONLY_DISABLE}" != "1" ]]; then - if [[ -n "${file_diff:-}" ]]; then - docs_only=1 - # Robust iteration over newline-separated file_diff - while IFS= read -r f; do - [[ -z "$f" ]] && continue - # **Policy:** only skip if *every* path starts with docs/ - if [[ "$f" != docs/* ]]; then - docs_only=0 - break - fi - done < <(printf '%s\n' "$file_diff" | tr ' ' '\n' | tr -d '\r') - - if [[ "$docs_only" -eq 1 ]]; then - buildkite-agent annotate ":memo: CI skipped — docs/** only changes detected - -\`\`\` -${file_diff} -\`\`\`" --style "info" || true - echo "[docs-only] All changes are under docs/. Exiting before pipeline upload." - exit 0 + SKIP_CI="$(resolve_skip_ci)" + if [[ "${SKIP_CI}" == "1" ]]; then + echo "[docs-only] Docs/markdown-only changes detected. Exiting before pipeline upload." + exit 0 fi - fi fi # ---------------------------------------------------------------------- diff --git a/.buildkite/scripts/upload_pipeline_with_skip_ci.sh b/.buildkite/scripts/upload_pipeline_with_skip_ci.sh index d5de97e88..ff6dbbfca 100644 --- a/.buildkite/scripts/upload_pipeline_with_skip_ci.sh +++ b/.buildkite/scripts/upload_pipeline_with_skip_ci.sh @@ -21,7 +21,7 @@ is_docs_only_change() { if [[ "${file_path}" == *.md ]]; then continue fi - if [[ "${file_path}" == "mkdocs.yaml" ]]; then + if [[ "${file_path}" == "mkdocs.yml" ]]; then continue fi return 1