1
+ #! /bin/bash
2
+
3
+ # ###
4
+ # Utils
5
+ # ###
6
+ source ${BASH_SOURCE%/* } /utils.sh
7
+ source ${BASH_SOURCE%/* } /github_utils.sh
8
+ # ##
9
+
10
+ # 1. Get options
11
+
12
+ # # Defaults
13
+ APPLY=" false"
14
+
15
+ while [[ $# -gt 0 ]]; do
16
+ case $1 in
17
+ -A|--apply)
18
+ APPLY=" true"
19
+ shift # past argument
20
+ ;;
21
+ -P|--previous-version-tag)
22
+ PREV_TAG_VERSION=" $2 "
23
+ shift # past argument
24
+ shift # past value
25
+ ;;
26
+ -V|--version)
27
+ VERSION=" $2 "
28
+ shift # past argument
29
+ shift # past value
30
+ ;;
31
+ -T|--github-token)
32
+ GITHUB_TOKEN=" $2 "
33
+ shift # past argument
34
+ shift # past value
35
+ ;;
36
+ -* |--* )
37
+ echo " Unknown option $1 "
38
+ exit 1
39
+ ;;
40
+ * )
41
+ POSITIONAL_ARGS+=(" $1 " ) # save positional arg
42
+ shift # past argument
43
+ ;;
44
+ esac
45
+ done
46
+
47
+ if [[ -z $GITHUB_TOKEN && apply == " true" ]]; then
48
+ echo_error " Github token required (-T, --github-token)"
49
+ exit 1
50
+ fi
51
+
52
+ if [[ -z $PREV_TAG_VERSION ]]; then
53
+ echo_error " Previous version tag required (-P, --previous-version-tag)"
54
+ exit 1
55
+ fi
56
+
57
+ if [[ -z $VERSION ]]; then
58
+ echo_error " Version to release required (-V, --version)"
59
+ exit 1
60
+ fi
61
+
62
+ # 2. Github
63
+ DATE=$( date +" %Y-%m-%d" )
64
+ RELEASE_NAME=" $VERSION / $DATE "
65
+ PREV_TAG_NAME=$PREV_TAG_VERSION
66
+ TAG_NAME=v$VERSION
67
+
68
+ # 2.1 Create Git tag for the repository
69
+ if [[ $APPLY == " true" ]]; then
70
+ echo_info " Tagging repository"
71
+ tag_repository $TAG_NAME
72
+ else
73
+ echo_warning " Dry run execution. Not tagging Github repo"
74
+ fi
75
+
76
+ # 2.2. Generate release notes
77
+ if [[ $APPLY == " true" ]]; then
78
+ echo_info " Generating Github release notes"
79
+ RESPONSE=$( generate_github_release_notes $GITHUB_TOKEN )
80
+ DESCRIPTION=$( echo $RESPONSE | jq ' .body' | tail -1 | sed " s/\" //g" )
81
+
82
+ if [ $( echo $RESPONSE | jq ' .body' | wc -l) -eq 1 ]; then
83
+ if [ $( echo $RESPONSE | jq ' .' | grep ' documentation_url' | wc -l) -gt 0 ]; then
84
+ echo_error " Something went wrong generating Github release notes"
85
+ echo $RESPONSE | jq --slurp ' .[0]'
86
+ exit 1
87
+ fi
88
+
89
+ if [ $( echo $RESPONSE | jq ' .type' | grep ' error' | wc -l) -gt 0 ]; then
90
+ echo_error " Something went wrong generating Github release notes"
91
+ echo $RESPONSE | jq --slurp ' .[1]'
92
+ exit 1
93
+ fi
94
+ fi
95
+ else
96
+ echo_warning " Dry run execution. Not generating Github release notes"
97
+ fi
98
+
99
+ # 2.3 Create Github release
100
+ if [[ $APPLY == " true" ]]; then
101
+ echo_info " Generating Github release"
102
+ create_github_release $GITHUB_TOKEN
103
+ else
104
+ echo_warning " Dry run execution. Not creating Github release"
105
+ fi
0 commit comments