-
Notifications
You must be signed in to change notification settings - Fork 16
/
trunk_merge.sh
executable file
·49 lines (41 loc) · 1.42 KB
/
trunk_merge.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# shellcheck disable=SC2086
set -euo pipefail
if [[ ${INPUT_DEBUG} == "true" ]]; then
set -x
fi
fetch() {
git -c protocol.version=2 fetch -q \
--no-tags \
--no-recurse-submodules \
"$@"
}
MINIMUM_CHECK_RUN_ID_VERSION=1.7.0
head_sha=$(git rev-parse HEAD)
fetch --depth=2 origin "${head_sha}"
upstream=$(git rev-parse HEAD^1)
git_commit=$(git rev-parse HEAD^2)
echo "Detected merge queue commit, using HEAD^1 (${upstream}) as upstream and HEAD^2 (${git_commit}) as github commit"
if [[ -n ${INPUT_CHECK_RUN_ID} ]]; then
trunk_version="$(${TRUNK_PATH} version)"
# trunk-ignore-begin(shellcheck/SC2312): the == will fail if anything inside the $() fails
if sort_result=$(printf "%s\n%s\n" "${MINIMUM_CHECK_RUN_ID_VERSION}" "${trunk_version}" | sort --version-sort); then
if [[ $(echo "${sort_result}" | head -n 1) == "${trunk_version}" ]]; then
echo "::error::Please update your CLI to ${MINIMUM_CHECK_RUN_ID_VERSION} or higher (current version ${trunk_version})."
exit 1
fi
else
echo "::warning::sort --version-sort failed - continuing without checking CLI version"
fi
# trunk-ignore-end(shellcheck/SC2312)
annotation_argument=--trunk-annotate=${INPUT_CHECK_RUN_ID}
else
annotation_argument=""
fi
"${TRUNK_PATH}" check \
--ci \
--upstream "${upstream}" \
--github-commit "${git_commit}" \
--github-label "${INPUT_LABEL}" \
${annotation_argument} \
${INPUT_ARGUMENTS}