github自动同步上游仓库
# 前言
前段时间在linux do
社区,看佬友项目LibreTV - 免费在线视频搜索与观看平台 (opens new window),有意思,cloudflare搭一个玩玩
最近推给同学使用的过程,发现里面的一些资源节点不能用了(黑木耳等等),我想是不是作者有没有更新,去更新一下。最近刷linux do
竟然又刷到作者了,刚好更新一下。
# 过程
本来想着删库重新fork的(x),想了想大佬们一定有更优雅的姿势,学习一下
# 被动同步:网页点击同步按钮
这里有种简单的被动更新同步姿势,在自己fork的库下,有同步上游仓库的按钮,点击就可以同步了
# 主动同步:github action定时任务
第一次接触Github fork同步功能,迫不及待的跟issue区的其他佬友分享(x)
因为我的博客是之前参考大佬主题的自动部署方案,接触过github action,所以简单提了一嘴。作者在项目仓库里竟然已经写好了github workflow的文件,让ai解释一下,直接使用就可以了。
name: Upstream Sync
permissions:
contents: write
on:
schedule:
- cron: "0 4 * * *" # At 04:00, every day
workflow_dispatch:
jobs:
sync_latest_from_upstream:
name: Sync latest commits from upstream repo
runs-on: ubuntu-latest
if: ${{ github.event.repository.fork }}
steps:
# Step 1: run a standard checkout action
- name: Checkout target repo
uses: actions/checkout@v3
# Step 2: run the sync action
- name: Sync upstream changes
id: sync
uses: aormsby/Fork-Sync-With-Upstream-action@v3.4
with:
upstream_sync_repo: LibreSpark/LibreTV
upstream_sync_branch: main
target_sync_branch: main
target_repo_token: ${{ secrets.GITHUB_TOKEN }} # automatically generated, no need to set
# Set test_mode true to run tests instead of the true action!!
test_mode: false
- name: Sync check
if: failure()
run: |
echo "[Error] Due to a change in the workflow file of the upstream repository, GitHub has automatically suspended the scheduled automatic update. You need to manually sync your fork."
exit 1
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
36
37
38
39
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
36
37
38
39
解释:
- name: 同步上游提交
- if: 判断只有仓库是fork的情况下才执行
- upstream_sync_repo: 指定上游仓库是 LibreSpark/LibreTV;
- upstream_sync_branch: 上游的 main 分支
- target_sync_branch: fork的 main 分支;
- target_repo_token: 用默认的 GITHUB_TOKEN 来做身份认证;
- test_mode: false: 设置为 false 表示这是正式同步,不是测试。
启用github action
找到项目的action,启用
找到左侧上游同步,找到enable workflow
,启用
手动运行一次workflow,看看是否成功
查看运行细节,成功同步。因为我已经网页手动同步了,这里就没有新的更新需要同步了,所以没有更新。
后续
接下来,这个github action会每天定时运行,自动同步上游仓库的更新。
on:
schedule:
- cron: "0 4 * * *"
1
2
3
2
3
定时任务会在每天中午12 (UTC 4 + 8)点定时同步一次,不再需要手动同步
编辑 (opens new window)
最后一次更新于: 2025/04/24, 20:50:12