72 lines
1.9 KiB
YAML
72 lines
1.9 KiB
YAML
|
|
name: Sync GitHub dev to Gitea
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- 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:
|
|
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."
|