Skip to content

Commit

Permalink
Rewrote shell code with focus on improved readability
Browse files Browse the repository at this point in the history
  • Loading branch information
bgandon committed Dec 4, 2024
1 parent 62db24f commit 73e175a
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 184 deletions.
19 changes: 9 additions & 10 deletions check
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#!/bin/sh
#!/bin/bash

set -e
set -ueo pipefail

exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging

PAYLOAD=$(mktemp /tmp/resource-check.XXXXXX)
payload=$(cat <&0)

cat > "$PAYLOAD" <&0
timestamp=$(jq --raw-output '.version.timestamp // empty' <<< "${payload}")

TS=$(jq '.version.timestamp // empty' < "$PAYLOAD")

if [ -z "$TS" ]; then
if [[ -z "${timestamp}" ]]; then
echo '[]' >&3
else
jq -n "[
{ timestamp: $TS }
]" >&3
jq --null-input \
--arg "timestamp" "${timestamp}" \
'[ { timestamp: $timestamp } ]' \
>&3
fi
20 changes: 8 additions & 12 deletions in
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
#!/bin/sh
#!/bin/bash

set -e
set -ueo pipefail

exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging

PAYLOAD=$(mktemp /tmp/resource-in.XXXXXX)
payload=$(cat <&0)

cat > "$PAYLOAD" <&0
timestamp=$(jq --raw-output '.version.timestamp // "none"' <<< "${payload}")

TS=$(jq '.version.timestamp // empty' < "$PAYLOAD")
[ -z "$TS" ] && TS='"none"'

jq -n "{
version: {
timestamp: $TS
}
}" >&3
jq --null-input \
--arg "timestamp" "${timestamp}" \
'{ version: { timestamp: $timestamp } }' \
>&3
Loading

0 comments on commit 73e175a

Please sign in to comment.