Files
iotlcm/.gitea/workflows/cleanup-old-gitee-repos.yml
T
2026-11-02 14:22:00 +08:00

59 lines
2.2 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: cleanup-old-gitee-repos
# 一次性任务:删除 Gitee 企业仓下 12 个已并入单仓的旧仓。
# 结果写入 report.txt 并作为 artifact 上传(Gitea 日志无读取 API,只能靠 artifact 回报)。
on:
workflow_dispatch:
jobs:
cleanup:
runs-on: host
steps:
- name: 删除旧仓并生成报告
env:
DST_TOKEN: ${{ secrets.GITEE_TOKEN }}
DST_OWNER: ${{ secrets.GITEE_OWNER }}
run: |
set -u
REPORT="$PWD/report.txt"
: > "$REPORT"
log() { echo "$@" | tee -a "$REPORT"; }
REPOS="iotlcm-admin-svr iotlcm-admin-ui iotlcm-app iotlcm-bot iotlcm-deploy iotlcm-docs iotlcm-onelink-mock iotlcm-openapi iotlcm-sms iotlcm-upstream-chan iotlcm-upstream-proxy iotlcm-worker-svr"
log "=== 1. 删除(DELETE /repos/{owner}/{repo})==="
for r in $REPOS; do
if [ "$r" = "iotlcm" ]; then log "❌ 拒绝删除单仓"; exit 1; fi
code=$(curl -sS -o /tmp/b -w '%{http_code}' -X DELETE \
"https://gitee.com/api/v5/repos/${DST_OWNER}/${r}?access_token=${DST_TOKEN}")
log "DELETE ${r} -> $code $(head -c 120 /tmp/b)"
done
log ""
log "=== 2. 复核(期望 404)==="
for r in $REPOS; do
code=$(curl -sS -o /tmp/b -w '%{http_code}' \
"https://gitee.com/api/v5/repos/${DST_OWNER}/${r}?access_token=${DST_TOKEN}")
log "GET ${r} -> $code"
done
log ""
log "=== 3. 单仓仍须 200 ==="
code=$(curl -sS -o /tmp/b -w '%{http_code}' \
"https://gitee.com/api/v5/repos/${DST_OWNER}/iotlcm?access_token=${DST_TOKEN}")
log "GET iotlcm -> $code $(head -c 160 /tmp/b)"
log ""
log "=== 4. 企业仓列表(前 2000 字符)==="
curl -sS "https://gitee.com/api/v5/enterprises/${DST_OWNER}/repos?access_token=${DST_TOKEN}&per_page=100" \
| head -c 2000 | tee -a "$REPORT"
log ""
log "=== done ==="
- name: 上传报告
if: always()
uses: actions/upload-artifact@v3
with:
name: cleanup-report
path: report.txt