mirror of
https://github.com/Finesssee/ProxyPilot.git
synced 2026-11-18 18:04:20 +00:00
173 lines
6.0 KiB
YAML
173 lines
6.0 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 tracked upstream version
|
|
id: current
|
|
run: |
|
|
CURRENT_TAG=$(tr -d '[:space:]' < UPSTREAM_VERSION 2>/dev/null || true)
|
|
CURRENT_SHA=""
|
|
if [ -n "$CURRENT_TAG" ]; then
|
|
CURRENT_SHA=$(git ls-remote https://github.com/router-for-me/CLIProxyAPI.git "refs/tags/$CURRENT_TAG" | cut -f1)
|
|
fi
|
|
echo "tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
|
|
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 tracked tag: ${{ steps.current.outputs.tag }}"
|
|
echo "Current SHA: ${{ steps.current.outputs.sha }}"
|
|
echo "Upstream SHA: ${{ steps.upstream.outputs.sha }}"
|
|
echo "Upstream Tag: ${{ steps.upstream.outputs.tag }}"
|
|
|
|
if [ -z "${{ steps.upstream.outputs.tag }}" ]; then
|
|
echo "Unable to determine latest upstream release tag"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "${{ steps.current.outputs.tag }}" != "${{ steps.upstream.outputs.tag }}" ]; 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: |
|
|
CURRENT_TAG="${{ steps.current.outputs.tag }}"
|
|
TAG="${{ steps.upstream.outputs.tag }}"
|
|
SHA="${{ steps.upstream.outputs.sha }}"
|
|
SHORT_SHA="${SHA:0:7}"
|
|
|
|
if [ -n "$CURRENT_TAG" ]; then
|
|
BRANCH_NAME="sync-upstream-$CURRENT_TAG-to-$TAG"
|
|
PR_TITLE="chore: sync CLIProxyAPI $CURRENT_TAG-$TAG"
|
|
PR_BODY="## Summary
|
|
|
|
ProxyPilot is currently tracking upstream CLIProxyAPI release \`$CURRENT_TAG\` and a newer release \`$TAG\` is available.
|
|
|
|
**Upstream release:** https://github.com/router-for-me/CLIProxyAPI/releases/tag/$TAG
|
|
|
|
## Tracking
|
|
|
|
- Current tracked upstream version: \`$CURRENT_TAG\`
|
|
- Latest upstream version: \`$TAG\`
|
|
- Latest upstream commit: \`$SHORT_SHA\`
|
|
|
|
## Checklist
|
|
|
|
- [ ] Merge upstream changes into ProxyPilot
|
|
- [ ] Review upstream changes
|
|
- [ ] Test locally before merging
|
|
- [ ] Update \`UPSTREAM_VERSION\`, docs, and release notes
|
|
- [ ] Cut a new ProxyPilot release tag
|
|
|
|
---
|
|
🤖 Generated by [check-upstream workflow](https://github.com/${{ github.repository }}/actions/workflows/check-upstream.yml)"
|
|
else
|
|
BRANCH_NAME="sync-upstream-$SHORT_SHA"
|
|
PR_TITLE="chore: sync CLIProxyAPI $TAG"
|
|
PR_BODY="## Summary
|
|
|
|
ProxyPilot does not have a tracked upstream version in \`UPSTREAM_VERSION\`, and upstream CLIProxyAPI release \`$TAG\` is available.
|
|
|
|
**Upstream release:** https://github.com/router-for-me/CLIProxyAPI/releases/tag/$TAG
|
|
|
|
## Checklist
|
|
|
|
- [ ] Set the correct tracked upstream version
|
|
- [ ] Merge upstream changes into ProxyPilot
|
|
- [ ] 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 marker files so the PR records which upstream release triggered it.
|
|
echo "$SHA" > .upstream-sync-sha
|
|
echo "$TAG" > .upstream-sync-tag
|
|
|
|
# Commit
|
|
git add .upstream-sync-sha .upstream-sync-tag
|
|
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"
|