Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): support additional paths in the build cache key #11341

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 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'
extra:
description: 'Additional values/file hashes to use in the cache key'
required: false

outputs:
cache-key:
Expand All @@ -20,6 +23,9 @@ runs:
- name: Generate cache key
id: cache-key
shell: bash
env:
PREFIX: ${{ inputs.prefix }}
EXTRA: ${{ inputs.extra }}
run: |
# please keep these sorted
FILE_HASHES=(
Expand All @@ -36,10 +42,21 @@ runs:
${{ hashFiles('build/**') }}
${{ hashFiles('kong-*.rockspec') }}
${{ hashFiles('kong.conf.default') }}
${{ hashFiles('kong/**') }}
)

HASH=$(sha256sum - <<< "${FILE_HASHES[*]}" | awk '{print $1}' )
CACHE_KEY=${{ inputs.prefix }}::${HASH}
echo "cache-key: ${CACHE_KEY}"
echo "CACHE_KEY=${CACHE_KEY}" >> $GITHUB_OUTPUT
if [[ -n ${EXTRA:-} ]]; then
readarray \
-O "${#FILE_HASHES[@]}" \
-t \
FILE_HASHES \
<<< "$EXTRA"
fi

HASH=$(printf '%s\n' "${FILE_HASHES[@]}" \
| grep -vE '^$' \
| sort --stable --unique \
| sha256sum - \
| awk '{print $1}'
)

echo "CACHE_KEY=${PREFIX}::${HASH}" | tee -a $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
extra: |
${{ hashFiles('kong/**') }}

- name: Cache Packages
id: cache-deps
Expand Down