-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from bwhitehead0/develop
Develop
- Loading branch information
Showing
5 changed files
with
113 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
on: | ||
push: | ||
|
||
name: "Trigger: Push action" | ||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
shellcheck: | ||
name: Shellcheck | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
token: ${{ github.token }} | ||
- name: Run ShellCheck | ||
uses: bwhitehead0/action-shellcheck@master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/bash | ||
# simple script to take 'key: value' pairs and convert to a simple JSON string | ||
# | ||
# such that a series of values from the pipeline like the following: | ||
# value1: abc | ||
# value2: def | ||
# value3: ghi | ||
# | ||
# becomes: | ||
# {"value1":"abc","value2":"def","value3":"ghi"} | ||
# | ||
# use flag -p to output as pretty JSON, and the above example would become: | ||
# { | ||
# "value1": "abc", | ||
# "value2": "def", | ||
# "value3": "ghi" | ||
# } | ||
|
||
while getopts "p" opt; do | ||
case $opt in | ||
p) | ||
pretty=true | ||
;; | ||
\?) | ||
echo "Invalid option: -$OPTARG" >&2 | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
newline=$'\n' | ||
first_entry=true | ||
|
||
# Read key-value pairs from pipeline | ||
while IFS=':' read -r key value; do | ||
# Remove leading/trailing whitespace from key and value, and escape double quotes in value | ||
key=$(echo "$key" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') | ||
value=$(echo "$value" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//;s/\"/\\\"/g') | ||
|
||
if [ "${pretty}" == true ]; then | ||
# Add a comma before each new entry except the first one | ||
if [ "$first_entry" = false ]; then | ||
json="$json,${newline}" | ||
fi | ||
first_entry=false | ||
|
||
# Add the key-value pair to the JSON object with indentation | ||
json="$json \"$key\": \"$value\"" | ||
else | ||
# Add key-value pair to JSON object | ||
json+="\"$key\":\"$value\"," | ||
fi | ||
done | ||
|
||
# build either pretty or non-pretty JSON and remove trailing comma | ||
if [ "${pretty}" == true ]; then | ||
json="{${newline}${json%,}${newline}}" | ||
else | ||
json="{${json%,}}" | ||
fi | ||
|
||
# print the JSON object | ||
echo "$json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters