Skip to content

Commit c886756

Browse files
authored
chore: Generate clog from template (coder#200)
1 parent 175244f commit c886756

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

scripts/create-clog.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env bash
2+
#
3+
# create-clog.sh [--version=<version>] [--release-date=<release-date>]
4+
#
5+
# Dependencies: getopt sed
6+
#
7+
# Description: Uses template_changelog.md to create a new changelog.
8+
#
9+
# Examples:
10+
# ./scripts/create-clog.sh --version="1.18.0" --release-date="05/18/2021"
11+
12+
13+
set -eou pipefail
14+
15+
VERSION_DELIM="<% X.Y.Z %>"
16+
RELEASE_DATE_DELIM="<% MM/DD/YYYY %>"
17+
VERSION=""
18+
RELEASE_DATE=""
19+
20+
# usage prints information for how to use this program. Exits with status code
21+
# 1.
22+
function usage () {
23+
echo "Usage: create-clog [--version=<version>] [--release-date=<release-date>]"
24+
echo "Create a changelog from a template"
25+
echo "Arguments:"
26+
echo " <version>: A version string 'x.y.z'"
27+
echo " <release-date>: A date string 'mm/dd/yyyy'"
28+
exit 1
29+
}
30+
31+
# init parses arguments and initializes all variables.
32+
function init () {
33+
options=$(getopt \
34+
--name="$(basename "$0")" \
35+
--longoptions=" \
36+
help, \
37+
release-date:, \
38+
version:" \
39+
--options="h" \
40+
-- "$@")
41+
[ $? -eq 0 ] || {
42+
usage
43+
}
44+
45+
eval set -- "$options"
46+
47+
while true; do
48+
case "${1:-}" in
49+
-h|--help)
50+
usage
51+
;;
52+
--version)
53+
shift;
54+
VERSION="$1"
55+
;;
56+
--release-date)
57+
shift;
58+
RELEASE_DATE="$1"
59+
;;
60+
--)
61+
shift
62+
break
63+
;;
64+
esac
65+
shift
66+
done
67+
68+
if [ -z "$VERSION" ]; then
69+
echo "version argument is empty."
70+
echo "Expected a version string like 'x.y.z'"
71+
usage
72+
fi
73+
74+
if [ -z "$RELEASE_DATE" ]; then
75+
echo "release-date argument is empty."
76+
echo "Expected a date string like 'mm/dd/yyyy'"
77+
usage
78+
fi
79+
}
80+
81+
# create_from_template creates a new changelog file from template_changelog.md
82+
# using VERSION and RELEASE_DATE.
83+
function create_from_template () {
84+
echo "Creating template using version: $VERSION and release date: $RELEASE_DATE"
85+
pushd "$(git rev-parse --show-toplevel)" > /dev/null
86+
clogPath="./changelog/$VERSION.md"
87+
cp ./scripts/template_changelog.md "$clogPath"
88+
sed -i "s|$VERSION_DELIM|$VERSION|g" "$clogPath"
89+
sed -i "s|$RELEASE_DATE_DELIM|$RELEASE_DATE|g" "$clogPath"
90+
popd > /dev/null
91+
}
92+
93+
# main program
94+
init "$@"
95+
create_from_template
96+
echo "Done"

scripts/template_changelog.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: "<% X.Y.Z %>"
3+
description: "Released on <% MM/DD/YYYY %>"
4+
---
5+
6+
### Breaking Changes ❗
7+
8+
There are no breaking changes in <% X.Y.Z %>.
9+
10+
### Features ✨
11+
12+
There are no new features in <% X.Y.Z %>.
13+
14+
### Bug Fixes 🐛
15+
16+
There are no bug fixes in <% X.Y.Z %>.
17+
18+
### Security Updates 🔐
19+
20+
There are no security updates in <% X.Y.Z %>.

0 commit comments

Comments
 (0)