Skip to content

Commit 0189c01

Browse files
committed
auto sync #3
1 parent ba2b402 commit 0189c01

File tree

5 files changed

+102
-113
lines changed

5 files changed

+102
-113
lines changed

.github/workflows/sync.yml

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# -------------------------------------------------------------------
77
# https://github.com/Soltus
88

9-
name: Test
9+
name: sync
1010

1111
on:
1212
workflow_call:
@@ -58,37 +58,11 @@ jobs:
5858
- name: Check if target_sync_branch exists in the remote
5959
id: check-branch-exists
6060
run: |
61-
# 创建一个临时分支来fetch远程分支的内容
62-
git fetch upstream ${{ inputs.upstream_sync_branch }}:temp_${{ inputs.upstream_sync_branch }}
63-
git checkout temp_${{ inputs.upstream_sync_branch }}
64-
# 强制删除本地分支 并忽略报错(如果分支不存在)
65-
git branch -D ${{ inputs.target_sync_branch }} || true
66-
git branch ${{ inputs.target_sync_branch }} temp_${{ inputs.upstream_sync_branch }} # 创建新分支
67-
# 强制推送新分支到远程仓库
68-
git push --force origin ${{ inputs.target_sync_branch }}
69-
70-
# # REQUIRED step
71-
# # Step 2: run the sync action
72-
# - name: Sync upstream changes
73-
# id: sync
74-
# if: steps.check-branch-exists.outputs.branch_exists == 'true'
75-
# uses: aormsby/[email protected]
76-
# with:
77-
# target_sync_branch: ${{ inputs.target_sync_branch }}
78-
# target_repo_token: ${{ secrets.TOEKN_FOREVER_FULL_WRITE }} # 可能涉及 workflows 的修改,需要对应权限
79-
# upstream_repo_access_token: ${{ secrets.TOEKN_FOREVER_FULL_WRITE }} # 上游如果不是 ${{ github.repository }} 则需要
80-
# upstream_sync_branch: ${{ inputs.upstream_sync_branch }}
81-
# upstream_sync_repo: ${{ inputs.upstream_sync_repo }}
82-
# test_mode: ${{ inputs.sync_test_mode }}
83-
84-
# # Step 3: Display a sample message based on the sync output var 'has_new_commits'
85-
# - name: New commits found
86-
# if: steps.sync.outputs.has_new_commits == 'true'
87-
# run: echo "New commits were found to sync."
88-
89-
# - name: No new commits
90-
# if: steps.sync.outputs.has_new_commits == 'false'
91-
# run: echo "There were no new commits."
92-
93-
# - name: Show value of 'has_new_commits'
94-
# run: echo ${{ steps.sync.outputs.has_new_commits }}
61+
# 创建一个临时分支来fetch远程分支的内容
62+
git fetch upstream ${{ inputs.upstream_sync_branch }}:temp_${{ inputs.upstream_sync_branch }}
63+
git checkout temp_${{ inputs.upstream_sync_branch }}
64+
# 强制删除本地分支 并忽略报错(如果分支不存在)
65+
git branch -D ${{ inputs.target_sync_branch }} || true
66+
git branch ${{ inputs.target_sync_branch }} temp_${{ inputs.upstream_sync_branch }} # 创建新分支
67+
# 强制推送新分支到远程仓库
68+
git push --force origin ${{ inputs.target_sync_branch }}

.github/workflows/test-all.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,44 @@ jobs:
1616
with:
1717
name: "test"
1818
repo_name: "prototype-test/dist-repo-use-branch_test"
19+
upstream_dist_path: "test"
1920
test2:
2021
uses: ./.github/workflows/validation-proxy.yml
2122
needs: []
2223
secrets: inherit
2324
with:
2425
name: "test2"
2526
repo_name: "prototype-test/dist-repo-use-branch_test2"
27+
upstream_dist_path: "test2"
2628
test3:
2729
uses: ./.github/workflows/validation-proxy.yml
2830
needs: []
2931
secrets: inherit
3032
with:
3133
name: "test3"
3234
repo_name: "prototype-test/dist-repo-use-branch_test3"
35+
upstream_dist_path: "test3"
3336
test4:
3437
uses: ./.github/workflows/validation-proxy.yml
3538
needs: []
3639
secrets: inherit
3740
with:
3841
name: "test4"
3942
repo_name: "prototype-test/dist-repo-use-branch_test4"
43+
upstream_dist_path: "test4"
4044
test5:
4145
uses: ./.github/workflows/validation-proxy.yml
4246
needs: []
4347
secrets: inherit
4448
with:
4549
name: "test5"
4650
repo_name: "prototype-test/dist-repo-use-branch_test5"
51+
upstream_dist_path: "test5"
4752
test6:
4853
uses: ./.github/workflows/validation-proxy.yml
4954
needs: []
5055
secrets: inherit
5156
with:
5257
name: "test6"
53-
repo_name: "prototype-test/dist-repo-use-branch_test6"
58+
repo_name: "prototype-test/dist-repo-use-branch_test6"
59+
upstream_dist_path: "test6"

.github/workflows/test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ on:
1111
description: "目标(下游)仓库,格式为 owner/repository ,必须指定"
1212
required: true
1313
type: string
14+
upstream_dist_path:
15+
description: "上游仓库分发路径,必须指定,不能以 / 结尾"
16+
required: true
17+
type: string
1418

1519
jobs:
1620
build:
1721
uses: ./.github/workflows/validation-proxy.yml
1822
secrets: inherit
1923
with:
2024
name: ${{ inputs.name }}
21-
repo_name: ${{ inputs.repo_name }}
25+
repo_name: ${{ inputs.repo_name }}
26+
upstream_dist_path: ${{ inputs.upstream_dist_path }}

.github/workflows/validation-proxy.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
workflow_call:
88
inputs:
99
name:
10-
description: "目标名,必须指定"
10+
description: "目标(下游)名,必须指定"
1111
required: true
1212
type: string
1313
repo_name:
@@ -18,26 +18,30 @@ on:
1818
description: "目标(下游)仓库主分支名"
1919
default: main
2020
type: string
21-
upstream_repository: # 上游仓库
21+
upstream_repository:
2222
description: "上游仓库, 格式为 owner/repository ,不指定则默认为当前仓库"
2323
default: prototype-validation/dist-repo-use-branch_upstream # ${{ github.repository }}
2424
type: string
25+
upstream_dist_path:
26+
description: "上游仓库分发路径,必须指定,不能以 / 结尾"
27+
required: true
28+
type: string
2529

2630
jobs:
27-
build:
31+
dist:
2832
uses: ./.github/workflows/validation.yml
2933
secrets: inherit
3034
with:
3135
repository: ${{ inputs.upstream_repository }}
3236
main_branch: ${{ inputs.main_branch }}
33-
cd_path: ${{ inputs.name }}/ci
34-
cd_branch: ${{ inputs.main_branch }}_-_cd_-_${{ inputs.name }}
35-
dist_path: ${{ inputs.name }}/src
37+
# cd_path: ${{ inputs.name }}/ci
38+
# cd_branch: ${{ inputs.main_branch }}_-_cd_-_${{ inputs.name }}
39+
dist_path: ${{ inputs.upstream_dist_path }}
3640
dist_branch: ${{ inputs.main_branch }}_-_dist_-_${{ inputs.name }}
3741
sync:
3842
uses: ./.github/workflows/sync.yml
3943
secrets: inherit
40-
needs: [build]
44+
needs: [dist]
4145
with:
4246
target_sync_repo: ${{ inputs.repo_name }}
4347
target_sync_branch: ${{ inputs.main_branch }}

.github/workflows/validation.yml

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ on:
1212
main_branch: # 上游主分支
1313
required: true
1414
type: string
15-
cd_path: # (Github)持续交付路径, 不能以 / 结尾
16-
required: true
17-
type: string
18-
cd_branch: # 不能包含 / 等字符
19-
required: true
20-
type: string
15+
# cd_path: # (Github)持续交付路径, 不能以 / 结尾
16+
# required: true
17+
# type: string
18+
# cd_branch: # 不能包含 / 等字符
19+
# required: true
20+
# type: string
2121
dist_path: # 分发路径, 不能以 / 结尾
2222
required: true
2323
type: string
@@ -52,17 +52,17 @@ jobs:
5252
echo "branch_exists=false" >> $GITHUB_OUTPUT
5353
echo "Remote branch ${{ inputs.dist_branch }} does not exist."
5454
fi
55-
- name: Check if cd_branch exists in the remote
56-
id: cd_branch-exists
57-
run: |
58-
# grep -qE 使用了 -E 参数来启用扩展的正则表达式, 并且使用了 $ 符号来确保匹配的字符串以 main 结尾, 达到精准匹配的目的
59-
if git ls-remote --heads origin | grep -qE 'refs/heads/${{ inputs.cd_branch }}$'; then
60-
echo "branch_exists=true" >> $GITHUB_OUTPUT
61-
echo "Remote branch ${{ inputs.cd_branch }} exists."
62-
else
63-
echo "branch_exists=false" >> $GITHUB_OUTPUT
64-
echo "Remote branch ${{ inputs.cd_branch }} does not exist."
65-
fi
55+
# - name: Check if cd_branch exists in the remote
56+
# id: cd_branch-exists
57+
# run: |
58+
# # grep -qE 使用了 -E 参数来启用扩展的正则表达式, 并且使用了 $ 符号来确保匹配的字符串以 main 结尾, 达到精准匹配的目的
59+
# if git ls-remote --heads origin | grep -qE 'refs/heads/${{ inputs.cd_branch }}$'; then
60+
# echo "branch_exists=true" >> $GITHUB_OUTPUT
61+
# echo "Remote branch ${{ inputs.cd_branch }} exists."
62+
# else
63+
# echo "branch_exists=false" >> $GITHUB_OUTPUT
64+
# echo "Remote branch ${{ inputs.cd_branch }} does not exist."
65+
# fi
6666
- name: Sync dist_path from main_branch to exists dist_branch
6767
if: steps.dist_branch-exists.outputs.branch_exists == 'true'
6868
run: |
@@ -84,27 +84,27 @@ jobs:
8484
git commit -m "🪂 Sync ${{ inputs.dist_path }} from ${{ inputs.main_branch }} to ${{ inputs.dist_branch }}" || echo "No changes to commit"
8585
# 删除临时分支
8686
git branch -D temp_${{ inputs.main_branch }}
87-
- name: Sync cd_path from main_branch to exists cd_branch
88-
if: steps.cd_branch-exists.outputs.branch_exists == 'true'
89-
run: |
90-
# 主分支需要重复使用, 因此基于临时分支操作
91-
git checkout -b temp_${{ inputs.main_branch }} ${{ inputs.main_branch }}
92-
# 创建临时文件夹,如果它不存在的话
93-
mkdir -p $HOME/tmp
94-
# 清空临时文件夹的内容
95-
find $HOME/tmp/ -mindepth 1 -maxdepth 1 -exec rm -rf {} +
96-
ls -A $HOME/tmp/
97-
rsync -a --exclude '.git' ${{ inputs.cd_path }}/ $HOME/tmp/
98-
ls -A $HOME/tmp/
99-
git checkout ${{ inputs.cd_branch }}
100-
# 清空所有文件,除了.git目录
101-
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
102-
rsync -a --exclude '.git' $HOME/tmp/ ./
103-
find . -path './.git' -prune -o -exec ls -lR {} +
104-
git add .
105-
git commit -m "🪂 Sync ${{ inputs.cd_path }} from ${{ inputs.main_branch }} to ${{ inputs.cd_branch }}" || echo "No changes to commit"
106-
# 删除临时分支
107-
git branch -D temp_${{ inputs.main_branch }}
87+
# - name: Sync cd_path from main_branch to exists cd_branch
88+
# if: steps.cd_branch-exists.outputs.branch_exists == 'true'
89+
# run: |
90+
# # 主分支需要重复使用, 因此基于临时分支操作
91+
# git checkout -b temp_${{ inputs.main_branch }} ${{ inputs.main_branch }}
92+
# # 创建临时文件夹,如果它不存在的话
93+
# mkdir -p $HOME/tmp
94+
# # 清空临时文件夹的内容
95+
# find $HOME/tmp/ -mindepth 1 -maxdepth 1 -exec rm -rf {} +
96+
# ls -A $HOME/tmp/
97+
# rsync -a --exclude '.git' ${{ inputs.cd_path }}/ $HOME/tmp/
98+
# ls -A $HOME/tmp/
99+
# git checkout ${{ inputs.cd_branch }}
100+
# # 清空所有文件,除了.git目录
101+
# find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
102+
# rsync -a --exclude '.git' $HOME/tmp/ ./
103+
# find . -path './.git' -prune -o -exec ls -lR {} +
104+
# git add .
105+
# git commit -m "🪂 Sync ${{ inputs.cd_path }} from ${{ inputs.main_branch }} to ${{ inputs.cd_branch }}" || echo "No changes to commit"
106+
# # 删除临时分支
107+
# git branch -D temp_${{ inputs.main_branch }}
108108
- name: Init dist_branch from dist_path at main_branch
109109
if: steps.dist_branch-exists.outputs.branch_exists == 'false'
110110
run: |
@@ -124,25 +124,25 @@ jobs:
124124
git commit -m "🪂 Initial ${{ inputs.dist_path }} from ${{ inputs.main_branch }} to ${{ inputs.dist_branch }}"
125125
# 删除临时分支
126126
git branch -D temp_${{ inputs.main_branch }}
127-
- name: Init cd_branch from cd_path at main_branch
128-
if: steps.cd_branch-exists.outputs.branch_exists == 'false'
129-
run: |
130-
# 主分支需要重复使用, 因此基于临时分支操作
131-
git checkout -b temp_${{ inputs.main_branch }} ${{ inputs.main_branch }}
132-
# 创建临时文件夹,如果它不存在的话
133-
mkdir -p $HOME/tmp
134-
# 清空临时文件夹的内容
135-
find $HOME/tmp/ -mindepth 1 -maxdepth 1 -exec rm -rf {} +
136-
rsync -a --exclude '.git' ${{ inputs.cd_path }}/ $HOME/tmp/
137-
# 清空所有文件,除了.git目录
138-
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
139-
# 创建一个全新的分支, 不基于任何现有的提交
140-
git checkout --orphan ${{ inputs.cd_branch }}
141-
rsync -a --exclude '.git' $HOME/tmp/ ./
142-
git add .
143-
git commit -m "🪂 Initial ${{ inputs.cd_path }} from ${{ inputs.main_branch }} to ${{ inputs.cd_branch }}"
144-
# 删除临时分支
145-
git branch -D temp_${{ inputs.main_branch }}
127+
# - name: Init cd_branch from cd_path at main_branch
128+
# if: steps.cd_branch-exists.outputs.branch_exists == 'false'
129+
# run: |
130+
# # 主分支需要重复使用, 因此基于临时分支操作
131+
# git checkout -b temp_${{ inputs.main_branch }} ${{ inputs.main_branch }}
132+
# # 创建临时文件夹,如果它不存在的话
133+
# mkdir -p $HOME/tmp
134+
# # 清空临时文件夹的内容
135+
# find $HOME/tmp/ -mindepth 1 -maxdepth 1 -exec rm -rf {} +
136+
# rsync -a --exclude '.git' ${{ inputs.cd_path }}/ $HOME/tmp/
137+
# # 清空所有文件,除了.git目录
138+
# find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
139+
# # 创建一个全新的分支, 不基于任何现有的提交
140+
# git checkout --orphan ${{ inputs.cd_branch }}
141+
# rsync -a --exclude '.git' $HOME/tmp/ ./
142+
# git add .
143+
# git commit -m "🪂 Initial ${{ inputs.cd_path }} from ${{ inputs.main_branch }} to ${{ inputs.cd_branch }}"
144+
# # 删除临时分支
145+
# git branch -D temp_${{ inputs.main_branch }}
146146
- run: |
147147
git checkout ${{ inputs.dist_branch }}
148148
- name: Push dist_branch
@@ -155,15 +155,15 @@ jobs:
155155
# force_with_lease: true # 仅在远程分支自上次检出以来没有其他提交的情况下成功
156156
env:
157157
github_token: ${{ secrets.TOEKN_FOREVER_FULL_WRITE }} # 使用具有完全写入权限的 TOKEN(必须包含 workflows )
158-
- run: |
159-
git checkout ${{ inputs.cd_branch }}
160-
- name: Push cd_branch
161-
id: push_cd_branch
162-
uses: ad-m/github-push-action@master
163-
with:
164-
repository: ${{ inputs.repository }}
165-
branch: ${{ inputs.cd_branch }}
166-
force: true
167-
# force_with_lease: true # 仅在远程分支自上次检出以来没有其他提交的情况下成功
168-
env:
169-
github_token: ${{ secrets.TOEKN_FOREVER_FULL_WRITE }} # 使用具有完全写入权限的 TOKEN(必须包含 workflows )
158+
# - run: |
159+
# git checkout ${{ inputs.cd_branch }}
160+
# - name: Push cd_branch
161+
# id: push_cd_branch
162+
# uses: ad-m/github-push-action@master
163+
# with:
164+
# repository: ${{ inputs.repository }}
165+
# branch: ${{ inputs.cd_branch }}
166+
# force: true
167+
# # force_with_lease: true # 仅在远程分支自上次检出以来没有其他提交的情况下成功
168+
# env:
169+
# github_token: ${{ secrets.TOEKN_FOREVER_FULL_WRITE }} # 使用具有完全写入权限的 TOKEN(必须包含 workflows )

0 commit comments

Comments
 (0)