changelog.sh 2.6 KB
Newer Older
S
songchenwen 已提交
1
#!/bin/bash
S
songchenwen 已提交
2 3 4
VARIANTNAME=$1
StatusFile=$VARIANTNAME/status.env
NewStatusFile=$VARIANTNAME/newstatus.env
S
songchenwen 已提交
5
URLFile=name_and_urls.env
S
songchenwen 已提交
6 7
ChangeLogFile=$VARIANTNAME/CHANGELOG.md
BuildTag="$VARIANTNAME-$(date +%Y-%m-%d)-$BuilderHash"
S
songchenwen 已提交
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
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
    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
            title="${name} [${oldHash}..$hash]($url/compare/$oldHash..$hash)"
S
songchenwen 已提交
36 37 38 39 40 41 42 43
            branch=master
            if [ "$name" == "Argon" ]; then
                branch="18.06"
            fi
            if [ "$name" == "FriendlyWRT" ]; then
                branch="master-v19.07.1"
            fi

S
songchenwen 已提交
44 45 46 47 48 49 50 51 52
            mkdir -p .temprepo
            cd .temprepo
            git init
            git remote add $name ${url}.git
            git fetch $name
            body="
| Commit | Author | Desc |
| :----- | :------| :--- |
"
S
songchenwen 已提交
53 54
            echo "Generating Change Log for $name $branch ${oldHash}..${hash}"
            table=$(git log --no-merges --invert-grep --author="action@github.com" --pretty=format:"| [%h](${url}/commit/%h) | %an | %s |" ${oldHash}..${hash} ${name}/$branch)
S
songchenwen 已提交
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
            if [ "$table" == "" ]; then
                body=""
            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
git add $StatusFile
git add $ChangeLogFile
git commit -m "ChangeLog for $BuildTag"
# git push