Skip to content

Merge pull request #6 from leic4u/upstream-sync/20260430-0407 #16

Merge pull request #6 from leic4u/upstream-sync/20260430-0407

Merge pull request #6 from leic4u/upstream-sync/20260430-0407 #16

name: Sync Fork Release Tag
on:
push:
branches: [main]
schedule:
- cron: '47 * * * *'
workflow_dispatch:
permissions:
actions: write
contents: write
concurrency:
group: sync-release-tag
cancel-in-progress: false
jobs:
tag:
runs-on: ubuntu-latest
steps:
- name: Checkout fork
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git
run: |
git config user.name "ccs-upstream-sync[bot]"
git config user.email "ccs-upstream-sync@users.noreply.github.com"
- name: Fetch upstream tags
run: |
git remote add upstream https://github.com/router-for-me/CLIProxyAPI.git
git fetch upstream main --tags
- name: Create missing fork release tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
UPSTREAM_TAG=""
if [ -f .ccs-fork-upstream.env ]; then
# shellcheck disable=SC1091
. ./.ccs-fork-upstream.env
fi
if ! echo "${UPSTREAM_TAG}" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
UPSTREAM_TAG=$(git tag --merged HEAD --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1 || true)
fi
if [ -z "$UPSTREAM_TAG" ]; then
echo "[i] No synced upstream release tag found; nothing to tag."
exit 0
fi
FORK_TAG="${UPSTREAM_TAG}-0"
if git ls-remote --exit-code --tags origin "refs/tags/${FORK_TAG}" >/dev/null 2>&1; then
if gh release view "${FORK_TAG}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then
echo "[i] ${FORK_TAG} release already exists; nothing to tag."
exit 0
fi
echo "[i] ${FORK_TAG} tag already exists but release is missing; dispatching release workflow."
gh workflow run release.yaml --repo "${GITHUB_REPOSITORY}" --ref "${GITHUB_REF_NAME}" -f tag="${FORK_TAG}"
exit 0
fi
echo "[i] Creating ${FORK_TAG} for upstream ${UPSTREAM_TAG}."
git tag -a "$FORK_TAG" -m "CLIProxyAPIPlus ${FORK_TAG} (upstream ${UPSTREAM_TAG})"
git push origin "refs/tags/${FORK_TAG}"
gh workflow run release.yaml --repo "${GITHUB_REPOSITORY}" --ref "${GITHUB_REF_NAME}" -f tag="${FORK_TAG}"