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

Add github-binarycache option to use built in cache #22

Merged
merged 19 commits into from Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
57f49c9
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
32c7929
Add test for github-binarycache
johnwason Jan 18, 2024
d22f913
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
a14a39b
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
67468c2
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
413390e
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
1b60171
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
efe287a
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
3bbdc02
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
b9b534e
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
d708206
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
bbb9e81
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
a6930ff
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
35a0230
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
3dc44e4
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
65a9581
Add github-binarycache option to use built in cache
johnwason Jan 18, 2024
d04310e
Add clear caches workflow
johnwason Jan 18, 2024
6c3d4a9
Add github-binarycache option to use built in cache, update readme
johnwason Jan 18, 2024
432bf35
Fix disable cache for vcpkg binarycache
johnwason Jan 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/clear_cache.yml
@@ -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
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
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
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