2018-11-07 12:08:10 +08:00
|
|
|
#!/bin/sh
|
2018-10-24 11:37:11 +08:00
|
|
|
# PR 文件变更收集
|
|
|
|
set -e
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# 读入:(无)
|
|
|
|
# 写出:
|
|
|
|
# - /tmp/changes # 文件变更列表
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
echo "[收集] 计算 PR 分支与目标分支的分叉点……"
|
|
|
|
|
2021-01-16 15:56:38 +08:00
|
|
|
TARGET_BRANCH="${GITHUB_BASE_REF:-master}"
|
2018-10-24 11:37:11 +08:00
|
|
|
echo "[收集] 目标分支设定为:${TARGET_BRANCH}"
|
|
|
|
|
2018-10-24 12:27:21 +08:00
|
|
|
MERGE_BASE='HEAD^'
|
2021-01-16 15:56:38 +08:00
|
|
|
[ "$PULL_REQUEST_ID" != 'false' ] \
|
2018-10-24 12:27:21 +08:00
|
|
|
&& MERGE_BASE="$(git merge-base "$TARGET_BRANCH" HEAD)"
|
2018-10-24 11:37:11 +08:00
|
|
|
echo "[收集] 找到分叉节点:${MERGE_BASE}"
|
|
|
|
|
2018-10-24 12:52:07 +08:00
|
|
|
echo "[收集] 变更摘要:"
|
|
|
|
git --no-pager show --summary "${MERGE_BASE}..HEAD"
|
|
|
|
|
2018-10-24 11:37:11 +08:00
|
|
|
{
|
2018-10-24 12:52:07 +08:00
|
|
|
git --no-pager log --oneline "${MERGE_BASE}..HEAD" | grep -Eq '绕过检查' && {
|
2018-10-24 11:37:11 +08:00
|
|
|
touch /tmp/bypass
|
|
|
|
echo "[收集] 已标记为绕过检查项"
|
|
|
|
}
|
|
|
|
} || true
|
|
|
|
|
|
|
|
echo "[收集] 写出文件变更列表……"
|
|
|
|
|
2018-11-07 12:08:10 +08:00
|
|
|
RAW_CHANGES="$(git diff "$MERGE_BASE" HEAD --no-renames --name-status -z \
|
|
|
|
| tr '\0' '\n')"
|
|
|
|
[ -z "$RAW_CHANGES" ] && {
|
|
|
|
echo "[收集] 无变更,退出……"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
echo "$RAW_CHANGES" | while read -r STAT; do
|
|
|
|
read -r NAME
|
|
|
|
echo "${STAT} ${NAME}"
|
|
|
|
done > /tmp/changes
|
2018-10-24 11:37:11 +08:00
|
|
|
echo "[收集] 已写出文件变更列表:"
|
|
|
|
cat /tmp/changes
|
|
|
|
{ [ -z "$(cat /tmp/changes)" ] && echo "(无变更)"; } || true
|