From 00fb8ad84344864c4bace931a765d2892f758a87 Mon Sep 17 00:00:00 2001 From: Jon Rohan Date: Tue, 17 Sep 2024 17:24:27 +0000 Subject: [PATCH] Add check for changeset --- script/check-for-changeset | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 script/check-for-changeset diff --git a/script/check-for-changeset b/script/check-for-changeset new file mode 100755 index 0000000000..090cd5b6aa --- /dev/null +++ b/script/check-for-changeset @@ -0,0 +1,28 @@ +#! /bin/bash + +DEEPEN_LENGTH=${DEEPEN_LENGTH:-10} +MAX_DEPTH=${MAX_DEPTH:-300} + +depth=0 + +# Fetch the base ref, i.e. main +git fetch --no-tags --progress --depth=1 origin "+refs/heads/$GITHUB_BASE_REF:refs/heads/$GITHUB_BASE_REF" + +# Keep fetching more commits until a merge base can be found +while [ -z "$(git merge-base "$GITHUB_BASE_REF" "origin/$GITHUB_HEAD_REF")" ]; do + git fetch --no-tags -q --deepen="$DEEPEN_LENGTH" origin "$GITHUB_BASE_REF" "$GITHUB_HEAD_REF" > /dev/null + depth=$(( depth + $DEEPEN_LENGTH )) + + # Make sure we don't end up in an infinite loop + if [[ "$depth" -ge "$MAX_DEPTH" ]]; then + echo "Could not find merge base, max depth exceeded." + exit 1 + fi +done + +# Check for added .md files in the .changeset directory +git diff --name-only origin/${GITHUB_BASE_REF}...origin/${GITHUB_HEAD_REF} | grep '.changeset/.*.md' > /dev/null || ( + exit_code=$? + echo "No changeset found. If these changes should not result in a new version, apply the ${SKIP_LABEL} label to this pull request. If these changes should result in a version bump, please add a changeset https://git.io/J6QvQ" + exit "${exit_code}" +)