chore: update sync_to_enterprise.yml to enhance branch management and streamline push process to enterprise repository
This commit is contained in:
1 parent
a4198743a4
commit
f8173ace88
1 file changed
+29
-31
@@ -1,3 +1,4 @@
|
||||
# 同步社区版代码到企业版
|
||||
name: Sync to Enterprise
|
||||
|
||||
on:
|
||||
@@ -10,43 +11,40 @@ jobs:
|
||||
sync:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout source code
|
||||
# 1. 检出当前仓库
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Sync to enterprise repo
|
||||
env:
|
||||
TOKEN: ${{ secrets.ENTERPRISE_REPO_TOKEN }}
|
||||
# 2. 配置远程仓库
|
||||
- name: Configure remote
|
||||
run: |
|
||||
# 设置 git config
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git remote add enterprise https://${{ secrets.ENTERPRISE_GH_TOKEN }}@github.com/cedar-v/license-manager-enterprise.git
|
||||
git remote -v
|
||||
shell: bash
|
||||
|
||||
# 用认证 URL
|
||||
REPO_URL="https://x-access-token:$TOKEN@github.com/cedar-v/license-manager-enterprise.git"
|
||||
# 3. 配置 Git 用户信息
|
||||
- name: Configure git identity
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
shell: bash
|
||||
|
||||
echo "Cloning enterprise repo..."
|
||||
git clone "$REPO_URL" /tmp/enterprise-repo
|
||||
# 4. 切换到 license-manager 分支,不存在则创建
|
||||
- name: Switch to license-manager branch
|
||||
run: |
|
||||
git checkout license-manager || git checkout -b license-manager
|
||||
shell: bash
|
||||
|
||||
cd /tmp/enterprise-repo
|
||||
# 5. 合并 main 分支的更新
|
||||
- name: Merge main to license-manager
|
||||
run: |
|
||||
git merge origin/main --no-edit
|
||||
shell: bash
|
||||
|
||||
# 清理 enterprise repo 里的 .git(避免复制过来的)
|
||||
rm -rf .git
|
||||
|
||||
# 从原始仓库复制文件,排除 .git 目录
|
||||
cd "$GITHUB_WORKSPACE"
|
||||
cp -r . /tmp/enterprise-repo/
|
||||
|
||||
cd /tmp/enterprise-repo
|
||||
git init
|
||||
git add -A
|
||||
git -c "user.email=github-actions[bot]@users.noreply.github.com" \
|
||||
-c "user.name=github-actions[bot]" \
|
||||
commit -m "Sync from license-manager - $(date)" || echo "Nothing to commit"
|
||||
|
||||
# 显式设置 remote 并 push
|
||||
git remote add enterprise "$REPO_URL"
|
||||
git push enterprise master --force
|
||||
|
||||
echo "Done!"
|
||||
# 6. 推送到企业版仓库
|
||||
- name: Push to enterprise
|
||||
run: |
|
||||
git push enterprise license-manager --force
|
||||
shell: bash
|
||||
Reference in new issue
Block a user