Skip to content

Commit

Permalink
chore(ci): support additional paths in the build cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
flrgh committed Aug 24, 2023
1 parent dbacabb commit 8dd9ced
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 17 deletions.
86 changes: 69 additions & 17 deletions .github/actions/build-cache-key/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ 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'
required: false

outputs:
cache-key:
Expand All @@ -20,26 +23,75 @@ runs:
- name: Generate cache key
id: cache-key
shell: bash
env:
EXTRA_PATHS: ${{ inputs.paths }}
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
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') }}
${{ hashFiles('kong/**') }}
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'
)
HASH=$(sha256sum - <<< "${FILE_HASHES[*]}" | awk '{print $1}' )
CACHE_KEY=${{ inputs.prefix }}::${HASH}
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
add_file "$fname"
done
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}')
CACHE_KEY=${{ inputs.prefix }}::${ALL}
echo "cache-key: ${CACHE_KEY}"
echo "CACHE_KEY=${CACHE_KEY}" >> $GITHUB_OUTPUT
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ jobs:
uses: ./.github/actions/build-cache-key
with:
prefix: ${{ matrix.label }}-build
paths: |
kong/**
- name: Cache Packages
id: cache-deps
Expand Down

0 comments on commit 8dd9ced

Please sign in to comment.