-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
35 lines (31 loc) · 1.32 KB
/
action.yaml
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
name: "git-branch-behind-main"
description: "Check whether the current branch is behind main"
branding:
icon: git-branch
color: orange
runs:
using: "composite"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check
shell: bash
run: |
git-log-flat-colored() {
git --no-pager log --format="%C(yellow)%h%Creset %C(cyan)%cd%Creset %s %Cgreen%an%Creset" --date=short "$@"
}
CURRENT_FEATURE=$(git symbolic-ref --short -q HEAD)
CURRENT_PATH=$(git rev-parse --show-toplevel)
REFERENCE_BRANCH="origin/main"
echo -e "\033[0;34m >>-----当前核查仓库路径${CURRENT_PATH}-----<< \033[0m"
git fetch origin main
NB_COMMITS_BEHIND=$(git rev-list --left-right --count ${REFERENCE_BRANCH}...@ | cut -f1)
if [ "${NB_COMMITS_BEHIND}" -gt "0" ]; then
echo -e "\033[0;31m >>-----${CURRENT_FEATURE}-----<< 当前分支有 ${NB_COMMITS_BEHIND} 个提交落后于 \"${REFERENCE_BRANCH}\", 请合并最新的 main 分支代码\n \033[0m"
git-log-flat-colored ${REFERENCE_BRANCH} | head -"${NB_COMMITS_BEHIND}"
exit 2
else
echo -e "\033[0;32m >>-----${CURRENT_FEATURE}-----<<当前分支包含 ${REFERENCE_BRANCH} 分支上的所有提交记录 \033[0m"
fi