codex-proxy / .github /workflows /sync-electron.yml
icebear0828
fix: review improvements — schema walker, status helper, UI i18n, CI version skip
6220911
raw
history blame
4.76 kB
name: Sync master electron
on:
push:
branches: [master]
workflow_dispatch:
concurrency:
group: sync-electron
cancel-in-progress: false
permissions:
actions: write
contents: write
issues: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Merge master into electron
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout electron
git merge origin/master --no-edit || {
# Conflict — abort and create issue
git merge --abort
echo "CONFLICT=true" >> "$GITHUB_ENV"
}
- name: Auto bump + tag if new commits
if: env.CONFLICT != 'true'
run: |
# Find last version tag
LAST_TAG=$(git describe --tags --abbrev=0 --match "v*" 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
echo "No previous tag found, skipping auto-bump"
echo "BUMP=false" >> "$GITHUB_ENV"
exit 0
fi
# Check for new non-merge commits since last tag
NEW_COMMITS=$(git log "${LAST_TAG}..HEAD" --no-merges --oneline | wc -l)
if [ "$NEW_COMMITS" -eq 0 ]; then
echo "No new non-merge commits since $LAST_TAG, skipping bump"
echo "BUMP=false" >> "$GITHUB_ENV"
exit 0
fi
echo "Found $NEW_COMMITS new commit(s) since $LAST_TAG"
# Parse current version and bump patch
CURRENT="${LAST_TAG#v}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
NEW_TAG="v${NEW_VERSION}"
# Check tag doesn't already exist (concurrent protection)
if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then
echo "Tag $NEW_TAG already exists, skipping"
echo "BUMP=false" >> "$GITHUB_ENV"
exit 0
fi
# Bump version in package.json
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
pkg.version = '${NEW_VERSION}';
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
git add package.json
git commit -m "chore: bump version to ${NEW_VERSION}"
git tag -a "$NEW_TAG" -m "Release ${NEW_TAG}"
echo "BUMP=true" >> "$GITHUB_ENV"
echo "NEW_TAG=$NEW_TAG" >> "$GITHUB_ENV"
echo "NEW_VERSION=$NEW_VERSION" >> "$GITHUB_ENV"
echo "Bumped to $NEW_VERSION, tagged $NEW_TAG"
- name: Sync version to master
if: env.BUMP == 'true'
run: |
git checkout master
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
pkg.version = process.env.NEW_VERSION;
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
git add package.json
git commit -m "chore: sync version to ${NEW_VERSION} [skip ci]"
git checkout electron
- name: Push electron + master + tags
if: env.CONFLICT != 'true'
run: |
if [ "$BUMP" = "true" ]; then
git push origin electron master --follow-tags
else
git push origin electron
fi
- name: Trigger release workflow
if: env.BUMP == 'true'
run: gh workflow run release.yml -f tag="$NEW_TAG" --ref electron
env:
GH_TOKEN: ${{ github.token }}
- name: Create issue on conflict
if: env.CONFLICT == 'true'
run: |
# Check for existing open issue to avoid duplicates
EXISTING=$(gh issue list --label "sync-conflict" --state open --limit 1 --json number -q '.[0].number')
if [ -n "$EXISTING" ]; then
echo "Issue #$EXISTING already open, skipping"
exit 0
fi
gh issue create \
--title "electron 分支合并冲突需手动解决" \
--label "sync-conflict" \
--body "$(cat <<'EOF'
\`master\` → \`electron\` 自动合并失败,需要手动解决冲突。
```bash
git checkout electron
git merge master
# 解决冲突(通常是 CHANGELOG.md)
git add .
git commit
git push origin electron
```
触发 commit: ${{ github.sha }}
EOF
)"
env:
GH_TOKEN: ${{ github.token }}