Skip to content

Commit 1cfb32d

Browse files
authored
Add script to build relnotes. (KhronosGroup#316)
Includes a failed attempt to deploy them from CI. To be kept until Travis dpl is fixed.
1 parent 082d1b6 commit 1cfb32d

File tree

3 files changed

+272
-41
lines changed

3 files changed

+272
-41
lines changed

.travis.yml

+21-2
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,27 @@ before_deploy:
108108
;;
109109
osx)
110110
# Only notarize if we're going to deploy. I.e on a tag. Also check for access
111-
# to singing certs to make sure we don't try this on a fork which has a tag.
111+
# to signing certs to make sure we don't try this on a fork which has a tag.
112112
#
113113
# Although undocumented, except for a blog post, before_deploy is run for each
114114
# deployment so we need to take steps to prevent notarization being run twice.
115115
# https://github.com/travis-ci/travis-ci/issues/2570 about this has been open
116116
# for years. What a crock!
117117
if [ -n "$MACOS_CERTIFICATES_P12" -a -n "$TRAVIS_TAG" -a -z "$NOTARIZED" ]; then
118-
./ci_scripts/notarize.sh build-macos/KTX-Software-*.pkg $APPLE_ID $DEVELOPMENT_TEAM $ALTOOL_PASSWORD; export NOTARIZED="true";
118+
./ci_scripts/notarize.sh build-macos/KTX-Software-*.pkg $APPLE_ID $DEVELOPMENT_TEAM $ALTOOL_PASSWORD; export NOTARIZED="true"
119+
fi
120+
if [ -z "$RELNOTES" -a -f RELEASE_NOTES.md ]; then
121+
# Copy RELEASE_NOTES into an env. var. so we can remove lines that are
122+
# unnecessary in the context of a GitHub release description.
123+
RELNOTES=$(cat RELEASE_NOTES.md | awk '/^Release Notes/,/^## Version/ { next }
124+
! /<!-- Copyright/ && ! /<!-- SPDX/ { print }')
119125
fi
120126
;;
121127
esac
122128
123129
deploy:
124130
- provider: pages
131+
#edge: true # Use bleeding edge (dplv2)
125132
skip-cleanup: true
126133
github-token: $GITHUB_TOKEN # Set in the repo settings page as a secure variable
127134
local-dir: build-macos/docs/html
@@ -130,10 +137,21 @@ deploy:
130137
condition: $TRAVIS_OS_NAME = osx
131138
tags: true
132139
- provider: releases
140+
# dpl v2 is broken. Same named but different releases are created for this
141+
# and the deploy below. Happens even when neither of release_notes or
142+
# release_notes_file is specified.
143+
#edge: true # Use bleeding edge (dplv2)
133144
api_key: $GITHUB_TOKEN # Set in the repo settings page as a secure variable
134145
file_glob: true
135146
file:
136147
- build-macos/KTX-Software-*.pkg
148+
# This goes to the release description so covers all versions.
149+
# These are dpl v2 parameters.
150+
#release_notes_file: RELEASE_NOTES.md
151+
#release_notes: $RELNOTES
152+
# dpl v1. Sadly this doesn't work. See https://github.com/travis-ci/dpl/issues/155.
153+
# body: $RELNOTES
154+
# Do release note deployment manually for now.
137155
skip_cleanup: true
138156
draft: true
139157
prerelease: true
@@ -142,6 +160,7 @@ deploy:
142160
#branch: master
143161
condition: $TRAVIS_OS_NAME = osx
144162
- provider: releases
163+
#edge: true # Use bleeding edge (dplv2)
145164
api_key: $GITHUB_TOKEN # Set in the repo settings page as a secure variable
146165
file_glob: true
147166
file:

mkrelnotes

+251
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
#! /bin/bash
2+
3+
# Copyright 2020, Mark Callow
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Generate release notes from git log.
7+
#
8+
# mkrelnotes [-b] [-c] [-d] [-p <preface> [-t] <previous release tag> <this release>
9+
#
10+
# <previous release tag> is the name of the tag identifying the previous
11+
# release. <this release> is the name to be given to the tag for the upcoming
12+
# release. N.B. this tag cannot be created until after ther release notes
13+
# have been generated and checked in. The release notes will include changes
14+
# in the two-dot commit range <previous release tag>..HEAD.
15+
#
16+
# <preface> is inserted between the title and the detailed change list
17+
# that is extracted with git log. It should be used to summarize
18+
# new features and known issues using level 3 (###) headings for those
19+
# sections.
20+
#
21+
# If -b is specified build system changes will be included in the
22+
# release # notes.
23+
#
24+
# If -c is specified any previous $RELNOTES_FILE will be appended, with the
25+
# title lines stripped, to the release notes generated here, thus enabling
26+
# cumulative release notes. Otherwise any previous $RELNOTES_FILE file is
27+
# replaced.
28+
#
29+
# If -d is specified details of the changes will be included, otherwise only
30+
# the summary is shown.
31+
#
32+
# If -i is specified the release notes will be built interactively. That is,
33+
# for each change the user will be asked if it should be included.
34+
#
35+
# If -t is specified changes to the tests will be included in the release notes
36+
# otherwise they are omitted.
37+
38+
# Depth of this script relative to the project root
39+
depth=.
40+
41+
RELNOTES_FILE="RELEASE_NOTES.md"
42+
43+
# The author name in a commit message comes from whatever the user
44+
# has set as user.name in their git config. It usually has no relation
45+
# to their GitHub username so putting an @ before it has no meaning.
46+
#
47+
SUMMARY_FORMAT_W_AUTH="* %s (%h) (%an)"
48+
SUMMARY_FORMAT="* %s (%h)"
49+
50+
function commit_summary() {
51+
local hash=$1
52+
local summary
53+
local prjson
54+
pr=$(git log --oneline -n 1 $hash | grep -o -E "\(#[0-9]+\)" | grep -o -E "[0-9]+")
55+
# Even in PR's the commit has the full name of the user as known to GitHub,
56+
# not their GitHub username. We want to use the GitHub username so there will
57+
# be a link back to the person. We can retrieve this by requesting detailed info
58+
# from GitHub via HTTPS.
59+
summary=$(git log --pretty="$SUMMARY_FORMAT" -n 1 $hash)
60+
if [ -z "$pr" ]; then
61+
cmtjson="$(curl -n https://api.github.com/repos/KhronosGroup/KTX-Software/commits/$hash 2>/dev/null)"
62+
author="$(echo $cmtjson | jq -r -e '.author.login')"
63+
else
64+
prjson="$(curl -n https://api.github.com/repos/KhronosGroup/KTX-Software/pulls/$pr 2>/dev/null)"
65+
author="$(echo $prjson | jq -r -e '.user.login')"
66+
fi
67+
summary+=" (@$author)"
68+
echo "$summary"
69+
if [ -n "$includeDetails" ]; then
70+
body="$(git log --pretty="%b" -n 1 $hash | sed -E 's/^(.+)/ \1/')"
71+
if [ -n "$body" ]; then
72+
echo ""
73+
# Remove CR which some multi-line commit bodies contain for unknown reasons.
74+
echo "$body" | tr -d \\r
75+
fi
76+
fi
77+
}
78+
79+
function revisions_in () {
80+
local range=$1; shift
81+
git rev-list $range $*
82+
}
83+
84+
function log() {
85+
local part=$1; shift
86+
local log
87+
for rev in $(revisions_in "$range" $*); do
88+
if [ -n "$interactive" ]; then
89+
git log -1 $rev > /dev/tty
90+
91+
processed=0
92+
while [ $processed -eq 0 ]; do
93+
echo "Include this change? [d,i,s,?] ?" > /dev/tty
94+
read -n 1 opt
95+
echo "" > /dev/tty
96+
97+
case $opt in
98+
d)
99+
git show --pretty=oneline $rev > /dev/tty
100+
;;
101+
[is])
102+
processed=1
103+
;;
104+
?)
105+
echo "d - show diff of this commit" > /dev/tty
106+
echo "i - include this commit." > /dev/tty
107+
echo "s - skip this commit." > /dev/tty
108+
echo "? - display this help message." > /dev/tty
109+
;;
110+
*)
111+
echo "Unknown option: $opt. Try again." > /dev/tty
112+
;;
113+
esac
114+
done
115+
116+
case $opt in
117+
i)
118+
log+="$(commit_summary $rev)"
119+
;;
120+
esac
121+
122+
else
123+
log+="$(commit_summary $rev)"
124+
fi
125+
# For reasons I do not understand I have been completely unable to prevent
126+
# trailing newlines from being removed from the output of commit_summary
127+
# so resorting to ANSI-C quoting to insert some new lines between summaries.
128+
log+=$'\n\n'
129+
done
130+
if [ -n "$log" ]; then
131+
echo "### $part"
132+
echo
133+
echo "$log"
134+
echo
135+
fi
136+
}
137+
138+
function usage() {
139+
cat << EOU
140+
Usage: $0 [-b] [-c] [-d] [-i] [-p <preface>] [-t] <commit range>"
141+
Options:
142+
-b Include build system changes
143+
-c Make cumulative release notes
144+
-d Include details of changes. If absent only the summary is shown.
145+
-i Interactively select the changes to include.
146+
-p <preface>
147+
Include the file <preface> before the list of changes.
148+
-t Include test changes.
149+
EOU
150+
}
151+
152+
while true; do
153+
case $1 in
154+
-b) includeBuildSystem="true"; shift ;;
155+
-c) cumulative="true"; shift;;
156+
-d) includeDetails="true"; shift ;;
157+
-i) interactive="true"; shift;;
158+
-p) preface=$2; shift 2 ;;
159+
-t) includeTests="true"; shift ;;
160+
-*) usage; exit 1 ;;
161+
*) break ;;
162+
esac
163+
done
164+
165+
if [ $# -ne 2 ]; then
166+
echo "$0: Need previous release tag and this release name, e.g. 'v4.0.0 v4.0.1'."
167+
exit 1
168+
else
169+
range=$1..
170+
lastrel=$1
171+
thisrel=$2
172+
fi
173+
174+
#if [ $# -ne 1 ]; then
175+
# echo '$0: Need a two-dot revision range, e.g, `v4.0.0..v4.0.1`.'
176+
# exit 1
177+
#else
178+
# range=$1
179+
# if ! [[ $range =~ ([[:alnum:][:punct:]]+)\.\.([[:alnum:]][[:alnum:][:punct:]]*)? ]]; then
180+
# echo "$0: <revision range> is not a two-dot range."
181+
# exit 1
182+
# else
183+
# lastrel=${BASH_REMATCH[1]}
184+
# thisrel=${BASH_REMATCH[2]}
185+
# if [ -z "$lastrel" ]; then
186+
# lastrel=HEAD
187+
# fi
188+
# fi
189+
#fi
190+
191+
SAVED_RELNOTES_FILE="${RELNOTES_FILE%.md}-$lastrel.md"
192+
193+
# Save or remove old relnotes.
194+
if [ -f $RELNOTES_FILE ]; then
195+
if [ -z "$cumulative" ]; then
196+
rm $RELNOTES_FILE;
197+
else
198+
mv $RELNOTES_FILE $SAVED_RELNOTES_FILE
199+
fi
200+
fi
201+
202+
# Read preface file before cd.
203+
if [ -n "$preface" ]; then
204+
PREFACE=$(cat $preface)
205+
fi
206+
207+
# Change to the directory where the script is.
208+
cd $(dirname $0)
209+
210+
# Change to project root.
211+
pushd $depth > /dev/null
212+
213+
lib=$(log libktx lib)
214+
tools=$(log Tools tools)
215+
if [ -n "$includeTests" ]; then
216+
tests=$(log "Tests" tests)
217+
fi
218+
js_binding=$(log "JS Wrappers" interface/js_binding)
219+
220+
if [ -n "$includeBuildSystem" ]; then
221+
cmake=$(log "Build System" $(find . \( -path ./build -o -path ./.git -o -path ./other_include \) -prune -false -o -name CMakeLists.txt -o -name '*.cmake'))
222+
fi
223+
224+
225+
cat > $RELNOTES_FILE <<- EOF
226+
$(date '+<!-- Copyright %Y, The Khronos Group Inc. -->')
227+
<!-- SPDX-License-Identifier: Apache-2.0 -->
228+
Release Notes
229+
=============
230+
## Version ${thisrel#v}
231+
$PREFACE
232+
233+
### Changes since $lastrel (by part)
234+
$lib
235+
236+
$tools
237+
238+
$tests
239+
240+
$js_binding
241+
242+
$cmake
243+
EOF
244+
245+
246+
popd > /dev/null
247+
248+
if [ -f $SAVED_RELNOTES_FILE ]; then
249+
awk '! /Release Notes/ && ! /======/ && ! /<!-- Copyright/ && ! /<!-- SPDX/ {print}' $SAVED_RELNOTES_FILE >> $RELNOTES_FILE
250+
rm $SAVED_RELNOTES_FILE
251+
fi

pkgdoc/preface.md

-39
This file was deleted.

0 commit comments

Comments
 (0)