Skip to content

Commit

Permalink
Make descriptions script work on Darwin, fix git diff check (kuskoman…
Browse files Browse the repository at this point in the history
…#283)

* Make descriptions script work on Darwin, fix git diff check

* Update Helm readme
  • Loading branch information
kuskoman authored Feb 15, 2024
1 parent 1aeee01 commit ebe3735
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/go-application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ 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
Expand All @@ -103,7 +107,11 @@ jobs:
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."
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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ See more in the [Migration](#migration) section.
- `make minify`: Minifies the binary executables.
- `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 clean-elasticsearch`: Cleans Elasticsearch data. The command may take a very long time to complete.
- `make clean-prometheus`: Cleans Prometheus data.
- `make upgrade-dependencies`: Upgrades all dependencies.
- `make migrate-v1-to-v2`: Migrates configuration from v1 to v2.
- `make update-readme-descriptions`: Update Makefile descriptions in main README.md.
Expand Down
8 changes: 4 additions & 4 deletions chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

### Custom logstash-exporter configuration. Overrides the default .logstash section

| Name | Description | Value |
| ---------------------- | --------------------------- | ------------------------------------------------- |
| `customConfig.enabled` | Enable custom configuration | `false` |
| Name | Description | Value |
| ---------------------- | --------------------------- | ---------------------------------------------------- |
| `customConfig.enabled` | Enable custom configuration | `false` |
| `customConfig.config` | Custom configuration | `logstash:
urls:
servers:
- "http://logstash:9600"
` |

Expand Down
2 changes: 1 addition & 1 deletion chart/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"config": {
"type": "string",
"description": "Custom configuration",
"default": "logstash:\n urls:\n - \"http://logstash:9600\"\n"
"default": "logstash:\n servers:\n - \"http://logstash:9600\"\n"
}
}
},
Expand Down
20 changes: 13 additions & 7 deletions scripts/add_descriptions_to_readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

# execute: ./scripts/add_descriptions_to_readme.sh

# define new line character to be used in `sed`
# 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

Expand Down Expand Up @@ -43,7 +49,7 @@ endLine=$(( $( grep -n "^#### File Structure" $FILE | cut -d : -f 1 ) - 2 ))
if (( startLine <= endLine));
then
# Deletes previous descriptions
sed -i "$startLine,${endLine}d" "$FILE"
"$SED_COMMAND" -i "$startLine,${endLine}d" "$FILE"
fi

function createMultipleAsterisks() {
Expand All @@ -58,13 +64,13 @@ function printAvailableCommands() {
commentLen=$(( ${#stringToWrite} - 11 ))
i=0

sed -i "${curLine}i\\${stringToWrite}" "$FILE"
"$SED_COMMAND" -i "${curLine}i\\${stringToWrite}" "$FILE"

# https://www.shellcheck.net/wiki/SC2219
(( curLine++ )) || true

# empty line
sed -i "${curLine}i${nl}" "$FILE"
"$SED_COMMAND" -i "${curLine}i${nl}" "$FILE"

(( curLine++ )) || true

Expand All @@ -75,20 +81,20 @@ function printAvailableCommands() {
stringToWrite=${stringToWrite//\'/\\\'}
echo "$stringToWrite"

sed -i "${curLine}i\\${stringToWrite}" "$FILE"
"$SED_COMMAND" -i "${curLine}i\\${stringToWrite}" "$FILE"
(( curLine++ )) || true

(( i++ )) || true
done

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

# multiple '*'
asterisks=$(createMultipleAsterisks $commentLen)
stringToWrite="<!--- ${asterisks} --->"
sed -i "${curLine}i\\${stringToWrite}" "$FILE"
"$SED_COMMAND" -i "${curLine}i\\${stringToWrite}" "$FILE"

(( curLine++ )) || true
}
Expand Down

0 comments on commit ebe3735

Please sign in to comment.