Skip to content

Commit

Permalink
condense bash
Browse files Browse the repository at this point in the history
  • Loading branch information
flrgh committed Sep 6, 2023
1 parent d9f6288 commit 73e9df0
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions .github/actions/build-cache-key/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ runs:
id: cache-key
shell: bash
env:
PREFIX: ${{ inputs.prefix }}
EXTRA: ${{ inputs.extra }}
run: |
# please keep these sorted
Expand All @@ -43,35 +44,19 @@ runs:
${{ hashFiles('kong.conf.default') }}
)
echo "FILE_HASHES (init):"
printf '%q\n' "${FILE_HASHES[@]}"
if [[ -n ${EXTRA:-} ]]; then
OFFSET=${#FILE_HASHES[@]}
echo "EXTRA:"
echo "$EXTRA"
readarray \
-O "$OFFSET" \
-O "${#FILE_HASHES[@]}" \
-t \
FILE_HASHES \
<<< "$EXTRA"
echo "FILE_HASHES (extended):"
printf '%q\n' "${FILE_HASHES[@]}"
fi
NORMALIZED=$(
printf '%s\n' "${FILE_HASHES[@]}" \
| grep -vE '^$' \
| sort --stable --unique
HASH=$(printf '%s\n' "${FILE_HASHES[@]}" \
| grep -vE '^$' \
| sort --stable --unique \
| sha256sum - \
| awk '{print $1}'
)
echo "FILE_HASHES (normalized):"
echo "$NORMALIZED"
HASH=$(sha256sum - <<< "$NORMALIZED" | awk '{print $1}' )
CACHE_KEY=${{ inputs.prefix }}::${HASH}
echo "cache-key: ${CACHE_KEY}"
echo "CACHE_KEY=${CACHE_KEY}" >> $GITHUB_OUTPUT
echo "CACHE_KEY=${PREFIX}::${HASH}" >> $GITHUB_OUTPUT

0 comments on commit 73e9df0

Please sign in to comment.