Sync Fork Release Tag #297
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| 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" | |
| # GITHUB_TOKEN tag pushes do NOT trigger downstream workflows, so we | |
| # explicitly dispatch release.yaml AND docker-image.yml after tagging. | |
| dispatch_downstream() { | |
| local tag="$1" | |
| gh workflow run release.yaml --repo "${GITHUB_REPOSITORY}" --ref "${GITHUB_REF_NAME}" -f tag="${tag}" || true | |
| gh workflow run docker-image.yml --repo "${GITHUB_REPOSITORY}" --ref "${GITHUB_REF_NAME}" -f tag="${tag}" || true | |
| } | |
| 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 downstream workflows." | |
| dispatch_downstream "${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}" | |
| dispatch_downstream "${FORK_TAG}" |