Skip to content

Commit

Permalink
Add github-binarycache option to use built in cache (#22)
Browse files Browse the repository at this point in the history
* Add github-binarycache option to use built in cache

* Add test for github-binarycache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add github-binarycache option to use built in cache

* Add clear caches workflow

* Add github-binarycache option to use built in cache, update readme

* Fix disable cache for vcpkg binarycache
  • Loading branch information
johnwason authored Jan 18, 2024
1 parent 3839b02 commit 729859f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 20 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/clear_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Clear all Github actions caches
on:
workflow_dispatch:

jobs:
my-job:
name: Delete all caches
runs-on: ubuntu-20.04

steps:
- name: Clear caches
uses: easimon/wipe-cache@main
44 changes: 43 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,27 @@ jobs:
runs-on: ${{ matrix.config.os }}
name: test-vcpkg-action
strategy:
fail-fast: false
matrix:
config:
- os: ubuntu-20.04
vcpkg_triplet: x64-linux-release
github-binarycache: false
- os: macos-11
vcpkg_triplet: x64-osx-release
github-binarycache: false
- os: windows-2019
vcpkg_triplet: x64-windows-release
github-binarycache: false
- os: ubuntu-20.04
vcpkg_triplet: x64-linux-release
github-binarycache: true
- os: macos-11
vcpkg_triplet: x64-osx-release
github-binarycache: true
- os: windows-2019
vcpkg_triplet: x64-windows-release
github-binarycache: true
steps:
- uses: actions/checkout@v3
- name: vcpkg build
Expand All @@ -29,6 +42,7 @@ jobs:
cache-key: ${{ matrix.config.os }}
revision: master
token: ${{ github.token }}
github-binarycache: ${{ matrix.config.github-binarycache }}
- name: tree
if: runner.os == 'Windows'
shell: cmd
Expand All @@ -41,14 +55,27 @@ jobs:
runs-on: ${{ matrix.config.os }}
name: test-vcpkg-action-latest-vcpkg-release
strategy:
fail-fast: false
matrix:
config:
- os: ubuntu-20.04
vcpkg_triplet: x64-linux-release
github-binarycache: false
- os: macos-11
vcpkg_triplet: x64-osx-release
github-binarycache: false
- os: windows-2019
vcpkg_triplet: x64-windows-release
github-binarycache: false
- os: ubuntu-20.04
vcpkg_triplet: x64-linux-release
github-binarycache: true
- os: macos-11
vcpkg_triplet: x64-osx-release
github-binarycache: true
- os: windows-2019
vcpkg_triplet: x64-windows-release
github-binarycache: true
steps:
- uses: actions/checkout@v3
- name: vcpkg build
Expand All @@ -59,6 +86,7 @@ jobs:
triplet: ${{ matrix.config.vcpkg_triplet }}
cache-key: ${{ matrix.config.os }}
token: ${{ github.token }}
github-binarycache: ${{ matrix.config.github-binarycache }}
- name: tree
if: runner.os == 'Windows'
shell: cmd
Expand All @@ -71,14 +99,27 @@ jobs:
runs-on: ${{ matrix.config.os }}
name: test-manifest
strategy:
fail-fast: false
matrix:
config:
- os: ubuntu-20.04
vcpkg_triplet: x64-linux-release
github-binarycache: false
- os: macos-11
vcpkg_triplet: x64-osx-release
github-binarycache: false
- os: windows-2019
vcpkg_triplet: x64-windows-release
github-binarycache: false
- os: ubuntu-20.04
vcpkg_triplet: x64-linux-release
github-binarycache: true
- os: macos-11
vcpkg_triplet: x64-osx-release
github-binarycache: true
- os: windows-2019
vcpkg_triplet: x64-windows-release
github-binarycache: true
steps:
- uses: actions/checkout@v3
- name: vcpkg build
Expand All @@ -89,6 +130,7 @@ jobs:
cache-key: ${{ matrix.config.os }}
token: ${{ github.token }}
manifest-dir: ${{ github.workspace }}/.github/manifest
github-binarycache: ${{ matrix.config.github-binarycache }}
- name: cmake configure
run: >
cmake ${{ steps.vcpkg.outputs.vcpkg-cmake-config }} -S ${{ github.workspace }}/.github/cmake_test -B cmake_build
cmake ${{ steps.vcpkg.outputs.vcpkg-cmake-config }} -S ${{ github.workspace }}/.github/cmake_test -B cmake_build
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
features:

* Simplicity
* Use of a "dry-run" build to generate a unique cache key for the configuration. This guarantees that if packages
change, the cache will be rebuilt, but avoids rebuilding when it isn't necessary.
* Uses vcpkg built-in GitHub caching feature (NEW) OR Use of a "dry-run" build to generate a unique cache key for the configuration.
* Optionally supports reading `vcpkg.json` manifest files

`vcpkg` is cloned to the `${{ github.workspace }}\vcpkg` directory, and the build products are located in
Expand Down Expand Up @@ -37,6 +36,7 @@ Simple usage example:
pkgs: boost-date-time boost-system
triplet: x64-windows-release
token: ${{ github.token }}
github-binarycache: true
```
Simple manifest example:
Expand All @@ -49,6 +49,7 @@ Simple manifest example:
manifest-dir: ${{ github.workspace }} # Set to directory containing vcpkg.json
triplet: x64-windows-release
token: ${{ github.token }}
github-binarycache: true
```
Expand All @@ -75,6 +76,9 @@ Simple manifest example:
token: ''
# Directory containing vcpkg.json manifest file. Cannot be used with pkgs.
manifest-dir: ''
github-binarycache: ''
# "Use vcpkg built-in GitHub binary caching if "true". If not specified, will use the dry-run based file cache."
# Recommended set to "true"

```

Expand Down Expand Up @@ -106,5 +110,6 @@ jobs:
cache-key: ${{ matrix.config.os }}
revision: master
token: ${{ github.token }}
github-binarycache: true
```
40 changes: 23 additions & 17 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ inputs:
description: Directory containing vcpkg.json manifest file. Cannot be used with pkgs.
required: false
default: ''
github-binarycache:
description: "Use vcpkg built-in GitHub binary caching. If not specified, will use the dry-run based file cache."
required: false
default: ''
outputs:
vcpkg-cmake-config:
description: Configure options for cmake to use vcpkg
Expand Down Expand Up @@ -84,61 +88,66 @@ runs:
shell: bash
env:
VCPKG_ROOT: "${{ github.workspace }}/vcpkg"
- name: set-binarycache-variable
if: inputs.github-binarycache != 'true' && inputs.github-binarycache != true
shell: bash
run: |
echo VCPKG_DEFAULT_BINARY_CACHE='${{ github.workspace }}/vcpkg_cache' >> $GITHUB_ENV
mkdir -p '${{ github.workspace }}/vcpkg_cache'
- name: vcpkg-dry-run-win
if: runner.os == 'Windows' && inputs.manifest-dir == ''
if: runner.os == 'Windows' && inputs.manifest-dir == '' && inputs.github-binarycache != 'true' && inputs.github-binarycache != true
working-directory: ${{ github.workspace }}\vcpkg
shell: powershell
run: |
$VCPKG_DEFAULT_BINARY_CACHE = "${{ github.workspace }}\vcpkg_cache"
mkdir $VCPKG_DEFAULT_BINARY_CACHE
& "${{ github.workspace }}/vcpkg/vcpkg.exe" install --dry-run --triplet ${{ inputs.triplet }} ${{ inputs.extra-args }} ${{ inputs.pkgs }} | Tee-Object -FilePath vcpkg_dry_run.txt
env:
VCPKG_ROOT: "${{ github.workspace }}/vcpkg"
- name: vcpkg-dry-run-unix
if: runner.os != 'Windows' && inputs.manifest-dir == ''
if: runner.os != 'Windows' && inputs.manifest-dir == '' && inputs.github-binarycache != 'true' && inputs.github-binarycache != true
working-directory: ${{ github.workspace }}/vcpkg
shell: bash
run: |
export VCPKG_DEFAULT_BINARY_CACHE=${{ github.workspace }}/vcpkg_cache
mkdir $VCPKG_DEFAULT_BINARY_CACHE
"${{ github.workspace }}/vcpkg/vcpkg" install --dry-run --triplet ${{ inputs.triplet }} ${{ inputs.extra-args }} ${{ inputs.pkgs }} | tee vcpkg_dry_run.txt
env:
VCPKG_ROOT: "${{ github.workspace }}/vcpkg"
- name: vcpkg-dry-run-win-manifest
if: runner.os == 'Windows' && inputs.manifest-dir != ''
if: runner.os == 'Windows' && inputs.manifest-dir != '' && inputs.github-binarycache != 'true' && inputs.github-binarycache != true
working-directory: ${{ github.workspace }}\vcpkg
shell: powershell
run: |
$VCPKG_DEFAULT_BINARY_CACHE = "${{ github.workspace }}\vcpkg_cache"
mkdir $VCPKG_DEFAULT_BINARY_CACHE
& "${{ github.workspace }}/vcpkg/vcpkg.exe" install --dry-run --triplet ${{ inputs.triplet }} ${{ inputs.extra-args }} --x-manifest-root=${{ inputs.manifest-dir }} --x-install-root=${{ github.workspace }}\vcpkg\installed | Tee-Object -FilePath vcpkg_dry_run.txt
env:
VCPKG_ROOT: "${{ github.workspace }}/vcpkg"
- name: vcpkg-dry-run-unix-manifest
if: runner.os != 'Windows' && inputs.manifest-dir != ''
if: runner.os != 'Windows' && inputs.manifest-dir != '' && inputs.github-binarycache != 'true' && inputs.github-binarycache != true
working-directory: ${{ github.workspace }}/vcpkg
shell: bash
run: |
export VCPKG_DEFAULT_BINARY_CACHE=${{ github.workspace }}/vcpkg_cache
mkdir $VCPKG_DEFAULT_BINARY_CACHE
"${{ github.workspace }}/vcpkg/vcpkg" install --dry-run --triplet ${{ inputs.triplet }} ${{ inputs.extra-args }} --x-manifest-root=${{ inputs.manifest-dir }} --x-install-root=${{ github.workspace }}/vcpkg/installed | tee vcpkg_dry_run.txt
env:
VCPKG_ROOT: "${{ github.workspace }}/vcpkg"
- name: cache-vcpkg-archives
if: ${{ inputs.disable_cache != 'true' }}
if: ${{ inputs.disable_cache != 'true' }} && inputs.github-binarycache != 'true' && inputs.github-binarycache != true
id: cache-vcpkg-archives
uses: pat-s/always-upload-cache@v3
with:
path: ${{ github.workspace }}/vcpkg_cache
key: ${{ runner.os }}-${{ inputs.triplet }}-vcpkg-${{ hashFiles('vcpkg/vcpkg_dry_run.txt') }}-${{ inputs.cache-key }}
env:
VCPKG_ROOT: "${{ github.workspace }}/vcpkg"
- name: Export GitHub Actions cache environment variables
if: (inputs.disable_cache != 'true' && inputs.disable_cache != true) && (inputs.github-binarycache == 'true' || inputs.github-binarycache == true)
uses: actions/github-script@v6
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
core.exportVariable('VCPKG_BINARY_SOURCES', "clear;x-gha,readwrite");
- name: build-vcpkg-win
if: runner.os == 'Windows' && inputs.manifest-dir == ''
shell: cmd
working-directory: ${{ github.workspace }}\vcpkg
run: |
set VCPKG_DEFAULT_BINARY_CACHE=${{ github.workspace }}\vcpkg_cache
"${{ github.workspace }}/vcpkg/vcpkg.exe" install --triplet ${{ inputs.triplet }} ${{ inputs.extra-args }} ${{ inputs.pkgs }}
env:
VCPKG_ROOT: "${{ github.workspace }}/vcpkg"
Expand All @@ -147,7 +156,6 @@ runs:
shell: bash
working-directory: ${{ github.workspace }}/vcpkg
run: |
export VCPKG_DEFAULT_BINARY_CACHE=${{ github.workspace }}/vcpkg_cache
"${{ github.workspace }}/vcpkg/vcpkg" install --triplet ${{ inputs.triplet }} ${{ inputs.extra-args }} ${{ inputs.pkgs }}
env:
VCPKG_ROOT: "${{ github.workspace }}/vcpkg"
Expand All @@ -156,7 +164,6 @@ runs:
shell: cmd
working-directory: ${{ github.workspace }}\vcpkg
run: |
set VCPKG_DEFAULT_BINARY_CACHE=${{ github.workspace }}\vcpkg_cache
"${{ github.workspace }}/vcpkg/vcpkg.exe" install --triplet ${{ inputs.triplet }} ${{ inputs.extra-args }} --x-manifest-root=${{ inputs.manifest-dir }} --x-install-root=${{ github.workspace }}/vcpkg/installed
env:
VCPKG_ROOT: "${{ github.workspace }}/vcpkg"
Expand All @@ -165,7 +172,6 @@ runs:
shell: bash
working-directory: ${{ github.workspace }}/vcpkg
run: |
export VCPKG_DEFAULT_BINARY_CACHE=${{ github.workspace }}/vcpkg_cache
"${{ github.workspace }}/vcpkg/vcpkg" install --triplet ${{ inputs.triplet }} ${{ inputs.extra-args }} --x-manifest-root=${{ inputs.manifest-dir }} --x-install-root=${{ github.workspace }}/vcpkg/installed
env:
VCPKG_ROOT: "${{ github.workspace }}/vcpkg"
Expand Down

0 comments on commit 729859f

Please sign in to comment.