Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/auto-merge-feature-branches.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 24 additions & 4 deletions .github/workflows/main-post-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:

echo "Fork latest version: $FORK_VERSION"

# 收集高于当前版本的上游 tag
# 收集需要同步的 tag(包括需要强制替换的)
TAGS=()
while read -r tag; do
[ -z "$tag" ] && continue
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading