From 6c4a7ddfcc41812e4a78402fb35fdcfecc1752fb Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Wed, 8 Sep 2021 00:23:29 +0200 Subject: [PATCH] feat: Add basic logic for changelog generation (#923) --- .chglog/CHANGELOG.tpl.md | 22 +++++++++++++++ .chglog/config.yml | 27 ++++++++++++++++++ .github/workflows/apps.release.yaml | 2 +- .github/workflows/apps.test.yaml | 2 +- tools/build-release.sh | 44 ++++++++++++++++++++++++++--- 5 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 .chglog/CHANGELOG.tpl.md create mode 100644 .chglog/config.yml diff --git a/.chglog/CHANGELOG.tpl.md b/.chglog/CHANGELOG.tpl.md new file mode 100644 index 00000000000..c989a891056 --- /dev/null +++ b/.chglog/CHANGELOG.tpl.md @@ -0,0 +1,22 @@ +{{ range .Versions }} + +## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }}) + +{{ range .CommitGroups -}} +### {{ .Title }} + +{{ range .Commits -}} +* {{ .Subject }} +{{ end }} +{{ end -}} + +{{- if .NoteGroups -}} +{{ range .NoteGroups -}} +### {{ .Title }} + +{{ range .Notes }} +{{ .Body }} +{{ end }} +{{ end -}} +{{ end -}} +{{ end -}} diff --git a/.chglog/config.yml b/.chglog/config.yml new file mode 100644 index 00000000000..8b127687d92 --- /dev/null +++ b/.chglog/config.yml @@ -0,0 +1,27 @@ +style: github +template: CHANGELOG.tpl.md +info: + title: CHANGELOG + repository_url: https://github.com/truecharts/apps +options: + commits: + # filters: + # Type: + # - feat + # - fix + # - perf + # - refactor + commit_groups: + # title_maps: + # feat: Features + # fix: Bug Fixes + # perf: Performance Improvements + # refactor: Code Refactoring + header: + pattern: "^(\\w*)\\:\\s(.*)$" + pattern_maps: + - Type + - Subject + notes: + keywords: + - BREAKING CHANGE diff --git a/.github/workflows/apps.release.yaml b/.github/workflows/apps.release.yaml index 9ab15eb5845..d9e2c9ee3d3 100644 --- a/.github/workflows/apps.release.yaml +++ b/.github/workflows/apps.release.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest concurrency: gitpush container: - image: ghcr.io/truecharts/truecharts-release:v1.0.0 + image: ghcr.io/truecharts/truecharts-release:v1.2.0 steps: - name: Cache helm repo cache id: cache diff --git a/.github/workflows/apps.test.yaml b/.github/workflows/apps.test.yaml index 514912c1b6d..ebb765c1707 100644 --- a/.github/workflows/apps.test.yaml +++ b/.github/workflows/apps.test.yaml @@ -196,7 +196,7 @@ jobs: release-test: runs-on: ubuntu-latest container: - image: ghcr.io/truecharts/truecharts-release:v1.0.0 + image: ghcr.io/truecharts/truecharts-release:v1.2.0 steps: - name: Cache helm repo cache id: cache diff --git a/tools/build-release.sh b/tools/build-release.sh index 68ac84f2ccb..1e03d215701 100755 --- a/tools/build-release.sh +++ b/tools/build-release.sh @@ -78,6 +78,7 @@ main() { chartversion=$(cat ${chart}/Chart.yaml | grep "^version: " | awk -F" " '{ print $2 }') chartname=$(basename ${chart}) train=$(basename $(dirname "$chart")) + create_changelog "$chart" "$chartname" "$train" "$chartversion" generate_docs "$chart" "$chartname" "$train" "$chartversion" copy_docs "$chart" "$chartname" "$train" "$chartversion" helm dependency update "${chart}" --skip-refresh @@ -98,6 +99,14 @@ main() { release_charts update_index fi + for chart in "${changed_charts[@]}"; do + if [[ -d "$chart" ]]; then + chartversion=$(cat ${chart}/Chart.yaml | grep "^version: " | awk -F" " '{ print $2 }') + chartname=$(basename ${chart}) + train=$(basename $(dirname "$chart")) + edit_release "$chart" "$chartname" "$train" "$chartversion" + fi + done else echo "Nothing to do. No chart changes detected." fi @@ -105,6 +114,30 @@ main() { popd > /dev/null } +edit_release() { + local chart="$1" + local chartname="$2" + local train="$3" + local chartversion="$4" + # In here we can in the future add code to edit the release notes of the github releases + # For example: using the github API: https://docs.github.com/en/rest/reference/repos#update-a-release + } + +create_changelog() { + local chart="$1" + local chartname="$2" + local train="$3" + local chartversion="$4" + local prevversion="$(git tag -l "${chartname}-*" --sort=-v:refname | head -n 1)" + if [[ -z "$standalone" ]]; then + echo "Generating changelogs for: ${chartname}" + # SCALE "Changelog" containing only last change + git-chglog --next-tag ${chartversion} --tag-filter-pattern ${chartname} --path ${chart} ${chartversion} -o ${chart}/SCALE/CHANGELOG.md + # Append SCALE changelog to actual changelog + cat ${chart}/SCALE/CHANGELOG.md | cat - ${chart}/CHANGELOG.md > temp && mv temp ${chart}/CHANGELOG.md + fi + } + copy_general_docs() { yes | cp -rf index.yaml docs/index.yaml 2>/dev/null || : yes | cp -rf .github/README.md docs/index.md 2>/dev/null || : @@ -176,6 +209,7 @@ copy_docs() { else mkdir -p docs/apps/${train}/${chartname} || echo "app path already exists, continuing..." yes | cp -rf ${chart}/README.md docs/apps/${train}/${chartname}/index.md 2>/dev/null || : + yes | cp -rf ${chart}/CHANGELOG.md docs/apps/${train}/${chartname}/CHANGELOG.md 2>/dev/null || : yes | cp -rf ${chart}/CONFIG.md docs/apps/${train}/${chartname}/CONFIG.md 2>/dev/null || : yes | cp -rf ${chart}/helm-values.md docs/apps/${train}/${chartname}/helm-values.md 2>/dev/null || : sed -i '1s/^/# License
\n\n/' docs/apps/${train}/${chartname}/LICENSE.md 2>/dev/null || : @@ -207,12 +241,14 @@ patch_apps() { local chartversion="$4" local target="catalog/${train}/${chartname}/${chartversion}" echo "Applying SCALE patches for App: ${chartname}" - mv ${target}/SCALE/ix_values.yaml ${target}/ - mv ${target}/SCALE/questions.yaml ${target}/ + rm -rf ${target}/CHANGELOG.md 2>/dev/null || : + mv ${target}/SCALE/CHANGELOG.md ${target}/CHANGELOG.md 2>/dev/null || : + mv ${target}/SCALE/ix_values.yaml ${target}/ 2>/dev/null || : + mv ${target}/SCALE/questions.yaml ${target}/ 2>/dev/null || : cp -rf ${target}/SCALE/templates/* ${target}/templates 2>/dev/null || : mv ${target}/SCALE/item.yaml catalog/${train}/${chartname}/item.yaml - rm -rf ${target}/SCALE - mv ${target}/values.yaml ${target}/test_values.yaml + rm -rf ${target}/SCALE 2>/dev/null || : + mv ${target}/values.yaml ${target}/test_values.yaml 2>/dev/null || : touch ${target}/values.yaml }