Files
ProxyPilot/.github/workflows/check-upstream.yml
T
FinessseandClaude Opus 4.5 a8c389ffa6 ci: add upstream sync check workflow
Add GitHub Actions workflow to check for upstream
repository updates.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 05:11:17 +07:00

157 lines
5.1 KiB
YAML

name: check-upstream
on:
schedule:
# Run daily at 08:00 UTC (like vibeproxy)
- cron: '0 8 * * *'
workflow_dispatch: # Allow manual trigger
concurrency:
group: check-upstream
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
jobs:
check-update:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get current version
id: current
run: |
# Extract current CLIProxyAPI version from go.mod or a version file
# For now, we'll check the latest commit from upstream
CURRENT_SHA=$(git ls-remote https://github.com/router-for-me/CLIProxyAPI.git HEAD | cut -f1)
echo "sha=$CURRENT_SHA" >> $GITHUB_OUTPUT
- name: Get upstream release info
id: upstream
run: |
# Fetch latest release from CLIProxyAPI
RELEASE_INFO=$(curl -s https://api.github.com/repos/router-for-me/CLIProxyAPI/releases/latest)
# Extract tag name and version
TAG_NAME=$(echo "$RELEASE_INFO" | jq -r '.tag_name // empty')
if [ -z "$TAG_NAME" ]; then
echo "No release found, checking latest commit instead"
LATEST_SHA=$(git ls-remote https://github.com/router-for-me/CLIProxyAPI.git HEAD | cut -f1)
echo "tag=" >> $GITHUB_OUTPUT
echo "sha=$LATEST_SHA" >> $GITHUB_OUTPUT
else
echo "Found release: $TAG_NAME"
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
# Get the commit SHA for this tag
TAG_SHA=$(git ls-remote https://github.com/router-for-me/CLIProxyAPI.git "refs/tags/$TAG_NAME" | cut -f1)
echo "sha=$TAG_SHA" >> $GITHUB_OUTPUT
fi
- name: Check for updates
id: check
run: |
echo "Current SHA: ${{ steps.current.outputs.sha }}"
echo "Upstream SHA: ${{ steps.upstream.outputs.sha }}"
echo "Upstream Tag: ${{ steps.upstream.outputs.tag }}"
if [ "${{ steps.current.outputs.sha }}" != "${{ steps.upstream.outputs.sha }}" ]; then
echo "Update available!"
echo "has_update=true" >> $GITHUB_OUTPUT
else
echo "Already up to date"
echo "has_update=false" >> $GITHUB_OUTPUT
fi
- name: Create sync branch and PR
if: steps.check.outputs.has_update == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ steps.upstream.outputs.tag }}"
SHA="${{ steps.upstream.outputs.sha }}"
SHORT_SHA="${SHA:0:7}"
if [ -n "$TAG" ]; then
BRANCH_NAME="sync-upstream-$TAG"
PR_TITLE="feat: sync with CLIProxyAPI $TAG"
PR_BODY="## Summary
This PR syncs ProxyPilot with upstream CLIProxyAPI release \`$TAG\`.
**Upstream release:** https://github.com/router-for-me/CLIProxyAPI/releases/tag/$TAG
## Changes
- Updated to CLIProxyAPI $TAG ($SHORT_SHA)
## Checklist
- [ ] Review upstream changes
- [ ] Test locally before merging
- [ ] Update changelog if needed
---
🤖 Generated by [check-upstream workflow](https://github.com/${{ github.repository }}/actions/workflows/check-upstream.yml)"
else
BRANCH_NAME="sync-upstream-$SHORT_SHA"
PR_TITLE="feat: sync with CLIProxyAPI ($SHORT_SHA)"
PR_BODY="## Summary
This PR syncs ProxyPilot with latest upstream CLIProxyAPI commit.
**Upstream commit:** https://github.com/router-for-me/CLIProxyAPI/commit/$SHA
## Checklist
- [ ] Review upstream changes
- [ ] Test locally before merging
---
🤖 Generated by [check-upstream workflow](https://github.com/${{ github.repository }}/actions/workflows/check-upstream.yml)"
fi
# Check if branch already exists
if git ls-remote --exit-code --heads origin "$BRANCH_NAME" > /dev/null 2>&1; then
echo "Branch $BRANCH_NAME already exists, skipping"
exit 0
fi
# Check if PR already exists
EXISTING_PR=$(gh pr list --search "$PR_TITLE" --state open --json number --jq '.[0].number')
if [ -n "$EXISTING_PR" ]; then
echo "PR already exists: #$EXISTING_PR"
exit 0
fi
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create branch
git checkout -b "$BRANCH_NAME"
# Add a marker file to track the sync (optional, can be removed)
echo "$SHA" > .upstream-sync-sha
echo "$TAG" > .upstream-sync-tag 2>/dev/null || true
# Commit
git add -A
git commit -m "$PR_TITLE" --allow-empty
# Push
git push origin "$BRANCH_NAME"
# Create PR
gh pr create \
--title "$PR_TITLE" \
--body "$PR_BODY" \
--base main \
--head "$BRANCH_NAME" \
--label "sync-upstream"