Skip to content

Commit 59472c3

Browse files
authored
chore: add script: draft-changelog (#1071)
* chore: add script: draft-changelog * fix: draft-changelog diff ref
1 parent fa24a5f commit 59472c3

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

GNUmakefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,7 @@ endif
164164
ln -sf ../../../ext/providers/tencentcloud/website/tencentcloud.erb $(GOPATH)/src/github.com/hashicorp/terraform-website/content/source/layouts/tencentcloud.erb
165165
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
166166

167+
changelog:
168+
./scripts/draft-changelog.sh
169+
167170
.PHONY: build sweep test testacc fmt fmtcheck lint tools test-compile doc hooks website website-lint website-test

scripts/draft-changelog.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/sh
2+
3+
# this script can generate draft changelog instead of painful writing it
4+
# run with `make changelog` then copy it!
5+
6+
version=""
7+
gitTag=$(git describe --tag --abbrev=0)
8+
IFS=. read -r major minor patch <<< "$gitTag"
9+
10+
major=${major:1}
11+
12+
type=$1
13+
14+
if [[ -z $type ]]; then
15+
read -r -p "Specify semver: major, minor, patch(default) " input
16+
17+
type=$input
18+
if [[ -z $input ]]; then
19+
type="patch"
20+
fi
21+
fi
22+
23+
case $type in
24+
v*)
25+
version=$1
26+
;;
27+
major)
28+
version="$((major + 1)).0.0"
29+
;;
30+
minor)
31+
version="$major.$((minor + 1)).0"
32+
;;
33+
patch)
34+
version="$major.$minor.$((patch+1))"
35+
esac
36+
37+
diffs=$(git diff --name-only HEAD $gitTag | grep "tencentcloud/*")
38+
39+
40+
resource="^tencentcloud\/resource_tc_([a-z_]+)\.go$"
41+
data="^tencentcloud\/data_source_tc_([a-z_]+)\.go$"
42+
service="^tencentcloud\/service_([a-z_]+)\.go$"
43+
test="([a-z_]+)_test$"
44+
45+
items=""
46+
47+
48+
for file in ${diffs}; do
49+
module=""
50+
fileType="resource"
51+
if [[ $file =~ $resource ]]; then
52+
module="tencentcloud_${BASH_REMATCH[1]}"
53+
elif [[ $file =~ $data ]]; then
54+
fileType="data source"
55+
module="tencentcloud_${BASH_REMATCH[1]}"
56+
elif [[ $file =~ $service ]]; then
57+
module="tencentcloud_${BASH_REMATCH[1]}"
58+
fi
59+
60+
if [[ $module =~ $test ]]; then
61+
module=${BASH_REMATCH[1]}
62+
fi
63+
if [[ $module != "" ]]; then
64+
item="* $fileType \`$module\`"
65+
if [[ ! $items =~ "$item" ]]; then
66+
items="$items\n$item"
67+
fi
68+
fi
69+
70+
done
71+
72+
LANG=en_US
73+
dateStr=$(date +"%B %d, %Y")
74+
75+
template="
76+
## $version $dateStr
77+
\n
78+
\nFEATURES:
79+
\nDEPRECATED:
80+
\nENHANCEMENTS:
81+
\nBUGFIXES:
82+
\nCOMMON:
83+
\n
84+
$items
85+
\n
86+
"
87+
88+
echo $template

0 commit comments

Comments
 (0)