changelog.sh 3.3 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
RepoUsedPathFile=$VARIANTNAME/repo_used_path.env
S
songchenwen 已提交
6
URLFile=name_and_urls.env
S
songchenwen 已提交
7 8
ChangeLogFile=$VARIANTNAME/CHANGELOG.md
BuildTag="$VARIANTNAME-$(date +%Y-%m-%d)-$BuilderHash"
S
songchenwen 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
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
S
songchenwen 已提交
27 28 29 30 31 32

    logPathLine=""
    if [ -f "$RepoUsedPathFile" ]; then
        logPathLine=$(grep $RepoUsedPathFile -e ${name})
    fi

S
songchenwen 已提交
33 34 35 36 37 38 39 40 41
    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
S
songchenwen 已提交
42 43 44 45 46 47 48
            logPath=""
            if ! [ "$logPathLine" == "" ]; then
                read -ra Parts <<< "$logPathLine"
                logPath=${Parts[1]}
                echo "only log repo $name for $logPath"
            fi

S
songchenwen 已提交
49
            title="${name} [${oldHash}..$hash]($url/compare/$oldHash..$hash)"
S
songchenwen 已提交
50 51 52 53 54 55 56 57
            branch=master
            if [ "$name" == "Argon" ]; then
                branch="18.06"
            fi
            if [ "$name" == "FriendlyWRT" ]; then
                branch="master-v19.07.1"
            fi

S
songchenwen 已提交
58 59 60 61 62 63 64 65 66
            mkdir -p .temprepo
            cd .temprepo
            git init
            git remote add $name ${url}.git
            git fetch $name
            body="
| Commit | Author | Desc |
| :----- | :------| :--- |
"
67 68
            echo "Generating Change Log for ${name}/${branch} ${oldHash}..${hash} -- ${logPath}"
            table=$(git log --no-merges --invert-grep --author="action@github.com" --pretty=format:"| [%h](${url}/commit/%h) | %an | %s |" ${oldHash}..${hash} ${name}/${branch} -- ${logPath})
S
songchenwen 已提交
69 70
            if [ "$table" == "" ]; then
                body=""
S
songchenwen 已提交
71
                title=""
S
songchenwen 已提交
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
            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
S
songchenwen 已提交
110

111
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
S
songchenwen 已提交
112

S
songchenwen 已提交
113 114
git add $StatusFile
git add $ChangeLogFile
115
git add ${VARIANTNAME}/README.md
S
songchenwen 已提交
116 117
git commit -m "ChangeLog for $BuildTag"
# git push