Skip to content

Commit

Permalink
caller passes in hashes directly
Browse files Browse the repository at this point in the history
  • Loading branch information
flrgh committed Aug 24, 2023
1 parent 8dd9ced commit d7e7120
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 65 deletions.
94 changes: 31 additions & 63 deletions .github/actions/build-cache-key/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ inputs:
description: 'String prefix applied to the build cache key'
required: false
default: 'build'
paths:
description: 'Additional paths (newline-delimited) to use in cache key generation'
extra:
description: 'Additional values/file hashes to use in the cache key'
required: false

outputs:
Expand All @@ -24,74 +24,42 @@ runs:
id: cache-key
shell: bash
env:
EXTRA_PATHS: ${{ inputs.paths }}
EXTRA: ${{ inputs.extra }}
run: |
echo "::group::Enumerate Paths"
LIST=$(mktemp)
add_file() {
local f=$1
echo "path spec: $f"
git ls-files \
--full-name \
--recurse-submodules \
"$f" \
>> "$LIST"
}
# please keep these sorted
DEFAULT_PATHS=(
'.bazelignore'
'.bazelrc'
'.bazelversion'
'.github/actions/build-cache-key/**'
'.github/workflows/build.yml'
'.requirements'
'BUILD.bazel'
'WORKSPACE'
'bin/kong'
'bin/kong-health'
'build/**'
'kong-*.rockspec'
'kong.conf.default'
FILE_HASHES=(
${{ hashFiles('.bazelignore') }}
${{ hashFiles('.bazelrc') }}
${{ hashFiles('.bazelversion') }}
${{ hashFiles('.github/actions/build-cache-key/**') }}
${{ hashFiles('.github/workflows/build.yml') }}
${{ hashFiles('.requirements') }}
${{ hashFiles('BUILD.bazel') }}
${{ hashFiles('WORKSPACE') }}
${{ hashFiles('bin/kong') }}
${{ hashFiles('bin/kong-health') }}
${{ hashFiles('build/**') }}
${{ hashFiles('kong-*.rockspec') }}
${{ hashFiles('kong.conf.default') }}
)
for fname in "${DEFAULT_PATHS[@]}"; do
add_file "$fname"
done
if [[ -n ${EXTRA_PATHS:-} ]]; then
readarray -t EXTRA <<< "$EXTRA_PATHS"
for fname in "${EXTRA[@]}"; do
if [[ -z ${fname:-} ]]; then
continue
fi
if [[ -n ${EXTRA:-} ]]; then
OFFSET=${#FILE_HASHES[@]}
add_file "$fname"
done
readarray \
-O "$OFFSET" \
-t \
FILE_HASHES \
<<< "$EXTRA"
fi
echo "::endgroup::"
echo "::group::Hash Files"
HASH=$(mktemp)
sort \
--stable \
--unique \
< "$LIST" \
| while read -r fname; do
sha256sum "$fname" | tee -a "$HASH"
done
echo "::endgroup::"
ALL=$(sha256sum "$HASH" | awk '{print $1}')
NORMALIZED=$(
printf '%s\n' "${FILE_HASHES[@]}" \
| grep -vE '^$' \
| sort --stable --unique
)
CACHE_KEY=${{ inputs.prefix }}::${ALL}
HASH=$(sha256sum - <<< "$NORMALIZED" | awk '{print $1}' )
CACHE_KEY=${{ inputs.prefix }}::${HASH}
echo "cache-key: ${CACHE_KEY}"
echo "CACHE_KEY=${CACHE_KEY}" >> $GITHUB_OUTPUT
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ jobs:
uses: ./.github/actions/build-cache-key
with:
prefix: ${{ matrix.label }}-build
paths: |
kong/**
extra: |
${{ hashFiles('kong/**') }}
- name: Cache Packages
id: cache-deps
Expand Down

0 comments on commit d7e7120

Please sign in to comment.