TrueChartsClone/.github/scripts/chart-docs.sh

189 lines
5.7 KiB
Bash
Raw Normal View History

2024-05-12 17:57:58 +00:00
#!/bin/bash
[ "$DEBUG" == 'true' ] && set -x
2024-05-12 18:34:56 +00:00
[ "$STRICT" == 'true' ] && set -e
2024-05-12 17:57:58 +00:00
2024-06-09 10:44:40 +00:00
docs_base="website/src/content/docs/charts"
tmp_docs_base="tmpwebsite/src/content/docs/charts"
safe_docs=(
"CHANGELOG.md"
)
keep_docs_safe() {
local train="$1"
local chart="$2"
2024-06-09 10:51:46 +00:00
mkdir -p "$tmp_docs_base/${train}/${chart}"
2024-06-09 10:44:40 +00:00
echo "Keeping some docs safe..."
for doc in "${safe_docs[@]}"; do
if [ ! -f "$docs_base/${train}/${chart}/${doc}" ]; then
2024-06-09 10:51:46 +00:00
echo "Doc [$doc] does not exist, cannot keep it safe. Skipping."
2024-06-09 10:44:40 +00:00
continue
fi
mv "$docs_base/${train}/${chart}/${doc}" "$tmp_docs_base/${train}/${chart}/${doc}"
done
}
restore_safe_docs() {
local train="$1"
local chart="$2"
echo "Restoring safe docs..."
for doc in "${safe_docs[@]}"; do
if [ ! -f "$tmp_docs_base/${train}/${chart}/${doc}" ]; then
2024-06-09 10:51:46 +00:00
echo "Doc [$doc] does not exist, cannot restore it. Skipping."
2024-06-09 10:44:40 +00:00
continue
fi
mv "$tmp_docs_base/${train}/${chart}/${doc}" "$docs_base/${train}/${chart}/${doc}"
done
}
2024-05-12 17:57:58 +00:00
remove_old_docs() {
local train="$1"
local chart="$2"
feat: Use remade changelog generator (#22476) **Description** <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> ⚒️ Fixes # <!--(issue)--> **⚙️ 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?** <!-- Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration --> **📃 Notes:** <!-- Please enter any other relevant information here --> **✔️ 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 <info@kjeldschouten.nl> Signed-off-by: Kjeld Schouten <kjeld@schouten-lebbing.nl> Co-authored-by: Kjeld Schouten <kjeld@schouten-lebbing.nl>
2024-05-30 14:03:23 +00:00
echo "Removing old docs and recreating based on website repo..."
2024-06-09 10:44:40 +00:00
rm -rf $docs_base/*/${chart} || :
mkdir -p $docs_base/${train}/${chart} || echo "chart path already exists, continuing..."
2024-05-12 17:57:58 +00:00
}
copy_new_docs() {
local $train="$1"
local chart="$2"
echo "copying new docs to website for ${chart}"
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 || :
}
check_and_fix_title() {
local file="$1"
echo "Checking title..."
ok_title="false"
echo "Getting the first line"
if grep -q "^---$" "${file}"; then
ok_title="true"
elif grep -q "^# " "${file}"; then
echo "Found old-style title, fixing..."
title=$(grep "^# " "${file}" | cut -d " " -f 2-)
# Remove title
sed -i "s/^# ${title}//" "${file}"
content=$(cat "${file}")
echo -e "---\ntitle: ${title}\n---\n${content}" >"${file}"
ok_title="true"
else
ok_title="false"
fi
if [ ${ok_title} == "false" ]; then
echo "Doc title should use front matter and not # for title, for example"
echo "---"
echo "title: some title"
echo "---"
return 1
fi
echo "Title is ok"
return 0
}
process_index() {
local train="$1"
local chart="$2"
2024-06-09 10:44:40 +00:00
local index_path="$docs_base/${train}/${chart}/index.md"
2024-05-12 17:57:58 +00:00
local chart_yaml_path="charts/${train}/${chart}/Chart.yaml"
echo "Creating index.md..."
2024-06-09 10:44:40 +00:00
touch $docs_base/${train}/${chart}/index.md
2024-05-12 17:57:58 +00:00
echo "Adding front matter to index.md..."
echo "---" >>${index_path}
2024-05-12 19:46:23 +00:00
go-yq -i --front-matter=process '.title="'${chart}'"' ${index_path}
2024-05-12 17:57:58 +00:00
echo -e "---\n" >>${index_path}
echo "Getting data from Chart.yaml..."
2024-05-12 19:46:23 +00:00
version=$(go-yq '.version' ${chart_yaml_path})
appversion=$(go-yq '.appVersion' ${chart_yaml_path})
description=$(go-yq -r '.description' ${chart_yaml_path})
sources=$(go-yq -r '.sources' ${chart_yaml_path})
2024-05-12 17:57:58 +00:00
echo "Adding 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)' >>${index_path}
echo "" >>${index_path}
echo -e "$description\n" >>${index_path}
echo -e "## Chart Sources\n" >>${index_path}
echo -e "$sources\n" >>${index_path}
echo -e "## Available Documentation\n" >>${index_path}
echo "Iterating over all files in the docs directory..."
2024-06-09 10:44:40 +00:00
for f in $docs_base/${train}/${chart}/*.md*; do
2024-06-09 10:35:13 +00:00
echo "Checking file: ${f}"
filename=$(basename "${f}")
2024-05-12 17:57:58 +00:00
# If title is not ok, skip
2024-06-09 10:35:13 +00:00
if ! check_and_fix_title "${f}"; then
echo "Title is not ok, skipping..."
2024-05-12 17:57:58 +00:00
continue
fi
# If file is index.md, skip
if [ "${filename}" == "index.md" ]; then
2024-06-09 10:35:13 +00:00
echo "File is index.md, not adding it to the links"
2024-05-12 17:57:58 +00:00
continue
fi
2024-06-09 10:35:13 +00:00
title=$(go-yq --front-matter=process '.title' ${f} | head -n 1)
2024-05-12 17:57:58 +00:00
echo "The title is: ${title}"
echo "Generating markdown links"
filename="${filename##*/}"
filenameURL=${filename%.*}
filenameURL=${filenameURL,,}
link="[**${title}**](./${filenameURL})"
echo "The link is: ${link}"
echo "- ${link}" >>${index_path}
done
echo "" >>${index_path}
2024-05-25 10:30:16 +00:00
echo "" >>${index_path}
echo "---" >>${index_path}
echo "" >>${index_path}
2024-06-09 10:44:40 +00:00
echo -e "## Readme\n" >>$docs_base/${train}/${chart}/index.md
tail -n +4 "charts/${train}/${chart}/README.md" >>$docs_base/${train}/${chart}/readmetmp.md
sed -i 's/##/###/' "$docs_base/${train}/${chart}/readmetmp.md"
cat "$docs_base/${train}/${chart}/readmetmp.md" >>"$docs_base/${train}/${chart}/index.md"
rm "$docs_base/${train}/${chart}/readmetmp.md" || echo "couldnt delete readmetmp.md"
2024-05-12 17:57:58 +00:00
}
main() {
local chart_path="$1"
IFS='/' read -r -a chart_parts <<<"$chart_path"
train=${chart_parts[0]}
chart=${chart_parts[1]}
if [ ! -f "charts/${train}"/"${chart}/Chart.yaml" ]; then
echo "chart path does not exist, skipping..."
continue
fi
echo "copying docs to website for ${chart}"
2024-06-09 10:44:40 +00:00
keep_docs_safe "$train" "$chart"
2024-05-12 17:57:58 +00:00
remove_old_docs "$train" "$chart"
copy_new_docs "$train" "$chart"
process_index "$train" "$chart"
2024-06-09 10:44:40 +00:00
restore_safe_docs "$train" "$chart"
2024-05-12 17:57:58 +00:00
echo "Finished processing ${chart}"
}
main "$1"