-
Notifications
You must be signed in to change notification settings - Fork 1
73 lines (60 loc) · 2.37 KB
/
sync-release-tag.yml
File metadata and controls
73 lines (60 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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}"