forked from MLstate/opalang
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] CHANGELOG: automatic update script
- Loading branch information
1 parent
c90b937
commit e69e133
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
9a7e9a41dc88ecfcc579ae7b383a00455b65ec6d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/usr/bin/env bash | ||
|
||
TMPPREF=/tmp/upchangelog_ | ||
DIFFGIT=${TMPPREF}diffgit | ||
DIFFCHANGELOG=${TMPPREF}diffchangelog | ||
DIFFCHANGELOGNOCOMMENT=${TMPPREF}diffchangelog_nocomment | ||
FULLCHANGELOGPROP=${TMPPREF}FULLCHANGELOG.proposal | ||
CHANGELOGPROP=${TMPPREF}FULLCHANGELOG.proposal | ||
|
||
CHANGELOG=CHANGELOG | ||
FULLCHANGELOG=utils/FULLCHANGELOG | ||
CHANGELOGTAGF=utils/CHANGELOG.TAG | ||
|
||
touch $FULLCHANGELOG | ||
|
||
set -u | ||
set -e | ||
|
||
help() { | ||
cat >&2 <<EOF | ||
Usage: | ||
upchangelog.sh options | ||
with: | ||
-low TAG the tag where to start the extract (defaut is CHANGELOG.TAG) | ||
-high TAG the tag where to start the extract (defaut is last vTAG) | ||
-help shows this message | ||
EOF | ||
} | ||
|
||
|
||
MASTERTAG=$(git tag | grep -e "^v[0-9]*" | sort -n | tail -n 1) | ||
CHANGELOGTAG=$(cat $CHANGELOGTAGF) | ||
|
||
normalise_tag(){ | ||
local SHA=git log -n --format="%H" $1 | ||
local TAG=git tag --contains $1 | ||
if [ "$TAG" = "" ]; | ||
then | ||
echo $SHA | ||
else | ||
echo $TAG | ||
fi | ||
} | ||
|
||
while [ $# -gt 0 ]; do | ||
case "$1" in | ||
-low) | ||
shift | ||
CHANGELOGTAG=$(normalise_tag $1) | ||
;; | ||
-high) | ||
shift | ||
MASTERTAG=$(normalise_tag $1) | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
echo $CHANGELOGTAG "=>" $MASTERTAG | ||
echo $(git log $CHANGELOGTAG..$MASTERTAG | wc -l) commits | ||
|
||
|
||
header(){ | ||
if [ "$(head -n 1 CHANGELOG)" != "$CHANGELOGTAG" ]; | ||
then | ||
echo -n "$CHANGELOGTAG.." | ||
fi | ||
echo $MASTERTAG | ||
} | ||
|
||
content(){ | ||
(git log -n 1 $1 | grep CHANGELOG | sed s/CHANGELOG//g | sed '1s/^\(.\)\{3\}//g') | ||
} | ||
|
||
changelogcommit(){ | ||
local commit=$1 | ||
local author=$(git log -n 1 --format="%an <%ae> %ad" $commit) | ||
if [ $(content $commit | wc -w) -eq 0 ]; | ||
then | ||
echo -n " * " | ||
git log -n 1 --format="%s" $commit | ||
else | ||
echo -n " * " | ||
content $commit | ||
fi | ||
echo " -- $author" | ||
echo " -- $commit" | ||
echo "" | ||
} | ||
|
||
|
||
git log --pretty=format:%h --grep="^CHANGELOG" $CHANGELOGTAG..$MASTERTAG > $DIFFGIT | ||
|
||
echo $(cat $DIFFGIT | wc -w) entries | ||
|
||
if [ "$(cat $DIFFGIT | wc -w)" -gt 0 ]; | ||
then | ||
echo Adding the following | ||
header > $DIFFCHANGELOG | ||
for commit in $(cat $DIFFGIT); | ||
do | ||
changelogcommit $commit >> $DIFFCHANGELOG | ||
done | ||
cat $DIFFCHANGELOG | grep -v "^ \-\-" | ||
|
||
cat $DIFFCHANGELOG $FULLCHANGELOG > $FULLCHANGELOGPROP | ||
cat $FULLCHANGELOGPROP > $FULLCHANGELOG | ||
|
||
grep -v "^ \-\-" $DIFFCHANGELOG > $DIFFCHANGELOGNOCOMMENT | ||
cat $DIFFCHANGELOGNOCOMMENT $CHANGELOG > $CHANGELOGPROP | ||
echo $MASTERTAG > $CHANGELOGTAGF | ||
|
||
cat $CHANGELOGPROP > $CHANGELOG | ||
|
||
|
||
rm /${TMPPREF}* | ||
else | ||
echo Nothing to do | ||
fi |