11#! /bin/bash
22
3- set -e
4-
5- VERSION=$( perl -MFile::Slurp::Tiny=read_file -MDateTime << EOF
6- use v5.16;
7- my \$ log = read_file(q{CHANGELOG.md});
8- \$ log =~ /\n(\d+\.\d+\.\d+) \((\d{4}-\d{2}-\d{2})\)\n/;
9- die 'Release time is not today!' unless DateTime->now->ymd eq \$ 2;
10- say \$ 1;
11- EOF
12- )
3+ set -eu -o pipefail
4+
5+ changelog=$( cat CHANGELOG.md)
6+
7+ regex='
8+ ([0-9]+\.[0-9]+\.[0-9]+) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\)
9+ -*
10+
11+ ((.|
12+ )*)
13+ '
14+
15+ if [[ ! $changelog =~ $regex ]]; then
16+ echo " Could not find date line in change log!"
17+ exit 1
18+ fi
19+
20+ version=" ${BASH_REMATCH[1]} "
21+ date=" ${BASH_REMATCH[2]} "
22+ notes=" $( echo " ${BASH_REMATCH[3]} " | sed -n -e ' /^[0-9]\+\.[0-9]\+\.[0-9]\+/,$!p' ) "
23+
24+ if [[ " $date " -ne $( date +" %Y-%m-%d" ) ]]; then
25+ echo " $date is not today!"
26+ exit 1
27+ fi
1328
14- TAG =" v$VERSION "
29+ tag =" v$version "
1530
1631if [ -n " $( git status --porcelain) " ]; then
1732 echo " . is not clean." >&2
3752
3853mvn versions:display-dependency-updates
3954
40- read -e -p " Continue given above dependencies? (y/n) " SHOULD_CONTINUE
55+ read -e -p " Continue given above dependencies? (y/n) " should_continue
4156
42- if [ " $SHOULD_CONTINUE " != " y" ]; then
57+ if [ " $should_continue " != " y" ]; then
4358 echo " Aborting"
4459 exit 1
4560fi
4661
47- PAGE =.gh-pages/index.md
48- cat << EOF > $PAGE
62+ page =.gh-pages/index.md
63+ cat << EOF > $page
4964---
5065layout: default
5166title: MaxMind minFraud Score and Insights Java API
5267language: java
53- version: $TAG
68+ version: $tag
5469---
5570
5671EOF
5772
58- export VERSION
59- # alter the documentation to point to this version
60- perl -pi -e ' s/(?<=<version>)[^<]*/$ENV{VERSION}/' README.md
61- perl -pi -e ' s/(?<=com\.maxmind\.geoip2\:geoip2\:)\d+\.\d+\.\d+([\w\-]+)?/$ENV{VERSION}/' README.md
73+ perl -pi -e " s/(?<=<version>)[^<]*/$version /" README.md
74+ perl -pi -e " s/(?<=com\.maxmind\.geoip2\:geoip2\:)\d+\.\d+\.\d+([\w\-]+)?/$version /" README.md
6275
63- cat README.md >> $PAGE
76+ cat README.md >> $page
6477
6578if [ -n " $( git status --porcelain) " ]; then
6679 git diff
6780
68- read -e -p " Commit README.md changes? " SHOULD_COMMIT
69- if [ " $SHOULD_COMMIT " != " y" ]; then
81+ read -e -p " Commit README.md changes? " should_commit
82+ if [ " $should_commit " != " y" ]; then
7083 echo " Aborting"
7184 exit 1
7285 fi
7689
7790# could be combined with the primary build
7891mvn release:clean
79- mvn release:prepare -DreleaseVersion=" $VERSION " -Dtag=" $TAG "
92+ mvn release:prepare -DreleaseVersion=" $version " -Dtag=" $tag "
8093mvn release:perform
81- rm -fr " .gh-pages/doc/$TAG "
82- cp -r target/apidocs " .gh-pages/doc/$TAG "
94+ rm -fr " .gh-pages/doc/$tag "
95+ cp -r target/apidocs " .gh-pages/doc/$tag "
8396
8497pushd .gh-pages
8598
8699git add doc/
87- git commit -m " Updated for $TAG " -a
100+ git commit -m " Updated for $tag " -a
101+
102+ echo " Release notes for $version :
103+
104+ $notes
88105
89- read -e -p " Push to origin? " SHOULD_PUSH
106+ "
90107
91- if [ " $SHOULD_PUSH " != " y" ]; then
108+ read -e -p " Push to origin? " should_push
109+
110+ if [ " $should_push " != " y" ]; then
92111 echo " Aborting"
93112 exit 1
94113fi
@@ -100,4 +119,12 @@ popd
100119git push
101120git push --tags
102121
122+ message=" $version
123+
124+ $notes "
125+
126+ hub release create -a " minfraud-$version -with-dependencies.zip" \
127+ -a " minfraud-$version -with-dependencies.zip.asc" \
128+ -m " $message " " $tag "
129+
103130echo " Remember to do the release on https://oss.sonatype.org/!"
0 commit comments