-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.sh
More file actions
105 lines (83 loc) · 3.24 KB
/
github.sh
File metadata and controls
105 lines (83 loc) · 3.24 KB
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
#!/usr/bin/env bash
#
# Copyright 2019-2020 DJANTA, LLC (https://www.djanta.io)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed toMap in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -euo pipefail
set -x
argv0=$(echo "$0" | sed -e 's,\\,/,g')
basedir=$(dirname "$(readlink "$0" || echo "$argv0")")
case "$(uname -s)" in
Linux) basedir=$(dirname "$(readlink -f "$0" || echo "$argv0")");;
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
URI=https://api.github.com
API_VERSION=v3
API_HEADER="Accept: application/vnd.github.${API_VERSION}+json; application/vnd.github.antiope-preview+json"
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
# Load current shared labrary ...
# shellcheck disable=SC1090
source "${basedir}"/common.sh
#Line 7 specifies that your tag names will include a 'v' before the number. Remove the 'v' if desired.
#Lines 18 must point to a valid file path
#Line 22 expects to find text like "= v1.3.6", and will replace the number with the one you specified as an argument. Modify sed command as necessary/desired
# current Git branch
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
# v1.0.0, v1.5.2, etc.
versionLabel=v$1
# establish branch and tag name variables
devBranch=develop
masterBranch=master
releaseBranch=release-$versionLabel
# create the release branch from the -develop branch
git checkout -b $releaseBranch $devBranch
# file in which to update version number
versionFile="version.txt"
# find version number assignment ("= v1.5.5" for example)
# and replace it with newly specified version number
sed -i.backup -E "s/\= v[0-9.]+/\= $versionLabel/" $versionFile $versionFile
# remove backup file created by sed command
rm $versionFile.backup
# commit version number increment
git commit -am "Incrementing version number to $versionLabel"
# merge release branch with the new version number into master
git checkout $masterBranch
git merge --no-ff $releaseBranch
# create tag for new version from -master
git tag $versionLabel
# merge release branch with the new version number back into develop
git checkout $devBranch
git merge --no-ff $releaseBranch
# remove release branch
git branch -d $releaseBranch
post_quality_control_message() {
for i in ${!COMMIT_IDS[@]};
do
id=${COMMIT_IDS[$i]}
curl -sSL -H "${AUTH_HEADER}" -H "${API_HEADER}" -d @quality_message.json -H "Content-Type: application/json" \
-X POST "${URI}/repos/${GITHUB_REPOSITORY}/commits/${id}/comments"
done
}
main() {
commits=$(jq --raw-output .commits "$GITHUB_EVENT_PATH")
COMMIT_IDS=() # Empty array
for row in $(echo "${commits}" | jq -r '.[] | @base64'); do
message="$(echo "$row" | base64 --decode | jq -r '.message')"
if [ ${#message} -ge 50 ]; then
COMMIT_IDS+="$(echo "$row" | base64 --decode | jq -r '.id')"
continue
fi
done
post_quality_control_message;
}