Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move some of v2 features to v1 #286

Merged
merged 7 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .github/workflows/go-application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,28 @@ jobs:
run: make helm-readme

- name: Verify that there are no changes
run: git diff --exit-code || echo "README.md is not up to date. Please use helm-readme and commit the changes."
run: git diff --exit-code || (echo "README.md is not up to date. Please use helm-readme and commit the changes." && exit 1)

- name: Print changes
run: git diff
if: failure()

verify-makefile-readme:
name: Verify that Makefile section of README is up to date
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Generate README
run: make update-readme-descriptions

- name: Verify that there are no changes
run: git diff --exit-code || (echo "README.md is not up to date. Please use makefile-readme and commit the changes." && exit 1)

- name: Print changes
run: git diff
if: failure()
lint-helm-chart:
name: Lint Helm chart
runs-on: ubuntu-20.04
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ _debug*.yaml

# Readme generator files
helm-generator/

# V2 config
config.yml
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,15 @@ clean-elasticsearch:
echo "" ;\
done

#: Update Makefile descriptions in main README.md
update-readme-descriptions:
./scripts/add_descriptions_to_readme.sh

#: Upgrades all dependencies
upgrade-dependencies:
go get -u ./...
go mod tidy


#: Shows info about available commands
help:
@grep -B1 -E "^[a-zA-Z0-9_-]+\:([^\=]|$$)" Makefile \
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ All configuration variables can be checked in the [config directory](./config/).
- `make build-linux`: Builds a binary executable for Linux.
- `make build-darwin`: Builds a binary executable for Darwin.
- `make build-windows`: Builds a binary executable for Windows.
- `make build-linux-arm`: Builds a binary executable for Linux ARM.
- `make build-docker`: Builds a Docker image for the Go Exporter application.
- `make build-docker-multi`: Builds a multi-arch Docker image (`amd64` and `arm64`).
- `make clean`: Deletes all binary executables in the out directory.
Expand All @@ -128,6 +129,8 @@ All configuration variables can be checked in the [config directory](./config/).
- `make install-helm-readme`: Installs readme-generator-for-helm tool.
- `make helm-readme`: Generates Helm chart README.md file.
- `make clean-elasticsearch`: Cleans Elasticsearch data, works only with default ES port. The command may take a very long time to complete.
- `make update-readme-descriptions`: Update Makefile descriptions in main README.md.
- `make upgrade-dependencies`: Upgrades all dependencies.
- `make help`: Shows info about available commands.

<!--- **************************************************** --->
Expand Down
4 changes: 2 additions & 2 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: logstash-exporter
description: Prometheus exporter for Logstash written in Go
type: application
version: "1.0.2"
appVersion: "1.0.2"
version: "1.6.1"
appVersion: "1.6.1"
167 changes: 72 additions & 95 deletions scripts/add_descriptions_to_readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,128 +2,105 @@

# execute: ./scripts/add_descriptions_to_readme.sh

# define new line character to be u"$SED_COMMAND" in `"$SED_COMMAND"`
nl='
'

SED_COMMAND="sed"

if [[ "$OSTYPE" == "darwin"* ]]; then
SED_COMMAND="gsed"
fi

# enable regex (see: https://stackoverflow.com/a/42740385)
shopt -s extglob

scriptName="$(dirname "$0")/$(basename "$0")"

function getHelp() { # get descriptions and commands from Makefile
i=0
commands=()
descriptions=()

while read -r line; do
if (( i % 2 == 0 ));
then
descriptions+=( "$(echo $line | sed 's/#:[ ]*//')" )
else
commands+=( $(echo "$line" | cut -d : -f 1) )
fi

((i++))
done < <(
# https://stackoverflow.com/a/59087509
grep -B1 -E "^[a-zA-Z0-9_-]+\:([^\=]|$)" ./Makefile \
| grep -v -- --
)
i=0
commands=()
descriptions=()

while read -r line; do
if (( i % 2 == 0 ));
then
descriptions+=( "${line//#:*( )}" )
else
commands+=( "$(echo "$line" | cut -d : -f 1)" )
fi
((i++))
done < <(
# https://stackoverflow.com/a/59087509
grep -B1 -E "^[a-zA-Z0-9_-]+:([^\=]|$)" ./Makefile \
| grep -v -- --
)
}

FILE=README.md

# returns `commands` and `descriptions` arrays
getHelp

let startLine=$(grep -n "^#### Available Commands" $FILE | cut -d : -f 1)+2
let endLine=$(grep -n "^#### File Structure" $FILE | cut -d : -f 1)-2

# Updates "Available Commands" section:
startLine=$(( $( grep -n "^#### Available Commands" $FILE | cut -d : -f 1 ) + 2 ))
endLine=$(( $( grep -n "^#### File Structure" $FILE | cut -d : -f 1 ) - 2 ))

# Updates "Available Commands" section
if (( startLine <= endLine));
then
$(sed -i "$startLine,${endLine}d" $FILE) # deletion of previous descriptions
then
# Deletes previous descriptions
"$SED_COMMAND" -i "$startLine,${endLine}d" "$FILE"
fi

function printAvailableCommands() {
curLine=$startLine
stringToWrite="<!--- GENERATED by $scriptName --->"
let commentLen=${#stringToWrite}-11
i=0

$(sed -i "${curLine}i\\${stringToWrite}" $FILE)
let curLine++

$(sed -i "${curLine}i\\ " $FILE) # empty line
let curLine++

while (( $i < ${#commands[@]} ))
do

stringToWrite="- \`make ${commands[$i]}\`: ${descriptions[$i]}."
$(sed -i "${curLine}i\\${stringToWrite}" $FILE)
let curLine++

let i++
done

$(sed -i "${curLine}i\\ " $FILE) # empty line
let curLine++

stringToWrite="<!--- $( eval $( echo printf '"\*%.0s"' {1..$commentLen} ) ) --->" # multiple '*'
$(sed -i "${curLine}i\\${stringToWrite}" $FILE)
let curLine++

function createMultipleAsterisks() {
numOfAsterisks=$1
asterisks=$( eval printf "\*%.0s" "{1..${numOfAsterisks}}" )
echo "$asterisks"
}

echo 'Updating "Available Commands" section...'

printAvailableCommands

# Updates "Example Usage" section:

let startLine=$(grep -n "^#### Example Usage" $FILE | cut -d : -f 1)+2
let endLine=$(grep -n "^## Helper Scripts" $FILE | cut -d : -f 1)-2

if (( startLine <= endLine));
then
$(sed -i "$startLine,${endLine}d" $FILE) # deletion of previous descriptions
fi
function printAvailableCommands() {
curLine=$startLine
stringToWrite="<!--- GENERATED by $scriptName --->"
commentLen=$(( ${#stringToWrite} - 11 ))
i=0

function printExampleUsage() {
curLine=$startLine
stringToWrite="<!--- GENERATED by $scriptName --->"
let commentLen=${#stringToWrite}-11
i=0
"$SED_COMMAND" -i "${curLine}i\\${stringToWrite}" "$FILE"

$(sed -i "${curLine}i\\${stringToWrite}" $FILE)
let curLine++
# https://www.shellcheck.net/wiki/SC2219
(( curLine++ )) || true

$(sed -i "${curLine}i\\ " $FILE) # empty line
let curLine++
# empty line
"$SED_COMMAND" -i "${curLine}i${nl}" "$FILE"

while (( $i < ${#commands[@]} ))
do
stringToWrite="${descriptions[$i]}:"
$(sed -i "${curLine}i\\${stringToWrite}" $FILE)
let curLine++
(( curLine++ )) || true

$(sed -i "${curLine}i\\ " $FILE)
let curLine++
echo 'Writing the following commands with their descriptions:'
while (( i < ${#commands[@]} ))
do
stringToWrite="- \`make ${commands[$i]}\`: ${descriptions[$i]}."
stringToWrite=${stringToWrite//\'/\\\'}
echo "$stringToWrite"

stringToWrite=" make ${commands[$i]}" # 4 spaces for tab (DON'T CHANGE IT)
$(sed -i "${curLine}i\\${stringToWrite}" $FILE)
let curLine++
"$SED_COMMAND" -i "${curLine}i\\${stringToWrite}" "$FILE"
(( curLine++ )) || true

$(sed -i "${curLine}i\\ " $FILE)
let curLine++
(( i++ )) || true
done

let i++
done
# empty line
"$SED_COMMAND" -i "${curLine}i${nl}" "$FILE"
(( curLine++ )) || true

stringToWrite="<!--- $( eval $( echo printf '"\*%.0s"' {1..$commentLen} ) ) --->" # multiple '*'
$(sed -i "${curLine}i\\${stringToWrite}" $FILE)
let curLine++
# multiple '*'
asterisks=$(createMultipleAsterisks $commentLen)
stringToWrite="<!--- ${asterisks} --->"
"$SED_COMMAND" -i "${curLine}i\\${stringToWrite}" "$FILE"

(( curLine++ )) || true
}

echo 'Updating "Example Usage" section...'
echo 'Updating "Available Commands" section...'

printExampleUsage
printAvailableCommands

echo 'Done.'

Loading