From 3c564a0caf78e99a995bdf42e4010ed65642f8cd Mon Sep 17 00:00:00 2001 From: Sergey Grigoriev Date: Thu, 4 Jul 2024 20:54:45 +0200 Subject: [PATCH] chore: .scripts/convert-readme.sh updated --- .scripts/convert-readme.sh | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/.scripts/convert-readme.sh b/.scripts/convert-readme.sh index a311cbe..413bcb1 100755 --- a/.scripts/convert-readme.sh +++ b/.scripts/convert-readme.sh @@ -2,25 +2,45 @@ set -e +# Check if a command is installed +function check_command() { + if ! command -v "$1" &> /dev/null; then + echo -e "\033[0;31m $1 is not installed! \033[0m" >&2 + echo -e "\033[0;31m Help for About page will not be generated! \033[0m" >&2 + + if [ -n "$FAIL_ON_CHECK_COMMANDS" ]; then + exit 1 + else + exit 0 + fi + fi +} + +# Check if required commands are installed +check_command jq +check_command curl +check_command awk + INPUT_FILE="${1:-README.md}" OUTPUT_FILE="${2:-README.html}" # Convert the markdown file to a JSON payload -jq -R -s '{"mode": "gfm", "text": .}' < "$INPUT_FILE" > payload.json +JSON_PAYLOAD=$(jq -R -s '{"mode": "gfm", "text": .}' < "$INPUT_FILE") # Send the JSON payload to the GitHub API -curl -L \ +CURL_OUTPUT=$(curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/markdown \ - -d @payload.json > "$OUTPUT_FILE" + -d "$JSON_PAYLOAD") -# Remove the temporary JSON payload -rm payload.json - -# Remove the Build and Installation sections from readme -awk ' +# Process the curl output with awk to remove the Build, Installation and Changelog sections +MODIFIED_CONTENT=$(echo "$CURL_OUTPUT" | awk ' /

Build<\/h2>/ {skip=1; next} /

Polarion configuration<\/h2>/ {skip=0} -!skip' "$OUTPUT_FILE" > "$OUTPUT_FILE.tmp" && mv "$OUTPUT_FILE.tmp" "$OUTPUT_FILE" +/

Changelog<\/h2>/ {skip=1; next} +!skip') + +# Write the modified content to the output file +echo "$MODIFIED_CONTENT" > "$OUTPUT_FILE"