Skip to content

Commit

Permalink
improve vcpkg cache hits (#1033)
Browse files Browse the repository at this point in the history
* incorporate ImageVersion or build action hash into vcpkg cache keys
  • Loading branch information
scareything authored Oct 30, 2024
1 parent e00568a commit d87bd47
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
27 changes: 19 additions & 8 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ runs:
- name: macOS tools
if: runner.os == 'macOS'
shell: bash
run: brew install autoconf autoconf-archive automake pkg-config
run: |
brew install autoconf autoconf-archive automake pkg-config md5sha1sum
- name: simple build
run: echo "preset = ${{ inputs.preset }}"
Expand All @@ -39,16 +40,26 @@ runs:
# get baseline from vcpkg
vcpkgJsonGlob: './vcpkg.json'

- uses: actions/cache@v4
if: runner.os != 'Linux'
with:
key: deps-${{ inputs.preset }}-${{ hashFiles('./vcpkg.json') }}
path: ./vcpkg_cache
- name: get vcpkg cache key
id: get_vcpkg_cache_key
shell: bash
env:
DISTRO_LABEL: ${{ format('{0}-{1}', matrix.distro.name, matrix.distro.version) }}
KEY_PREFIX: vcpkg_cache-cmake-${{ inputs.preset }}
run: |
common_key="${KEY_PREFIX}-vcpkg_json_md5=$(md5sum ./vcpkg.json | awk '{ print $1 }')"
if [ "${RUNNER_OS}" != "Linux" ]; then
echo "key=${common_key}-ImageVersion=${ImageVersion}" | tee -a $GITHUB_OUTPUT
else
# ImageVersion is irrelevant since the build action runs in a container
# Express the vcpkg overlays, dockerfile, and entry point that the action will use as a single hash
build_action_hash="$(find ./.github/actions/openziti-tunnel-build-action/gh-release -type f -print | xargs md5sum | awk '{ print $1 }' | sort | md5sum | awk '{ print $1 }')"
echo "key=${common_key}-build_action_md5=${build_action_hash}" | tee -a $GITHUB_OUTPUT
fi
- uses: actions/cache@v4
if: runner.os == 'Linux'
with:
key: deps=${{ inputs.preset }}-${{ hashFiles('./vcpkg.json', '.github/actions/openziti-tunnel-build-action/gh-release/vcpkg-overlays/**/vcpkg.json') }}
key: ${{ steps.get_vcpkg_cache_key.outputs.key }}
path: ./vcpkg_cache

- uses: lukka/run-cmake@v10.6 # pin version to avoid failed glibc dependency on ubuntu 20 runners. go back to @latest when ubuntu 22+ is adopted for runner os.
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/cpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
shell: bash
run: |
dnf -y update
dnf -y install git
dnf -y install git findutils
git --version
- name: checkout workspace
Expand All @@ -93,9 +93,21 @@ jobs:
run: |
cp -vr ./.github/actions/openziti-tunnel-build-action/${DISTRO_LABEL}/* ./.github/actions/openziti-tunnel-build-action/
- name: get vcpkg cache key
id: get_vcpkg_cache_key
shell: bash
env:
DISTRO_LABEL: ${{ format('{0}-{1}', matrix.distro.name, matrix.distro.version) }}
KEY_PREFIX: vcpkg_cache-cpack-${{ matrix.arch.rpm }}-${{ matrix.distro.name }}-${{ matrix.distro.version }}
run: |
key_prefix="${KEY_PREFIX}-vcpkg_json_md5=$(md5sum ./vcpkg.json | awk '{ print $1 }')"
# Express the vcpkg overlays, dockerfile, and entry point that the action will use as a single hash
build_action_md5="$(find ./.github/actions/openziti-tunnel-build-action/${DISTRO_LABEL} -type f -print | xargs md5sum | awk '{ print $1 }' | sort | md5sum | awk '{ print $1 }')"
echo "key=${key_prefix}-build_action_md5=${build_action_md5}" | tee -a $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
key: deps-cpack-${{ matrix.arch.rpm }}-${{ matrix.distro.name }}-${{ matrix.distro.version }}-${{ hashFiles('./vcpkg.json', './.github/actions/openziti-tunnel-build-action/vcpkg-overlays/**/vcpkg.json') }}
key: ${{ steps.get_vcpkg_cache_key.outputs.key }}
path: ./vcpkg_cache

# entrypoint.sh uses the value of arch to select the cmake preset
Expand Down

0 comments on commit d87bd47

Please sign in to comment.