From 200097d1bae2d3f0969ff918f3076f82cbc7bea9 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Sun, 12 May 2024 19:41:55 +0300 Subject: [PATCH] fix(docs): fix docs (#21949) 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._ --- .github/scripts/frontmatter.sh | 58 +++++++++++++++++++++++++ .github/workflows/charts-release.yaml | 62 +++++++++++++-------------- 2 files changed, 88 insertions(+), 32 deletions(-) create mode 100755 .github/scripts/frontmatter.sh diff --git a/.github/scripts/frontmatter.sh b/.github/scripts/frontmatter.sh new file mode 100755 index 00000000000..49ec89350cc --- /dev/null +++ b/.github/scripts/frontmatter.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +file_path=$1 +base_cmd="yq --front-matter=process" +# Check if the file has valid front matter + +is_empty() { + if $(echo "$1" | grep -q "^null$"); then + return 0 + fi + + return 1 +} + +is_true() { + if $(echo "$1" | grep -q "^true$"); then + return 0 + fi + + return 1 +} + +update_property() { + local property=$1 + local value=$2 + local file_path=$3 + + $base_cmd -i ".$property = $value" "$file_path" +} + +echo "Checking front matter" +if ! grep -q "^---$" "$file_path"; then + echo "Front matter (start) not found, adding it" + content=$(cat "$file_path") + echo -e "---\n" >"$file_path" + echo "$content" >>"$file_path" +fi + +# Get the title from the front matter +echo "Checking title" +title=$($base_cmd '.title' "$file_path") +# Check if the title is empty +if is_empty "$title"; then + update_property "title" "Changelog" "$file_path" +fi + +echo "Checking pagefind" +pagefind=$($base_cmd '.pagefind' "$file_path") +if is_empty "$pagefind" || is_true "$pagefind"; then + update_property "pagefind" "false" "$file_path" +fi + +frontmatter=$($base_cmd '.' "$file_path") +# Check if the front matter does end with --- +if [ "${frontmatter: -3}" != "---" ]; then + echo "Front matter (end) not found, adding it" + echo -e "\n---\n" >>"$file_path" +fi diff --git a/.github/workflows/charts-release.yaml b/.github/workflows/charts-release.yaml index 0ac965b5823..7539d89abd9 100644 --- a/.github/workflows/charts-release.yaml +++ b/.github/workflows/charts-release.yaml @@ -76,7 +76,7 @@ jobs: - name: Prep go-yq run: | - wget https://github.com/mikefarah/yq/releases/download/v4.26.1/yq_linux_amd64 -O /usr/local/bin/go-yq && chmod +x /usr/local/bin/go-yq + wget https://github.com/mikefarah/yq/releases/download/v4.44.1/yq_linux_amd64 -O /usr/local/bin/go-yq && chmod +x /usr/local/bin/go-yq # Optional step if GPG signing is used - name: Prepare GPG key @@ -178,10 +178,10 @@ jobs: # remove old docs everywhere and recreate based on charts repo rm -rf website/src/content/docs/charts/*/${chart} || : mkdir -p website/src/content/docs/charts/${train}/${chart} || echo "chart path already exists, continuing..." - yes | cp -rf charts/${train}/${chart}/docs/* website/src/content/docs/charts/${train}/${chart}/ 2>/dev/null || : - yes | cp -rf charts/${train}/${chart}/icon.webp website/public/img/hotlink-ok/chart-icons/${chart}.webp 2>/dev/null || : - yes | cp -rf charts/${train}/${chart}/icon-small.webp website/public/img/hotlink-ok/chart-icons-small/${chart}.webp 2>/dev/null || : - yes | cp -rf charts/${train}/${chart}/screenshots/* website/public/img/hotlink-ok/chart-screenshots/${chart}/ 2>/dev/null || : + cp -rf charts/${train}/${chart}/docs/* website/src/content/docs/charts/${train}/${chart}/ 2>/dev/null || : + cp -rf charts/${train}/${chart}/icon.webp website/public/img/hotlink-ok/chart-icons/${chart}.webp 2>/dev/null || : + cp -rf charts/${train}/${chart}/icon-small.webp website/public/img/hotlink-ok/chart-icons-small/${chart}.webp 2>/dev/null || : + cp -rf charts/${train}/${chart}/screenshots/* website/public/img/hotlink-ok/chart-screenshots/${chart}/ 2>/dev/null || : echo "Copying back kept docs..." # Copy over kept documents @@ -194,46 +194,44 @@ jobs: # 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..." - sed -i '1s/^/---\ntitle: Changelog\npagefind: false\n---\n\n/' "website/src/content/docs/charts/${train}/${chart}/CHANGELOG.md" || echo "failed to add changelog header..." + ./.github/scripts/frontmatter.sh "website/src/content/docs/charts/${train}/${chart}/CHANGELOG.md" echo "Creating index.md..." touch website/src/content/docs/charts/${train}/${chart}/index.md - ( - echo "---" - echo "title: ${chart}" - echo "---" - ) >> website/src/content/docs/charts/${train}/${chart}/index.md - echo "" >> website/src/content/docs/charts/${train}/${chart}/index.md - version=$(cat charts/${train}/${chart}/Chart.yaml | grep "^version: " | awk -F" " '{ print $2 }') - appversion=$(cat charts/${train}/${chart}/Chart.yaml | grep "^appVersion: " | awk -F" " '{ print $2 }') + # Add front matter + echo "---" >> website/src/content/docs/charts/${train}/${chart}/index.md + yq -i --front-matter=process ".title = ${chart}" website/src/content/docs/charts/${train}/${chart}/index.md + echo -e "---\n" >> website/src/content/docs/charts/${train}/${chart}/index.md + + # Gather data + version=$(yq '.version' charts/${train}/${chart}/Chart.yaml) + appversion=$(yq '.appVersion' charts/${train}/${chart}/Chart.yaml) + description=$(yq -r '.description' charts/${train}/${chart}/Chart.yaml) + sources=$(yq -r '.sources' charts/${train}/${chart}/Chart.yaml) + + # Add the data to the index.md file echo '![Version: '"${version}"'](https://img.shields.io/badge/Version-'"${version}"'-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: '"${appversion}"'](https://img.shields.io/badge/AppVersion-'"${appversion}"'-informational?style=flat-square)' >> website/src/content/docs/charts/${train}/${chart}/index.md echo "" >> website/src/content/docs/charts/${train}/${chart}/index.md - cat charts/${train}/${chart}/Chart.yaml | yq .description -r >> website/src/content/docs/charts/${train}/${chart}/index.md - echo "" >> website/src/content/docs/charts/${train}/${chart}/index.md - echo "## Chart Sources" >> website/src/content/docs/charts/${train}/${chart}/index.md - echo "" >> website/src/content/docs/charts/${train}/${chart}/index.md - cat charts/${train}/${chart}/Chart.yaml | go-yq .sources -r >> website/src/content/docs/charts/${train}/${chart}/index.md - echo "" >> website/src/content/docs/charts/${train}/${chart}/index.md - echo "## Available Documentation" >> website/src/content/docs/charts/${train}/${chart}/index.md - echo "" >> website/src/content/docs/charts/${train}/${chart}/index.md + echo -e "$description\n" >> website/src/content/docs/charts/${train}/${chart}/index.md + echo -e "## Chart Sources\n" >> website/src/content/docs/charts/${train}/${chart}/index.md + echo -e "$sources\n" >> website/src/content/docs/charts/${train}/${chart}/index.md + echo -e "## Available Documentation\n" >> website/src/content/docs/charts/${train}/${chart}/index.md + echo "Iterating over all files in the docs directory..." # Iterate over all files in the docs directory for file in website/src/content/docs/charts/${train}/${chart}/*.md*; do # Extract the file name and first line from each file filename=$(basename "${file}") echo "Found doc file: ${file}" + ok_title="false" echo "Getting the first line" - h=$(head -n 1 "${file}") - echo "The first line is: ${h}. Checking validity..." - # Check if the first line has --- - if [[ "${h}" == "---" ]]; then - echo "First line is ---, continuing..." + if ! grep -q "^---$" "${file}"; then ok_title="true" - elif [[ "${h}" == "# "* ]]; then - echo "First line is #..." + elif ! grep -q "^# " "${file}"; then ok_title="false" fi + if [ ${ok_title} == "false" ]; then echo "Doc title should use front matter and not # for title, for example" echo "---" @@ -241,8 +239,9 @@ jobs: echo "---" else echo "Not bad title found, continuing..." - title=$(cat "${file}" | grep "title: " | sed 's/title: //' | head -n 1) + title=$(yq '.title' ${file} | head -n 1) echo "The title is: ${title}" + # Create a markdown link using the file name and title filename="${filename##*/}" filenameURL=${filename%.*} @@ -256,8 +255,7 @@ jobs: fi done echo "" >> website/src/content/docs/charts/${train}/${chart}/index.md - echo "## Readme Content" >> website/src/content/docs/charts/${train}/${chart}/index.md - echo "" >> website/src/content/docs/charts/${train}/${chart}/index.md + echo -e "## Readme Content\n" >> website/src/content/docs/charts/${train}/${chart}/index.md tail -n +4 "charts/${train}/${chart}/README.md" >> website/src/content/docs/charts/${train}/${chart}/readmetmp.md sed -i 's/##/###/' "website/src/content/docs/charts/${train}/${chart}/readmetmp.md" cat "website/src/content/docs/charts/${train}/${chart}/readmetmp.md" >> "website/src/content/docs/charts/${train}/${chart}/index.md"