-
Notifications
You must be signed in to change notification settings - Fork 215
75 lines (67 loc) · 2.45 KB
/
Copy pathdevelop-synced-dispatch.yml
File metadata and controls
75 lines (67 loc) · 2.45 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
74
75
name: Dispatch develop-synced after sync/main merged (Scheme A)
on:
workflow_dispatch:
inputs:
version:
description: 'Release version, e.g. 1.2.3'
required: true
type: string
pull_request:
types:
- closed
branches:
- develop
jobs:
dispatch_develop_synced:
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'sync/main-'))
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Resolve version from input or sync branch
id: version
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
set -euo pipefail
VERSION="${INPUT_VERSION:-}"
if [ -z "${VERSION}" ]; then
BRANCH="${PR_HEAD_REF}"
echo "Head branch: ${BRANCH}"
VERSION="${BRANCH#sync/main-}"
if [ -z "${VERSION}" ] || [ "${VERSION}" = "${BRANCH}" ]; then
echo "Failed to parse version from branch ${BRANCH}, skip dispatch."
echo "version=" >> "$GITHUB_OUTPUT"
exit 0
fi
fi
if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid develop-synced version: ${VERSION}"
exit 1
fi
echo "Parsed version: ${VERSION}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Send repository_dispatch develop-synced
if: steps.version.outputs.version != ''
env:
GH_TOKEN: ${{ secrets.CREATE_TAG_RELEASE_TOKEN || github.token }}
run: |
set -euo pipefail
VERSION="${{ steps.version.outputs.version }}"
OWNER_REPO="${GITHUB_REPOSITORY}"
PAYLOAD="$(VERSION="${VERSION}" node -e '
const version = process.env.VERSION;
process.stdout.write(JSON.stringify({
event_type: "develop-synced",
client_payload: { version }
}));
')"
echo "Sending repository_dispatch develop-synced for version ${VERSION} to ${OWNER_REPO}"
curl --fail-with-body -sS -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_TOKEN}" \
"https://api.github.com/repos/${OWNER_REPO}/dispatches" \
-d "${PAYLOAD}"