Skip to content

Commit 00fb8ad

Browse files
committed
Add check for changeset
1 parent c078252 commit 00fb8ad

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

script/check-for-changeset

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#! /bin/bash
2+
3+
DEEPEN_LENGTH=${DEEPEN_LENGTH:-10}
4+
MAX_DEPTH=${MAX_DEPTH:-300}
5+
6+
depth=0
7+
8+
# Fetch the base ref, i.e. main
9+
git fetch --no-tags --progress --depth=1 origin "+refs/heads/$GITHUB_BASE_REF:refs/heads/$GITHUB_BASE_REF"
10+
11+
# Keep fetching more commits until a merge base can be found
12+
while [ -z "$(git merge-base "$GITHUB_BASE_REF" "origin/$GITHUB_HEAD_REF")" ]; do
13+
git fetch --no-tags -q --deepen="$DEEPEN_LENGTH" origin "$GITHUB_BASE_REF" "$GITHUB_HEAD_REF" > /dev/null
14+
depth=$(( depth + $DEEPEN_LENGTH ))
15+
16+
# Make sure we don't end up in an infinite loop
17+
if [[ "$depth" -ge "$MAX_DEPTH" ]]; then
18+
echo "Could not find merge base, max depth exceeded."
19+
exit 1
20+
fi
21+
done
22+
23+
# Check for added .md files in the .changeset directory
24+
git diff --name-only origin/${GITHUB_BASE_REF}...origin/${GITHUB_HEAD_REF} | grep '.changeset/.*.md' > /dev/null || (
25+
exit_code=$?
26+
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"
27+
exit "${exit_code}"
28+
)

0 commit comments

Comments
 (0)