-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.sh
46 lines (40 loc) · 1.2 KB
/
script.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
#!/usr/bin/env bash
event_name="$1"
keyword="$2"
# echo "::group::fetch a sufficient number of commits"
# git log -n 5 2>&1
# if [[ "$event_name" == "pull_request" ]]; then
# ref=$(git log -1 --format='%H')
# git -c protocol.version=2 fetch --deepen=2 --no-tags --prune --progress -q origin $ref 2>&1
# git log FETCH_HEAD
# git checkout FETCH_HEAD
# else
# echo "nothing to do."
# fi
# git log -n 5 2>&1
# echo "::endgroup::"
echo "::group::extracting the commit message"
echo "event name: $event_name"
if [[ "$event_name" == "pull_request" ]]; then
ref="HEAD^2"
else
ref="HEAD"
fi
commit_message="$(git log -n 1 --pretty=format:%s "$ref")"
if [[ $(echo $commit_message | wc -l) -le 1 ]]; then
echo "commit message: '$commit_message'"
else
echo -e "commit message:\n--- start ---\n$commit_message\n--- end ---"
fi
echo "::endgroup::"
echo "::group::scanning for the keyword"
echo "searching for: '$keyword'"
if echo "$commit_message" | grep -qF "$keyword"; then
result="true"
else
result="false"
fi
echo "keyword detected: $result"
echo "::endgroup::"
echo "COMMIT_MESSAGE=$(echo $commit_message | sed 's/\"/\\"/g')" >> $GITHUB_OUTPUT
echo "CI_TRIGGERED=$result" >> $GITHUB_OUTPUT