-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathrelease.sh
executable file
·76 lines (60 loc) · 2.55 KB
/
release.sh
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
#!/bin/bash
# Copyright 2018 Google LLC
#
# 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 to 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.
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
EXAMPLES_DIR=${DIR}/../examples
# Prompt the user for the version
echo -n "Enter the version for this release - ex: v1.14.0: "
read VERSION
# Remove 'v' prefix from version
MAKEFILE_VERSION=$(echo $VERSION | sed 's/^[v]//')
# Extract major, minor, and build version numbers
VERSION_MAJOR=$(echo $MAKEFILE_VERSION | cut -d. -f1)
VERSION_MINOR=$(echo $MAKEFILE_VERSION | cut -d. -f2)
VERSION_BUILD=$(echo $MAKEFILE_VERSION | cut -d. -f3)
echo "Processing (takes some time)..."
# Get the current date
DATE=$(date +'%Y-%m-%d')
# you can pass your github token with --token here if you run out of requests
# Capture output and replace newline characters with a placeholder
PULL_REQS=$(go run ${DIR}/release_notes/listpullreqs.go | tr '\n' '|')
CONTRIBUTORS=$(git log "$(git describe --abbrev=0)".. --format="%aN" --reverse | sort | uniq | awk '{printf "- %s\n", $0 }' | tr '\n' '|')
# Substitute placeholders with actual data in the template
TEMP_CHANGELOG=$(mktemp)
TEMP_CHANGELOG_FIXED=$(mktemp)
sed -e "s@{{PULL_REQUESTS}}@${PULL_REQS}@g" \
-e "s@{{CONTRIBUTORS}}@${CONTRIBUTORS}@g" \
-e "s@{{VERSION}}@${VERSION}@g" \
-e "s@{{DATE}}@${DATE}@g" \
${DIR}/release_notes/changelog_template.txt > $TEMP_CHANGELOG
# Replace '|' with '\n' in temporary changelog
sed 's/|/\n/g' $TEMP_CHANGELOG > $TEMP_CHANGELOG_FIXED
# Prepend to CHANGELOG.md
cat $TEMP_CHANGELOG_FIXED CHANGELOG.md > TEMP && mv TEMP CHANGELOG.md
echo "Prepended the following release information to CHANGELOG.md"
echo ""
cat $TEMP_CHANGELOG_FIXED
# Optionally, clean up the fixed temporary changlog file
rm $TEMP_CHANGELOG_FIXED
# Cleanup
rm $TEMP_CHANGELOG
echo "Updated Makefile for the new version: $VERSION"
# Update Makefile
sed -i.bak \
-e "s|VERSION_MAJOR ?=.*|VERSION_MAJOR ?= $VERSION_MAJOR|" \
-e "s|VERSION_MINOR ?=.*|VERSION_MINOR ?= $VERSION_MINOR|" \
-e "s|VERSION_BUILD ?=.*|VERSION_BUILD ?= $VERSION_BUILD|" \
./Makefile
# Cleanup
rm ./Makefile.bak