Skip to content

Commit 7436caf

Browse files
committed
ci: refactor workflow files to use external reusable workflows
- Replace publish-release.yml and sync.yml with references to external repository reusable workflows - Simplify configuration by removing duplicate steps and permission declarations - Use inherit to inherit organization-level secret configuration
1 parent d6952f0 commit 7436caf

1 file changed

Lines changed: 18 additions & 47 deletions

File tree

.github/workflows/sync.yml

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,28 @@
1-
name: Sync Github To Image
1+
name: Sync Github To Image (External)
22

33
on:
44
push:
5-
branches: [main]
5+
branches:
6+
- '**'
7+
tags-ignore:
8+
- '**'
9+
workflow_run:
10+
workflows: ["Publish Release"] # 监听的工作流名称
11+
types:
12+
- completed # 监听完成事件
613
#schedule:
714
# 定时任务,每天 UTC 时间 0 点运行
815
#- cron: "0 0 * * *"
916
workflow_dispatch:
1017

11-
1218
jobs:
1319
sync-gitee:
14-
runs-on: ubuntu-latest
15-
16-
steps:
17-
- name: Checkout code
18-
uses: actions/checkout@v4
19-
with:
20-
fetch-depth: 0 # 为了 git pull --unshallow,我们需要获取所有的提交历史
21-
22-
- name: Set up Git user
23-
run: |
24-
git config --global user.email "wangfj11@foxmail.com"
25-
git config --global user.name "AlianBlank"
26-
27-
- name: Set SSH
28-
run: |
29-
mkdir -p ~/.ssh
30-
echo "${{ secrets.GITEE_ID_RSA }}" >> ~/.ssh/id_rsa
31-
chmod 600 ~/.ssh/id_rsa
32-
eval $(ssh-agent -s) && ssh-add ~/.ssh/id_rsa
33-
# 信任域名
34-
ssh-keyscan -H gitee.com >> ~/.ssh/known_hosts
35-
# 查看当前分支
36-
- name: Check current branch
37-
run: echo 当前分支:${{ github.ref_name }} ${{ github.Repository }}
38-
# 查看远端 地址
39-
- name: echo git url
40-
run: echo git@gitee.com:${{ github.Repository }}.git
41-
42-
# 添加远端
43-
- name: add remote url
44-
run: git remote add mirror "git@gitee.com:${{ github.Repository }}.git"
45-
46-
# 获取
47-
- name: fetch
48-
run: git fetch --prune mirror --tags --verbose
49-
50-
# 拉取和推送
51-
- name: pull and push
52-
run: |
53-
if [ "${{ github.ref_name }}" ]; then
54-
git checkout ${{ github.ref_name }}
55-
git push -f mirror ${{ github.ref_name }}
56-
git push -f mirror --tags --verbose
57-
fi
20+
# 引用外部仓库的可重用工作流
21+
# 格式: {owner}/{repo}/.github/workflows/{filename}@{ref}
22+
uses: GameFrameX/public-github-actions/.github/workflows/sync.yml@main
23+
with:
24+
# 传递参数给外部工作流
25+
target_branch: ${{ github.ref_name }}
26+
repository_name: ${{ github.repository }}
27+
# 组织级别已配置密钥,可以使用 inherit 继承所有密钥
28+
secrets: inherit

0 commit comments

Comments
 (0)