mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-23 17:41:05 +01:00
ci: refactor compat branch refresh to use patch-based approach
This commit is contained in:
21
.github/workflows/merge-main-into-compat.yml
vendored
21
.github/workflows/merge-main-into-compat.yml
vendored
@@ -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
|
||||
|
||||
26
scripts/refresh-compat.sh
Executable file
26
scripts/refresh-compat.sh
Executable file
@@ -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 ./...
|
||||
Reference in New Issue
Block a user