Skip to content

Commit

Permalink
chore(ci): support additional paths in the build cache key (#11341)
Browse files Browse the repository at this point in the history
This updates the `build-cache-key` action to accept additional paths to use when generating the cache key. The impetus for this change is to allow removal of `kong/**` from the default cache key so that it can be used selectively.

See also: #11299 (comment)
  • Loading branch information
flrgh authored Sep 12, 2023
1 parent c738e45 commit ddc1400
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
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

1 comment on commit ddc1400

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:ddc1400fca7f8b1cf7bec46c8970da619ef5a9ab
Artifacts available https://github.com/Kong/kong/actions/runs/6155075649

Please sign in to comment.