From c23cf8ef061fb1343abdf5f5ae36a5b115023a27 Mon Sep 17 00:00:00 2001 From: yusing Date: Thu, 26 Feb 2026 00:34:48 +0800 Subject: [PATCH] ci: refactor compat branch refresh to use patch-based approach --- .github/workflows/merge-main-into-compat.yml | 21 ++++------------ scripts/refresh-compat.sh | 26 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 16 deletions(-) create mode 100755 scripts/refresh-compat.sh diff --git a/.github/workflows/merge-main-into-compat.yml b/.github/workflows/merge-main-into-compat.yml index a9c4027f..aea068bc 100644 --- a/.github/workflows/merge-main-into-compat.yml +++ b/.github/workflows/merge-main-into-compat.yml @@ -1,4 +1,4 @@ -name: Cherry-pick into Compat +name: Refresh Compat from Main Patch on: push: @@ -8,7 +8,7 @@ on: - ".github/workflows/merge-main-into-compat.yml" jobs: - cherry-pick: + refresh-compat: runs-on: ubuntu-latest permissions: contents: write @@ -20,20 +20,9 @@ jobs: run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - - name: Cherry-pick commits from last tag + - name: Refresh compat with single patch commit run: | - git fetch origin compat - git checkout compat - CURRENT_TAG=${{ github.ref_name }} - PREV_TAG=$(git describe --tags --abbrev=0 $CURRENT_TAG^ 2>/dev/null || echo "") - - if [ -z "$PREV_TAG" ]; then - echo "No previous tag found. Cherry-picking all commits up to $CURRENT_TAG" - git rev-list --reverse --no-merges $CURRENT_TAG | xargs -r git cherry-pick - else - echo "Cherry-picking commits from $PREV_TAG to $CURRENT_TAG" - git rev-list --reverse --no-merges $PREV_TAG..$CURRENT_TAG | xargs -r git cherry-pick - fi + ./scripts/refresh-compat.sh - name: Push compat run: | - git push origin compat + git push origin compat --force diff --git a/scripts/refresh-compat.sh b/scripts/refresh-compat.sh new file mode 100755 index 00000000..5a47a3ff --- /dev/null +++ b/scripts/refresh-compat.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +git fetch origin main compat +git checkout -B compat origin/compat +patch_file="$(mktemp)" +git diff origin/main -- . ':(exclude)**/go.mod' ':(exclude)**/go.sum' >"$patch_file" +sed -i 's/sonic\./json\./g' "$patch_file" +sed -i 's/"github.com\/bytedance\/sonic"/"encoding\/json"/g' "$patch_file" +git checkout -B main origin/main +git branch -D compat +git checkout -b compat +git apply "$patch_file" +mapfile -t changed_go_files < <(git diff --name-only -- '*.go') +fmt_go_files=() +for file in "${changed_go_files[@]}"; do + [ -f "$file" ] || continue + sed -E -i 's/\bsonic[[:space:]]+"encoding\/json"/json "encoding\/json"/g' "$file" + fmt_go_files+=("$file") +done +if [ "${#fmt_go_files[@]}" -gt 0 ]; then + gofmt -w "${fmt_go_files[@]}" +fi +git add -A +git commit -m "Apply compat patch" +go vet ./... +go vet -C agent ./...