TranslateProject/scripts/check/collect.sh

47 lines
1.3 KiB
Bash
Raw Normal View History

#!/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}"
MERGE_BASE='HEAD^'
2021-01-16 15:56:38 +08:00
[ "$PULL_REQUEST_ID" != 'false' ] \
&& MERGE_BASE="$(git merge-base "$TARGET_BRANCH" HEAD)"
2018-10-24 11:37:11 +08:00
echo "[收集] 找到分叉节点:${MERGE_BASE}"
echo "[收集] 变更摘要:"
git --no-pager show --summary "${MERGE_BASE}..HEAD"
2018-10-24 11:37:11 +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 "[收集] 写出文件变更列表……"
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