From a5629f61195e214edf04bab26af8318fad0f06d2 Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Mon, 23 Nov 2026 17:09:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=E6=96=B9=E6=A1=88C=EF=BC=9As?= =?UTF-8?q?ync-to-gitea.yml=20=E6=81=A2=E5=A4=8D=E4=B8=BA=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E8=87=AA=E5=8C=85=E5=90=AB=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 不再依赖 ci-config 分支的可复用工作流 - 撤销对 ci-config 的调用入口,恢复原有 71 行实现 --- .github/workflows/sync-to-gitea.yml | 61 ++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/.github/workflows/sync-to-gitea.yml b/.github/workflows/sync-to-gitea.yml index 92be7802..4366471a 100644 --- a/.github/workflows/sync-to-gitea.yml +++ b/.github/workflows/sync-to-gitea.yml @@ -1,3 +1,4 @@ + name: Sync GitHub dev to Gitea on: @@ -6,15 +7,65 @@ on: - dev paths-ignore: - ".github/workflows/sync-to-gitea.yml" - workflow_dispatch: permissions: contents: read +concurrency: + group: github-to-gitea-dev + cancel-in-progress: false + jobs: sync: - uses: xiaowang2219/jayucloud/.github/workflows/reusable-sync-dev-to-gitea.yml@ci-config - secrets: - GITEA_USERNAME: ${{ secrets.GITEA_USERNAME }} - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + name: Push GitHub dev to Gitea dev + runs-on: ubuntu-latest + + steps: + - name: Checkout full history + uses: actions/checkout@v4 + with: + ref: dev + fetch-depth: 0 + + - name: Validate and push to Gitea + shell: bash + env: + GITEA_USERNAME: ${{ secrets.GITEA_USERNAME }} + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + GITHUB_SHA: ${{ github.sha }} + run: | + set -euo pipefail + + if [[ -z "$GITEA_USERNAME" || -z "$GITEA_TOKEN" ]]; then + echo "::error::Missing Gitea credentials." + exit 1 + fi + + AUTH="$(printf '%s' "$GITEA_USERNAME:$GITEA_TOKEN" | base64 -w 0)" + + git remote add gitea https://code.yunail.art/xiaowang/JayuCloud.git + + git -c http.extraheader="AUTHORIZATION: basic $AUTH" \ + fetch gitea refs/heads/dev:refs/remotes/gitea/dev + + GITEA_SHA="$(git rev-parse refs/remotes/gitea/dev)" + + echo "GitHub commit: $GITHUB_SHA" + echo "Gitea commit: $GITEA_SHA" + + if [[ "$GITEA_SHA" == "$GITHUB_SHA" ]]; then + echo "Both repositories are already synchronized." + exit 0 + fi + + if ! git merge-base --is-ancestor "$GITEA_SHA" "$GITHUB_SHA"; then + echo "::error::Gitea dev has diverged from or advanced beyond GitHub dev." + echo "::error::Refusing to overwrite Gitea." + exit 1 + fi + + git -c http.extraheader="AUTHORIZATION: basic $AUTH" \ + push gitea "$GITHUB_SHA:refs/heads/dev" + + echo "Successfully synchronized GitHub dev to Gitea dev."