From 1ee489d4e50e6b714fa5481a3933eedd0eca6483 Mon Sep 17 00:00:00 2001 From: Kagashino Date: Wed, 1 Jun 2022 19:53:53 +0800 Subject: [PATCH 1/2] chore: add script: draft-changelog --- GNUmakefile | 3 ++ scripts/draft-changelog.sh | 88 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100755 scripts/draft-changelog.sh diff --git a/GNUmakefile b/GNUmakefile index 13e8e5dd91..e6e86e6299 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -164,4 +164,7 @@ endif ln -sf ../../../ext/providers/tencentcloud/website/tencentcloud.erb $(GOPATH)/src/github.com/hashicorp/terraform-website/content/source/layouts/tencentcloud.erb @$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME) +changelog: + ./scripts/draft-changelog.sh + .PHONY: build sweep test testacc fmt fmtcheck lint tools test-compile doc hooks website website-lint website-test diff --git a/scripts/draft-changelog.sh b/scripts/draft-changelog.sh new file mode 100755 index 0000000000..5dcb1fe473 --- /dev/null +++ b/scripts/draft-changelog.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +# this script can generate draft changelog instead of painful writing it +# run with `make changelog` then copy it! + +version="" +gitTag=$(git describe --tag --abbrev=0) +IFS=. read -r major minor patch <<< "$gitTag" + +major=${major:1} + +type=$1 + +if [[ -z $type ]]; then + read -r -p "Specify semver: major, minor, patch(default) " input + + type=$input + if [[ -z $input ]]; then + type="patch" + fi +fi + +case $type in +v*) + version=$1 + ;; +major) + version="$((major + 1)).0.0" + ;; +minor) + version="$major.$((minor + 1)).0" + ;; +patch) + version="$major.$minor.$((patch+1))" +esac + +diffs=$(git diff --name-only HEAD origin/master | grep "tencentcloud/*") + + +resource="^tencentcloud\/resource_tc_([a-z_]+)\.go$" +data="^tencentcloud\/data_source_tc_([a-z_]+)\.go$" +service="^tencentcloud\/service_([a-z_]+)\.go$" +test="([a-z_]+)_test$" + +items="" + + +for file in ${diffs}; do + module="" + fileType="resource" + if [[ $file =~ $resource ]]; then + module="tencentcloud_${BASH_REMATCH[1]}" + elif [[ $file =~ $data ]]; then + fileType="data source" + module="tencentcloud_${BASH_REMATCH[1]}" + elif [[ $file =~ $service ]]; then + module="tencentcloud_${BASH_REMATCH[1]}" + fi + + if [[ $module =~ $test ]]; then + module=${BASH_REMATCH[1]} + fi + if [[ $module != "" ]]; then + item="* $fileType \`$module\`" + if [[ ! $items =~ "$item" ]]; then + items="$items\n$item" + fi + fi + +done + +LANG=en_US +dateStr=$(date +"%B %d, %Y") + +template=" +## $version $dateStr +\n +\nFEATURES: +\nDEPRECATED: +\nENHANCEMENTS: +\nBUGFIXES: +\nCOMMON: +\n +$items +\n +" + +echo $template \ No newline at end of file From 96f9b6b8aa8cb737b1994392bfa88546dd7d82e8 Mon Sep 17 00:00:00 2001 From: Kagashino Date: Wed, 1 Jun 2022 20:08:55 +0800 Subject: [PATCH 2/2] fix: draft-changelog diff ref --- scripts/draft-changelog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/draft-changelog.sh b/scripts/draft-changelog.sh index 5dcb1fe473..7f3692fee0 100755 --- a/scripts/draft-changelog.sh +++ b/scripts/draft-changelog.sh @@ -34,7 +34,7 @@ patch) version="$major.$minor.$((patch+1))" esac -diffs=$(git diff --name-only HEAD origin/master | grep "tencentcloud/*") +diffs=$(git diff --name-only HEAD $gitTag | grep "tencentcloud/*") resource="^tencentcloud\/resource_tc_([a-z_]+)\.go$"