-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·46 lines (37 loc) · 1.84 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
#!/usr/bin/env bash
# A helper function to escape certain characters in the GH Action runner.
function escapify {
local res="${1//'%'/'%25'}"
res="${res//$'\n'/'%0A'}"
res="${res//$'\r'/'%0D'}"
echo "$res"
}
# If the head is tagged then use that tag otherwise @ to reference it as the default.
THIS_TAG=$(git tag --points-at HEAD)
DEAFULT_HEAD=${THIS_TAG:-@}
# If the head is tagged, then use the second last tag, otherwise the last tag.
# If only the head is tagged or no tags are present, then use the initial commit reference.
INITIAL_COMMIT=$(git rev-list --max-parents=0 @)
read last prev <<< $(git tag --sort=-committerdate | head -2 | paste - -)
PREV_TAG=$( [ -z $THIS_TAG ] && echo $last || echo $prev )
DEAFULT_TAIL=${PREV_TAG:-$INITIAL_COMMIT}
# Use user-supplied values to determine the history range, otherwise fallback to above defaults.
HEAD=${INPUT_HEAD:-$DEAFULT_HEAD}
TAIL=${INPUT_TAIL:-$DEAFULT_TAIL}
RANGE=$TAIL..$HEAD
echo "::set-output name=head::$HEAD"
echo "::set-output name=tail::$TAIL"
commits=$(git log $RANGE --no-merges --oneline | awk '{print "- "$0}')
commits=$(escapify "$commits")
echo "::set-output name=commits::$commits"
prs=$(git log --format="%s %b" --merges $RANGE | grep "Merge pull request #" | cut -d' ' -f4,6- | awk '{print "- "$0}')
prs=$(escapify "$prs")
echo "::set-output name=prs::$prs"
files=$(git diff --stat $RANGE)
files=$(escapify "$files")
echo "::set-output name=files::$files"
authors=$(git log --format="%an" --no-merges $RANGE)
coauthors=$(git log --format="%(trailers)" --no-merges $RANGE | grep -oP "Co-authored-by: \K.+(?= <)")
contributors=$(echo -e "$authors\n$coauthors" | sed '/^$/d' | grep -v "\[bot\]" | tr ' ' '#' | sort | uniq -c | sort -nr | awk '{print "- "$2" ("$1" commits)"}' | tr '#' ' ')
contributors=$(escapify "$contributors")
echo "::set-output name=contributors::$contributors"