-
Notifications
You must be signed in to change notification settings - Fork 3
/
entrypoint.sh
executable file
·62 lines (43 loc) · 1.37 KB
/
entrypoint.sh
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
#!/usr/bin/env sh
set -e -o pipefail
GIT_TOKEN="${INPUT_TOKEN}"
DISPATCHES="${INPUT_DISPATCH}"
validate_vars() {
if [ -z "${GIT_TOKEN}" ]; then echo "::error::Password/token not set"; exit 1; fi
if [ -z "${DISPATCHES}" ]; then echo "::error::Dispatches not set"; exit 2; fi
}
check_commands() {
if ! command -v curl > /dev/null ; then echo "::error::Missing curl"; exit 3; fi
if ! command -v jq > /dev/null ; then echo "::error::Missing jq"; exit 4; fi
}
# https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event
trigger_dispatches() {
for dispatch in `echo "${DISPATCHES}" | jq -c .[]`
do
ORG=`echo ${dispatch} | jq -r '.org'`
REPO=`echo ${dispatch} | jq -r '.repo'`
BRANCH=`echo ${dispatch} | jq -r '.branch'`
WORKFLOW=`echo ${dispatch} | jq -r '.workflow'`
_post_data(){
cat <<EOF
{"ref": "refs/heads/${BRANCH}"}
EOF
}
echo "::group::$REPO"
echo "Triggering $WORKFLOW for $REPO."
echo "::endgroup::"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GIT_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${ORG}/${REPO}/actions/workflows/${WORKFLOW}/dispatches \
-d "$(_post_data)"
done
}
main(){
validate_vars
check_commands
trigger_dispatches
}
main $*