-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.sh
executable file
·68 lines (53 loc) · 2.23 KB
/
build.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
63
64
65
66
67
68
#!/usr/bin/env bash
set -e
REPO="mritd/autobuild"
TOKEN="${GITHUB_TOKEN:-}"
TARGET="$1"
function now {
date +"%Y-%m-%d %H:%M:%S"
}
if [ "${TARGET}" == "alpine" ] || [ "${TARGET}" == "all" ] || [ "${TARGET}" == "" ]; then
# 触发alpine action
ALPINE_RESPONSE=$(curl -s -X POST -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$REPO/actions/workflows/alpine.yaml/dispatches" \
-d '{"ref":"main"}')
if [ -n "$ALPINE_RESPONSE" ]; then
echo "[$(now)] Alpine workflow triggered: $ALPINE_RESPONSE"
else
echo "[$(now)] Alpine workflow triggered with no response"
fi
# 等待 alpine workflow job 运行
sleep 10
while true; do
# 从 GitHub API 获取 action 的状态
ALPINE_STATUS=$(curl -s -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$REPO/actions/workflows/alpine.yaml/runs" | \
jq -r '.workflow_runs[0].status')
# 打印日志
echo "[$(now)] Status of mritd/alpine action: $ALPINE_STATUS"
# 如果状态为 "completed",退出循环
if [ "$ALPINE_STATUS" == "completed" ]; then
break
fi
# 等待 3 秒后再次检测
sleep 3
done
fi
if [ "${TARGET}" == "all" ] || [ "${TARGET}" == "" ]; then
# 获取除alpine action和.earthly以外的所有workflow的名称和ID
WORKFLOWS=$(curl -s -X GET -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$REPO/actions/workflows" | \
jq -r '.workflows[] | select(.path != ".github/workflows/.earthly.yaml" and .name != "mritd/alpine") | "\(.id) \(.name)"')
# 遍历除alpine action和.earthly以外的所有workflow的名称和ID,并触发它们
while read -r workflow_id workflow_name
do
response=$(curl -s -X POST -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$REPO/actions/workflows/$workflow_id/dispatches" \
-d '{"ref":"main"}')
if [ -n "$response" ]; then
echo "[$(now)] Workflow $workflow_name ($workflow_id): $response"
else
echo "[$(now)] Workflow $workflow_name ($workflow_id) triggered with no response"
fi
done <<< "$WORKFLOWS"
fi