This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
/
changelog.sh
executable file
·120 lines (105 loc) · 3.38 KB
/
changelog.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
VARIANTNAME=$1
StatusFile=$VARIANTNAME/status.env
NewStatusFile=$VARIANTNAME/newstatus.env
RepoUsedPathFile=$VARIANTNAME/repo_used_path.env
URLFile=name_and_urls.env
ChangeLogFile=$VARIANTNAME/CHANGELOG.md
BuildTag="$VARIANTNAME-$(date +%Y-%m-%d)-$BuilderHash"
env | grep "Hash" > $NewStatusFile
ChangeLog=""
while read l; do
IFS='='
read -ra Parts <<< "$l"
name=${Parts[0]/Hash/}
hash=${Parts[1]}
hash=$(echo $hash | cut -c -7)
url=""
if [ -f "$URLFile" ]; then
urlLine=$(grep $URLFile -e ${name}URL)
url=$(echo "${urlLine/${name}URL=/}")
fi
oldLine=""
if [ -f "$StatusFile" ]; then
oldLine=$(grep $StatusFile -e ${name}Hash)
fi
logPathLine=""
if [ -f "$RepoUsedPathFile" ]; then
logPathLine=$(grep $RepoUsedPathFile -e ${name})
fi
title=""
body=""
if [ "$oldLine" == "" ]; then
title="${name} [$hash]($url/commit/$hash)"
else
read -ra Parts <<< "$oldLine"
oldHash=${Parts[1]}
oldHash=$(echo $oldHash | cut -c -7)
if ! [ "$oldHash" == "$hash" ]; then
logPath=""
if ! [ "$logPathLine" == "" ]; then
read -ra Parts <<< "$logPathLine"
logPath=${Parts[1]}
echo "only log repo $name for $logPath"
fi
title="${name} [${oldHash}..$hash]($url/compare/$oldHash..$hash)"
branch=master
if [ "$name" == "Argon" ]; then
branch="18.06"
fi
if [ "$name" == "FriendlyWRT" ]; then
branch="master-v19.07.1"
fi
if [ "$name" == "Kernel" ]; then
branch="nanopi-r2-v5.4.y"
fi
mkdir -p .temprepo
cd .temprepo
git init
git remote add $name ${url}.git
git fetch $name
body="
| Commit | Author | Desc |
| :----- | :------| :--- |
"
echo "Generating Change Log for ${name}/${branch} ${oldHash}..${hash} -- ${logPath}"
table=$(git log --no-merges --invert-grep --author="[email protected]" --pretty=format:"| [%h](${url}/commit/%h) | %an | %s |" ${oldHash}..${hash} ${name}/${branch} -- ${logPath})
if [ "$table" == "" ]; then
body=""
title=""
else
body="$body$table"
fi
cd ..
fi
fi
if ! [ "$title" == "" ]; then
ChangeLog="${ChangeLog}#### $title
$body
"
fi
done <$NewStatusFile
echo "$ChangeLog"
ChangeLogEscaped="${ChangeLog//'%'/'%25'}"
ChangeLogEscaped="${ChangeLogEscaped//$'\n'/'%0A'}"
ChangeLogEscaped="${ChangeLogEscaped//$'\r'/'%0D'}"
echo "::set-output name=changelog::$ChangeLogEscaped"
echo "::set-output name=buildtag::$BuildTag"
if [ "$ChangeLog" == "" ]; then
echo "No Change Happened, We Should Not Build."
exit 0
fi
ChangeLogFull="## $BuildTag
$ChangeLog
--------------
"
touch $ChangeLogFile
printf '%s\n%s\n' "$ChangeLogFull" "$(cat $ChangeLogFile)" >$ChangeLogFile
rm $StatusFile
mv $NewStatusFile $StatusFile
sed -i -E "s/(releases\/download\/)${VARIANTNAME}-[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9a-f]+\/${VARIANTNAME}-[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9a-f]+-ROM.zip/\1${BuildTag}\/${BuildTag}-ROM.zip/" ${VARIANTNAME}/README.md
git add $StatusFile
git add $ChangeLogFile
git add ${VARIANTNAME}/README.md
git commit -m "ChangeLog for $BuildTag"
# git push