forked from CherryHQ/cherry-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (60 loc) · 2.5 KB
/
Copy pathauto-release-build.yml
File metadata and controls
67 lines (60 loc) · 2.5 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
name: Auto Release Build
run-name: Auto build ${{ github.event.workflow_run.head_branch }} @ ${{ github.event.workflow_run.head_sha }}
on:
workflow_run:
workflows: [CI]
types: [completed]
permissions:
actions: write
contents: read
concurrency:
group: auto-release-build-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: false
jobs:
dispatch:
name: Dispatch exact release head
if: >-
github.repository == 'CherryHQ/cherry-studio' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_repository.full_name == github.repository &&
startsWith(github.event.workflow_run.head_branch, 'release/v')
runs-on: ubuntu-latest
steps:
- name: Revalidate and dispatch release build
shell: bash
env:
BRANCH: ${{ github.event.workflow_run.head_branch }}
CI_SHA: ${{ github.event.workflow_run.head_sha }}
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
run: |
export LC_ALL=C
TAG="${BRANCH#release/}"
if [[ ! "$TAG" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then
echo "Ignoring invalid release branch $BRANCH"
exit 0
fi
BRANCH_SHA="$(gh api "repos/$REPO/git/ref/heads/$BRANCH" --jq '.object.sha')"
if [ "$BRANCH_SHA" != "$CI_SHA" ]; then
echo "Ignoring stale CI result for $CI_SHA; $BRANCH now points to $BRANCH_SHA"
exit 0
fi
EXPECTED_TITLE="Release build all $BRANCH @ $CI_SHA"
RELEASE_RUNS="$(gh api --paginate --slurp \
"repos/$REPO/actions/workflows/release.yml/runs?head_sha=$CI_SHA&event=workflow_dispatch&per_page=100")"
EXISTING_RUN="$(jq -c --arg title "$EXPECTED_TITLE" --arg sha "$CI_SHA" '
[.[] | .workflow_runs[] | select(
.display_title == $title and
.head_sha == $sha and
.event == "workflow_dispatch"
)][0] // empty
' <<< "$RELEASE_RUNS")"
if [ -n "$EXISTING_RUN" ]; then
echo "Release build already exists: $(jq -r '.html_url' <<< "$EXISTING_RUN")"
exit 0
fi
gh workflow run release.yml --repo "$REPO" --ref "$BRANCH" \
-f platform=all \
-f expected_sha="$CI_SHA"
echo "Dispatched all-platform release build for $BRANCH at $CI_SHA"