-
Notifications
You must be signed in to change notification settings - Fork 4
/
diff.sh
executable file
·46 lines (41 loc) · 1.65 KB
/
diff.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
#!/bin/bash
source "${GITHUB_ACTION_PATH}/util.sh"
DIFF_BRANCH_HEAD_SHA="$(git show-ref --hash "origin/${DIFF_BRANCH}")"
echo "DIFF_BRANCH_HEAD_SHA=${DIFF_BRANCH_HEAD_SHA}" >> "${GITHUB_ENV}"
DIFF_BRANCH_HEAD_SHORT_SHA="$(git show-ref --hash=6 "origin/${DIFF_BRANCH}")"
echo "DIFF_BRANCH_HEAD_SHORT_SHA=${DIFF_BRANCH_HEAD_SHORT_SHA}" >> "${GITHUB_ENV}"
DIFF_BRANCH_HEAD_SHA_URL="$DEPLOY_REPO_URL/commit/$DIFF_BRANCH_HEAD_SHA"
echo "DIFF_BRANCH_HEAD_SHA_URL=${DIFF_BRANCH_HEAD_SHA_URL}" >> "${GITHUB_ENV}"
if is_debug; then
echo "[debug] DIFF_BRANCH_HEAD_SHA=${DIFF_BRANCH_HEAD_SHA}"
echo "[debug] DIFF_BRANCH_HEAD_SHORT_SHA=${DIFF_BRANCH_HEAD_SHORT_SHA}"
echo "[debug] DIFF_BRANCH_HEAD_SHA_URL=${DIFF_BRANCH_HEAD_SHA_URL}"
fi
if ! git diff --quiet "origin/${DIFF_BRANCH}" --; then
# Fail on non-zero exit
set -e
git diff "origin/${DIFF_BRANCH}" -- > git-diff
echo "git diff origin/${DIFF_BRANCH}:"
if is_debug; then
echo "[debug] git-diff:"
cat git-diff
fi
# Set random delimiter https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
# shellcheck disable=SC2129
echo "diff<<$EOF" >> "${GITHUB_OUTPUT}"
# shellcheck disable=SC2129
cat git-diff >> "${GITHUB_OUTPUT}"
# shellcheck disable=SC2129
echo "$EOF" >> "${GITHUB_OUTPUT}"
bytes="$(wc -c < git-diff | tr -d ' \n')"
echo
if is_debug; then
echo "[debug] git-diff bytes: ${bytes}"
fi
echo "diff-bytes=${bytes}" >> "${GITHUB_OUTPUT}"
rm git-diff
else
echo "There are no changes to push to the ${PUSH_BRANCH} branch when
compared with origin/${DIFF_BRANCH}."
fi