From 8c7bf977baa3289e891a793ca140c013b30bdea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=95=86=E9=99=B6?= Date: Sat, 21 Mar 2026 00:48:04 +0800 Subject: [PATCH 1/3] feat: add force replace logic for upstream sync - Detect existing tags with different commits - Delete old GitHub Release before force push - Use --force flag for tag replacement - Support syncing tags with fork-specific changes --- .github/workflows/main-post-merge.yml | 28 +++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main-post-merge.yml b/.github/workflows/main-post-merge.yml index 118b5afcf4..416d338a5c 100644 --- a/.github/workflows/main-post-merge.yml +++ b/.github/workflows/main-post-merge.yml @@ -108,7 +108,7 @@ jobs: echo "Fork latest version: $FORK_VERSION" - # 收集高于当前版本的上游 tag + # 收集需要同步的 tag(包括需要强制替换的) TAGS=() while read -r tag; do [ -z "$tag" ] && continue @@ -118,7 +118,15 @@ jobs: if [ "$(printf '%s\n' "$FORK_VERSION" "$TAG_VERSION" | sort -V | tail -1)" = "$TAG_VERSION" ] && [ "$TAG_VERSION" != "$FORK_VERSION" ]; then TAG_COMMIT="$(git rev-list -n 1 "$tag")" if git merge-base --is-ancestor "$TAG_COMMIT" HEAD; then - if ! git ls-remote --tags origin "refs/tags/$tag" | grep -q .; then + # 检查 fork 是否已有此 tag + if git ls-remote --tags origin "refs/tags/$tag" | grep -q .; then + # 比较 commit,如果不同则需要强制替换 + FORK_TAG_COMMIT="$(git ls-remote --tags origin "refs/tags/$tag" | awk '{print $1}')" + if [ "$TAG_COMMIT" != "$FORK_TAG_COMMIT" ]; then + TAGS+=("$tag") + echo "Found tag with changes: $tag (will force replace)" + fi + else TAGS+=("$tag") echo "Found new tag: $tag (newer than $FORK_VERSION)" fi @@ -153,11 +161,23 @@ jobs: for tag in ${{ steps.upstream_tag.outputs.all_tags }}; do echo "=== Processing tag: $tag ===" + # 检查 fork 是否已有此 tag + if git ls-remote --tags origin "refs/tags/$tag" | grep -q .; then + echo "Tag exists in fork, will force replace" + + # 删除旧的 GitHub Release(如果存在) + if gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then + echo "Deleting existing release: $tag" + gh release delete "$tag" --repo "$GITHUB_REPOSITORY" --yes + fi + fi + + # 重新创建 tag 并强制推送 MSG_FILE="$(mktemp)" git for-each-ref "refs/tags/$tag" --format='%(contents)' > "$MSG_FILE" 2>/dev/null || echo "$tag" > "$MSG_FILE" - git tag -d "$tag" + git tag -d "$tag" 2>/dev/null || true git tag -a "$tag" -F "$MSG_FILE" HEAD - git push origin "refs/tags/$tag" + git push --force origin "refs/tags/$tag" echo "Waiting for release workflow to start..." sleep 60 From 81610662351473438ac30cb2ebc848a750fff4a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=95=86=E9=99=B6?= Date: Sat, 21 Mar 2026 00:56:04 +0800 Subject: [PATCH 2/3] feat: add auto-merge workflow for feature branches --- .../workflows/auto-merge-feature-branches.yml | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/auto-merge-feature-branches.yml diff --git a/.github/workflows/auto-merge-feature-branches.yml b/.github/workflows/auto-merge-feature-branches.yml new file mode 100644 index 0000000000..722242eec6 --- /dev/null +++ b/.github/workflows/auto-merge-feature-branches.yml @@ -0,0 +1,73 @@ +name: Auto-merge Feature Branches + +on: + push: + branches: + - 'feat/**' + - 'fix/**' + +concurrency: + group: auto-merge-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: write + pull-requests: write + +jobs: + auto-merge: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.PAT_TOKEN }} + + - name: Configure Git + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Check for merge conflicts + id: conflict_check + run: | + git fetch origin main + if ! git merge-tree $(git merge-base HEAD origin/main) HEAD origin/main | grep -q "^changed in both"; then + echo "has_conflict=false" >> $GITHUB_OUTPUT + else + echo "has_conflict=true" >> $GITHUB_OUTPUT + fi + + - name: Create conflict issue + if: steps.conflict_check.outputs.has_conflict == 'true' + env: + GH_TOKEN: ${{ secrets.PAT_TOKEN }} + run: | + gh issue create \ + --title "Merge conflict in ${{ github.ref_name }}" \ + --body "Branch ${{ github.ref_name }} has conflicts with main. Please resolve manually." + exit 1 + + - name: Create or update PR + env: + GH_TOKEN: ${{ secrets.PAT_TOKEN }} + run: | + BRANCH="${{ github.ref_name }}" + if gh pr list --head "$BRANCH" --base main --json number --jq '.[0].number' | grep -q .; then + echo "PR already exists, updating..." + else + gh pr create \ + --base main \ + --head "$BRANCH" \ + --title "Auto-merge: $BRANCH" \ + --body "Automated PR from $BRANCH to main" + fi + + - name: Enable auto-merge + env: + GH_TOKEN: ${{ secrets.PAT_TOKEN }} + run: | + BRANCH="${{ github.ref_name }}" + PR_NUMBER=$(gh pr list --head "$BRANCH" --base main --json number --jq '.[0].number') + gh pr merge "$PR_NUMBER" --auto --merge From 1c3ea3717aeff1040fbcbda60434c00a9072e9e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=95=86=E9=99=B6?= Date: Sat, 21 Mar 2026 01:07:08 +0800 Subject: [PATCH 3/3] ci: remove integration tests from CI --- .github/workflows/backend-ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/backend-ci.yml b/.github/workflows/backend-ci.yml index fe882ccf9f..841b24fa50 100644 --- a/.github/workflows/backend-ci.yml +++ b/.github/workflows/backend-ci.yml @@ -30,9 +30,6 @@ jobs: - name: Unit tests working-directory: backend run: make test-unit - - name: Integration tests - working-directory: backend - run: make test-integration backend-golangci-lint: name: backend-golangci-lint