Files
yidaconnector/.gitea/workflows/sync-releases.yml
T

75 lines
2.6 KiB
YAML

name: Daily Release Archive
on:
schedule:
- cron: "0 19 * * *" # 03:00 Asia/Shanghai
workflow_dispatch:
inputs:
dry_run:
description: 'Only inspect and report; do not write releases'
default: 'true'
required: true
tag:
description: 'Optional source tag; empty means all published releases'
default: ''
required: false
verify_all:
description: 'Full verification (also performed by default)'
default: 'true'
required: false
concurrency:
group: daily-release-archive
cancel-in-progress: false
permissions:
contents: write
jobs:
sync:
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- name: Fetch exact workflow revision from this Gitea
env:
TARGET_GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
WORKFLOW_SHA: ${{ github.sha }}
run: |
python3 - <<'PY'
import io, os, re, shutil, tarfile, tempfile, urllib.request
sha = os.environ['WORKFLOW_SHA']
assert re.fullmatch('[0-9a-f]{40}', sha)
url = 'https://git.jskdjs.cn/api/v1/repos/ruihan/yidaconnector/archive/' + sha + '.tar.gz'
req = urllib.request.Request(url, headers={'Authorization': 'token ' + os.environ['TARGET_GITEA_TOKEN']})
with urllib.request.urlopen(req, timeout=60) as r:
payload = r.read()
with tempfile.TemporaryDirectory() as d:
with tarfile.open(fileobj=io.BytesIO(payload), mode='r:gz') as t:
t.extractall(d, filter='data')
root = os.path.join(d, os.listdir(d)[0])
shutil.copytree(root, '.', dirs_exist_ok=True)
PY
- name: Test synchronization logic
run: python3 -m unittest discover -s tests -v
- name: Synchronize and verify releases
env:
SOURCE_GITEA_TOKEN: ${{ secrets.SOURCE_GITEA_TOKEN }}
TARGET_GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
ARCHIVE_ANCHOR_SHA: '92634afb073b81216388c9288cbf275ba1e11a2c'
SYNC_DRY_RUN: ${{ github.event.inputs.dry_run }}
SYNC_TAG: ${{ github.event.inputs.tag }}
run: |
set -eu
args=()
if [ "${SYNC_DRY_RUN:-false}" = "true" ]; then args+=(--dry-run); fi
if [ -n "${SYNC_TAG:-}" ]; then args+=(--tag "$SYNC_TAG"); fi
python3 scripts/sync_releases.py "${args[@]}"
- name: Save synchronization report
if: always()
uses: ./.gitea/actions/upload-artifact
with:
name: release-sync-report
path: sync-report.json
if-no-files-found: warn
retention-days: 90