From 64833ea55389b478ef9cbcc93ac9dd1848fea267 Mon Sep 17 00:00:00 2001 From: Fritz Lin Date: Fri, 2 Aug 2024 12:25:39 +0800 Subject: [PATCH] test sync-from-gitee --- .github/workflows/sync-from-gitee.yml | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/sync-from-gitee.yml diff --git a/.github/workflows/sync-from-gitee.yml b/.github/workflows/sync-from-gitee.yml new file mode 100644 index 0000000..07b0825 --- /dev/null +++ b/.github/workflows/sync-from-gitee.yml @@ -0,0 +1,47 @@ +name: Sync from Gitee + +on: + workflow_dispatch: + schedule: + - cron: '20 5 * * *' # UTC时区; 每天执行一次 + +jobs: + sync: + if: github.ref == 'refs/heads/main' # 仅当在main分支上时才执行 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Pull changes from Gitee + run: | + git remote add gitee https://gitee.com/we-mid/go.git + git fetch gitee main + + # 判断某个远端分支,相比与当前本地分支是否存在ahead提交 + echo '---' + git rev-list HEAD..gitee/main + echo '---' + git rev-list gitee/main..HEAD + echo '---' + git rev-list --count HEAD..gitee/main + echo '---' + git rev-list --count gitee/main..HEAD + echo '---' + # if [ "$(git rev-list --count main..gitee/main)" != '0' ]; then + # if git rev-list main..gitee/main | grep -q .; then + if [ "$(git rev-list --count main..gitee/main)" -gt 0 ]; then + echo "ahead" + + # fix: Committer identity unknown + git config user.email "actions@github.com" + git config user.name "GitHub Actions" + + # 避免额外提交: Merge remote-tracking branch 'xx/xxx' + # git merge gitee/main --allow-unrelated-histories + # git push origin main + # 使用 rebase 而不是 merge + git rebase gitee/main + git push origin main --force-with-lease + else + echo "not ahead" + echo "skip" + fi