This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon
152 lines (121 loc) · 3.89 KB
/
common
1
2
3
4
5
6
7
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
set -e
if [[ -n $DEBUG ]]; then
set -x
fi
# Warn if current branch is not develop and/or not inline with upstream
verify_branch() {
git fetch
if [ "develop" != "$(basename "$(git symbolic-ref -q HEAD)")" ]; then
echo "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓">&2
echo "┃ 🚨 You are not on develop 🚨 ┃">&2
echo "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛">&2
fi
echo "==> Current commit id: $(git rev-parse HEAD)" >&2
count="$(git rev-list --count --left-right "@{upstream}...HEAD")"
case "$count" in
"")
echo "==> You do not have an upstream set" >&2 ;;
"0 0")
return ;;
"0 "*)
echo "==> Your branch is ${count#0 } commits ahead of the upstream" >&2 ;;
*" 0")
echo "==> Your branch is ${count% 0} commits behind upstream" >&2 ;;
*)
echo "==> Your branch is ${count#* } ahead and ${count# *} behind upstream" >&2 ;;
esac
if [ "y" != "$(prompt "Do you wish to continue [y/N]: ")" ]; then
exit 1
fi
}
identify_repo() {
REMOTE_URL="$(git remote get-url origin)"
if [[ "$REMOTE_URL" =~ ^https://github.com/ ]]; then
REPOSITORY_NAME="${REMOTE_URL##https://github.com/}"
elif [[ "$REMOTE_URL" =~ ^git@github.com:.*\.git$ ]]; then
REPOSITORY_NAME="${REMOTE_URL##git@github.com:}"
REPOSITORY_NAME="${REPOSITORY_NAME%%.git}"
else
echo "origin does not appear to be a valid GitHub Remote URL: ${REMOTE_URL}"
exit 1
fi
}
identify_release() {
BRANCH_NAME=$(branch_name)
if [[ ! "${BRANCH_NAME}" =~ ^release/.* ]]; then
echo "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓">&2
echo "┃ 🚨 Not on a release branch 🚨 ┃">&2
echo "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛">&2
exit 1
fi
RELEASE_TAG="${BRANCH_NAME##*/}"
}
update_release_numbers() {
VERSION_NUMBER="$(update_version_number)"
RELEASE_NAME="$(prompt "Enter a name for this release: ${VERSION_NUMBER}-")"
RELEASE_TAG="${VERSION_NUMBER}-${RELEASE_NAME}"
}
create_release_branch() {
BRANCH_NAME="release/${RELEASE_TAG:?must be defined}"
echo "==> Creating branch ${BRANCH_NAME}"
git checkout -b "$BRANCH_NAME"
}
tag_release_notes() {
local temp_file
temp_file=$(mktemp)
REPOSITORY_NAME="${REPOSITORY_NAME:?must be defined}"
RELEASE_TAG="${RELEASE_TAG:?must be defined}"
cat - "release_notes.md" <<RELEASE_NOTES_HEADER > "$temp_file"
- - -
## [${RELEASE_TAG}](https://github.com/${REPOSITORY_NAME}/releases/tag/${RELEASE_TAG})
Date: $(date +"%d %B %Y")
RELEASE_NOTES_HEADER
mv "${temp_file}" "release_notes.md"
git add "release_notes.md"
}
update_version_number() {
local version_number
# Get the current version number
version_number=$(read_version_number)
# Ask for the new one
new_version_number=$(prompt "Enter version number [${version_number}]: ")
# Use the current version if none was specified
if [[ -z $new_version_number ]]; then
new_version_number=$version_number
fi
# Put it back
write_version_number "${new_version_number}"
echo "${new_version_number}"
}
prompt() {
local input
echo -n "==> $1" >&2
read -r input
echo "$input"
}
read_version_number() {
cat "version"
}
write_version_number() {
echo "$1" > "version"
git add "version"
}
commit_message() {
RELEASE_TAG="${RELEASE_TAG:?must be defined}"
cat <<COMMIT_MESSAGE
Preparing release ${RELEASE_TAG}
#
# To abort: Empty this file, Save and exit
COMMIT_MESSAGE
}
branch_name() {
git symbolic-ref --short HEAD
}
github_api_request() {
GITHUB_TOKEN="${GITHUB_TOKEN:-$(github_token)}"
curl -s -H "Authorization: token $GITHUB_TOKEN" "$@"
}
github_token() {
git credential fill <<<"host=github.com" | awk -F '=' '/password/{print $2}'
}