fix(ci): ACR cleanup改到Deploy之后运行,保护当前构建tag不被误删 #614
@@ -908,7 +908,7 @@ jobs:
|
||||
runs-on: runtime-builder
|
||||
timeout-minutes: 10
|
||||
needs:
|
||||
- build-staging
|
||||
- deploy-staging
|
||||
if: github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'develop')
|
||||
env:
|
||||
ACR_REGISTRY: xiaoxia-registry.cn-hangzhou.cr.aliyuncs.com
|
||||
@@ -928,6 +928,7 @@ jobs:
|
||||
env:
|
||||
ACR_USERNAME: ${{ secrets.ACR_USERNAME }}
|
||||
ACR_PASSWORD: ${{ secrets.ACR_PASSWORD }}
|
||||
PROTECTED_TAG: ${{ github.sha }}
|
||||
run: |
|
||||
set -eu
|
||||
python3 scripts/ci/acr_cleanup.py \
|
||||
|
||||
@@ -278,6 +278,15 @@ def cleanup_repo(repo, keep_count, pr_days, dry_run):
|
||||
valid_kept = [t for t in kept if t["created"]]
|
||||
if valid_kept:
|
||||
print(" 最早保留:", valid_kept[-1]["tag"][:12], "(" + valid_kept[-1]["created"][:10] + ")")
|
||||
# 保护当前构建的tag(通过PROTECTED_TAG环境变量传入,如GITHUB_SHA)
|
||||
protected_tag = os.environ.get("PROTECTED_TAG", "").strip()
|
||||
if protected_tag:
|
||||
before = len(to_delete)
|
||||
to_delete = [t for t in to_delete if not t["tag"].startswith(protected_tag)]
|
||||
removed = before - len(to_delete)
|
||||
if removed > 0:
|
||||
print(f" 保护当前构建tag: {protected_tag[:12]} (跳过{removed}个)")
|
||||
|
||||
to_del_valid = [t for t in to_delete if t["digest"]]
|
||||
print(" 可删除(有digest):", len(to_del_valid), "个")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user