From 2c6cab665994e6ccf9daf76bd5f7089da488d96d Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Thu, 30 May 2024 17:03:23 +0300 Subject: [PATCH] feat: Use remade changelog generator (#22476) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes # **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [ ] ⚠️ My changes generate no new warnings - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning - [ ] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):` or `chore(chart-name):` **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Signed-off-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Signed-off-by: Kjeld Schouten Signed-off-by: Kjeld Schouten Co-authored-by: Kjeld Schouten --- .github/scripts/chart-docs.sh | 55 +-------------------------- .github/scripts/frontmatter.sh | 24 ------------ .github/workflows/charts-release.yaml | 38 +++++++++--------- templates/CHANGELOG.md.tmpl | 18 +++++++++ 4 files changed, 39 insertions(+), 96 deletions(-) delete mode 100755 .github/scripts/frontmatter.sh create mode 100644 templates/CHANGELOG.md.tmpl diff --git a/.github/scripts/chart-docs.sh b/.github/scripts/chart-docs.sh index 05f956c5d75..b7872e55dfb 100755 --- a/.github/scripts/chart-docs.sh +++ b/.github/scripts/chart-docs.sh @@ -2,35 +2,11 @@ [ "$DEBUG" == 'true' ] && set -x [ "$STRICT" == 'true' ] && set -e -make_sure_structure_is_there() { - local train="$1" - local chart="$2" - - mkdir -p tmp/website/src/content/docs/charts/${train}/${chart} || echo "chart path already exists, continuing..." - - echo "Checking if website/src/content/docs/charts/${train}/${chart}/CHANGELOG.md exists" - if [ -f "website/src/content/docs/charts/${train}/${chart}/CHANGELOG.md" ]; then - echo "CHANGELOG.md already exists, continuing..." - return 0 - fi - - mkdir -p "website/src/content/docs/charts/${train}/${chart}" || echo "chart path already exists, continuing..." - touch "website/src/content/docs/charts/${train}/${chart}/CHANGELOG.md" -} - -keep_safe_docs() { - local train="$1" - local chart="$2" - - echo "Keeping some docs safe..." - mv -f website/src/content/docs/charts/${train}/${chart}/CHANGELOG.md tmp/website/src/content/docs/charts/${train}/${chart}/CHANGELOG.md || : -} - remove_old_docs() { local train="$1" local chart="$2" - echo "Removing old docs and recreating based on charts repo..." + echo "Removing old docs and recreating based on website repo..." rm -rf website/src/content/docs/charts/*/${chart} || : mkdir -p website/src/content/docs/charts/${train}/${chart} || echo "chart path already exists, continuing..." } @@ -46,30 +22,6 @@ copy_new_docs() { cp -rf charts/${train}/${chart}/screenshots/* website/public/img/hotlink-ok/chart-screenshots/${chart}/ 2>/dev/null || : } -copy_safe_docs() { - local train="$1" - local chart="$2" - - echo "copying safe docs to website for ${chart}" - cp -rf tmp/website/src/content/docs/charts/${train}/${chart}/* website/src/content/docs/charts/${train}/${chart}/ 2>/dev/null || : -} - -append_scale_changelog() { - local train="$1" - local chart="$2" - - echo "appending SCALE changelog to actual changelog..." - # Remove header from changelog - sed -i '/^---$/,/^---$/d' "website/src/content/docs/charts/${train}/${chart}/CHANGELOG.md" - # Prepend app-changelog to changelog - cat "charts/${train}/${chart}/app-changelog.md" | - cat - "website/src/content/docs/charts/${train}/${chart}/CHANGELOG.md" >temp && - mv temp "website/src/content/docs/charts/${train}/${chart}/CHANGELOG.md" - - echo "Adding changelog header..." - # ./.github/scripts/frontmatter.sh "website/src/content/docs/charts/${train}/${chart}/CHANGELOG.md" -} - check_and_fix_title() { local file="$1" @@ -187,13 +139,8 @@ main() { echo "copying docs to website for ${chart}" - make_sure_structure_is_there "$train" "$chart" - keep_safe_docs "$train" "$chart" remove_old_docs "$train" "$chart" copy_new_docs "$train" "$chart" - copy_safe_docs "$train" "$chart" - append_scale_changelog "$train" "$chart" - # ./.github/scripts/frontmatter.sh "website/src/content/docs/charts/${train}/${chart}/CHANGELOG.md" process_index "$train" "$chart" echo "Finished processing ${chart}" diff --git a/.github/scripts/frontmatter.sh b/.github/scripts/frontmatter.sh deleted file mode 100755 index 000adf906ba..00000000000 --- a/.github/scripts/frontmatter.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -[ "$DEBUG" == 'true' ] && set -x -[ "$STRICT" == 'true' ] && set -e - -file_path="$1" -base_cmd="go-yq --front-matter=process" - -echo "Checking front matter" -if ! head -n 1 "$file_path" | grep -q "^---$"; then - echo "Front matter (start) not found, adding it" - # Dont trace content, as its usually too large - [ "$DEBUG" == "true" ] && set +x - (echo -e "---\n---\n"; cat "$file_path") >"$file_path.tmp" && mv "$file_path.tmp" "$file_path" - [ "$DEBUG" == "true" ] && set -x -fi - -wc -l $file_path - -# Get the title from the front matter -echo "Updating title" -$base_cmd -i '.title="Changelog"' "$file_path" - -echo "Updating pagefind" -$base_cmd -i '.pagefind=false' "$file_path" diff --git a/.github/workflows/charts-release.yaml b/.github/workflows/charts-release.yaml index 35ef9ee4eeb..491a0ebc174 100644 --- a/.github/workflows/charts-release.yaml +++ b/.github/workflows/charts-release.yaml @@ -36,11 +36,6 @@ jobs: # Fix sh files to always be executable find . -name '*.sh' | xargs chmod +x - - name: Clean Questions - shell: bash - run: | - find ./helm -type f -name 'questions.yaml' -exec rm {} \; - - name: Commit Helm Changes run: | rm -rf helm/charts @@ -57,20 +52,29 @@ jobs: git push cd - - - name: Fix Pre-Commit issues + - name: Cache Changelog + id: cache-changelog + uses: actions/cache@v4 + with: + path: changelog.json.gz + key: changelog-json + + - name: Generate Changelog shell: bash - if: | - steps.collect-changes.outputs.changesDetectedAfterTag == 'true' run: | - echo "Running pre-commit test-and-cleanup..." - pre-commit run --all ||: - # Fix sh files to always be executable - find . -name '*.sh' | xargs chmod +x + export REPO_PATH="./" + export TEMPLATE_PATH="templates/CHANGELOG.md.tmpl" + export CHARTS_DIR="./charts" + export JSON_FILE="changelog.json" + if [ -f "$JSON_FILE.gz" ]; then + gunzip "$JSON_FILE.gz" --force # Force overwrite if file already exists + fi + + ./charttool "$REPO_PATH" "$TEMPLATE_PATH" "$CHARTS_DIR" + gzip "$JSON_FILE" --best - name: Checkout uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 - if: | - steps.collect-changes.outputs.changesDetectedAfterTag == 'true' with: fetch-depth: 1 repository: truecharts/website @@ -78,8 +82,6 @@ jobs: path: website - name: Copy docs to website - if: | - steps.collect-changes.outputs.changesDetectedAfterTag == 'true' shell: bash run: | #!/bin/bash @@ -98,12 +100,12 @@ jobs: for i in "${CHARTS[@]}" do + # TODO: Remove any changelog stuff from this script + # TODO: Move all website docs structure generation to charttool ./.github/scripts/chart-docs.sh "$i" done - name: Commit Website Changes - if: | - steps.collect-changes.outputs.changesDetected == 'true' run: | cd website git config user.name "TrueCharts-Bot" diff --git a/templates/CHANGELOG.md.tmpl b/templates/CHANGELOG.md.tmpl new file mode 100644 index 00000000000..03115449827 --- /dev/null +++ b/templates/CHANGELOG.md.tmpl @@ -0,0 +1,18 @@ +--- +title: Changelog +pagefind: false +--- + +All history information can be found at [Github History](https://github.com/truecharts/charts/commits/master/charts/{{ .Train }}/{{ .Name }}) + +:::tip + +If you need more than 2 scrolls to find your current version, please consider updating the chart as soon as possible. + +::: +{{ range $key := .SortedVersions }} +## {{ $key }} • [Train: {{ (index $.Versions $key).Train }}] +{{ range $commit := (index $.Versions $key).SortedCommits }} +- {{ printf "%s • [`%s`](https://github.com/truecharts/charts/commit/%s) • [@%s] (%s)" $commit.Message (slice $commit.CommitHash 0 7) $commit.CommitHash $commit.Author.Name $commit.Author.Date -}} +{{ end }} +{{ end -}}