-
Notifications
You must be signed in to change notification settings - Fork 21
61 lines (56 loc) · 2.97 KB
/
Copy pathsync-gitcode.yml
File metadata and controls
61 lines (56 loc) · 2.97 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name: Sync Code & Releases to GitCode
# 定时把 GitHub 主仓库镜像到 GitCode(面向访问不了 GitHub 的用户):
# - 代码:全部分支与 tag(push --prune 保证 GitCode 侧 refs 与 GitHub 完全一致,GitCode 上不要直接改代码)
# - Release 资产:把 GitHub 上的 Release APK 同步到 GitCode Release(幂等,默认保留最新 3 个正式版,不含 RC)
# 每天 1 次自动执行(schedule,UTC 03:17),也可在 Actions 页面手动触发(workflow_dispatch)。
# 前置配置:GitHub Secret GITCODE_TOKEN = GitCode 个人访问令牌(需仓库读写 + API 权限)
# 用户名固定用 oauth2,令牌即密码(已实测 GitCode 支持该认证方式)。
on:
schedule:
- cron: '17 3 * * *'
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# 需要全部分支和 tag,浅克隆(默认 depth=1)无法覆盖
fetch-depth: 0
- name: Push branches & tags to GitCode
env:
GITCODE_TOKEN: ${{ secrets.GITCODE_TOKEN }}
GITCODE_OWNER: ${{ vars.GITCODE_OWNER }}
GITCODE_REPO: ${{ vars.GITCODE_REPO }}
run: |
set -euo pipefail
if [[ -z "$GITCODE_TOKEN" ]]; then
echo "::warning::未配置 GITCODE_TOKEN,跳过 GitCode 代码同步。请到 Settings→Secrets and variables→Actions 添加。"
exit 0
fi
owner="${GITCODE_OWNER:-${GITHUB_REPOSITORY%/*}}"
repo="${GITCODE_REPO:-${GITHUB_REPOSITORY#*/}}"
echo "目标 GitCode 仓库: ${owner}/${repo}"
git remote add gitcode "https://oauth2:${GITCODE_TOKEN}@gitcode.com/${owner}/${repo}.git"
git push --prune gitcode \
"+refs/heads/*:refs/heads/*" \
"+refs/tags/*:refs/tags/*"
echo "✓ 代码与 tag 已同步到 https://gitcode.com/${owner}/${repo}"
# Release APK 同步:从 GitHub Release 下载资产并补齐到 GitCode Release(幂等,
# 已同步的跳过、失败可重跑续传)。GitCode 无公开附件配额限制且删除 Release 只能
# 删 tag(连带删除,副作用大),故不做自动清理,只增量补齐缺失附件。
- name: Sync Release assets to GitCode
env:
GITCODE_TOKEN: ${{ secrets.GITCODE_TOKEN }}
GH_REPO: ${{ github.repository }}
GITCODE_OWNER: ${{ vars.GITCODE_OWNER }}
GITCODE_REPO: ${{ vars.GITCODE_REPO }}
run: |
set -euo pipefail
if [[ -z "$GITCODE_TOKEN" ]]; then
echo "::warning::未配置 GITCODE_TOKEN,跳过 GitCode Release 同步。请到 Settings→Secrets and variables→Actions 添加。"
exit 0
fi
python3 scripts/sync-gitcode-releases.py
echo "✓ Release 资产已同步到 https://gitcode.com/${GITCODE_OWNER:-${GITHUB_REPOSITORY%/*}}/${GITCODE_REPO:-${GITHUB_REPOSITORY#*/}}/releases"