diff --git a/.github/actions/build-cache-key/action.yml b/.github/actions/build-cache-key/action.yml index 7b91acb1210e..3edde92a3429 100644 --- a/.github/actions/build-cache-key/action.yml +++ b/.github/actions/build-cache-key/action.yml @@ -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: @@ -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=( @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 29573dc9de36..78e232d92429 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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