Skip to content

Commit

Permalink
- add prependedCacheKey input for letting users to prepend to the c…
Browse files Browse the repository at this point in the history
…ache key. (#161)

- add docs for avoiding saving partial cache: #128
- use vcpkg commit id at 2022.09.27 for functional tests.
  • Loading branch information
lukka committed Oct 5, 2022
1 parent c623083 commit 34684ef
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 119 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/build-test.yml
Expand Up @@ -44,7 +44,6 @@ jobs:
NODE_COVERALLS_DEBUG: 1

tests:
needs: build_and_unit_test
name: '${{ matrix.os }}: functional tests'
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -71,7 +70,7 @@ jobs:
runVcpkgInstall: true
# This forces the creation of a new cache entry each time the workflow is run.
# It is the same across jobs in the same workflows.
appendedCacheKey: ${{ env.GITHUB_RUN_ID }}
prependedCacheKey: ${{ env.GITHUB_RUN_ID }}
env:
VCPKG_INSTALLED_DIR: ${{ github.workspace }}/vcpkg_installed

Expand All @@ -88,13 +87,12 @@ jobs:
uses: actions/checkout@v3
with:
submodules: true

- name: basic test for run-vcpkg (not running vcpkg).
uses: ./
with:
vcpkgDirectory: ${{ github.workspace }}/vcpkg
vcpkgGitCommitId: '14e7bb4ae24616ec54ff6b2f6ef4e8659434ea44'
appendedCacheKey: ${{ env.GITHUB_RUN_ID }}
prependedCacheKey: ${{ env.GITHUB_RUN_ID }}

finalize_coveralls:
needs: build_and_unit_test
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -15,8 +15,8 @@ The software is provided as is, there is no warranty of any kind. All users are
`run-vcpkg` depends on public NPM packages published by [lukka/run-cmake-vcpkg-action-libs](https://github.com/lukka/run-cmake-vcpkg-action-libs) in the [GitHub Packages registry](https://docs.github.com/en/free-pro-team@latest/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages).
Unexpectedly, a public package still requires authentication when downloading it, hence if you want to `npm install` those packages correctly, you need to obtain a token with `read:packages` scope. Then create in the root of the repository a `.npmrc` file with the following content:

//npm.pkg.github.com/:_authToken=YOURTOKEN
@lukka:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=YOURTOKEN
@lukka:registry=https://npm.pkg.github.com/

__Note__: **Never commit this `.npmrc` file!**

Expand Down
20 changes: 16 additions & 4 deletions README.md
Expand Up @@ -86,6 +86,18 @@ jobs:
# (i.e. let CMake run `vcpkg install`) using the vcpkg.cmake toolchain.
# runVcpkgInstall: true

# The following `run` step is useful to prevent storing partial cache in the GH cache
# service.
# This is useful when vcpkg is not run at `run-vcpkg`'s runtime, but later when CMake
# is running, e.g. at `run-cmake` runtime.
# Driving the environment variable `RUNVCPKG_NO_CACHE`, at the end of the workflow the
# `run-vcpkg` post step is instructed to not save anything when the workflow has been
# cancelled or it has failed.
#- run: |
# echo "RUNVCPKG_NO_CACHE=1" >> $GITHUB_ENV
# if: ${{ failure() || cancelled() }}
# shell: bash

- name: Run CMake consuming CMakePreset.json and vcpkg.json by mean of vcpkg.
uses: lukka/run-cmake@v10
with:
Expand All @@ -108,8 +120,8 @@ jobs:
# VCPKG_ENABLE_METRICS: 1
#
# [OPTIONAL] Define the vcpkg's triplet you want to enforce, otherwise the default one
# for the hosting system will be automatically choosen (x64 is the default on all platforms,
# e.g. `x64-osx`).
# for the hosting system will be automatically choosen (x64 is the default on all
# platforms, e.g. `x64-osx`).
# VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }}
```

Expand All @@ -124,9 +136,9 @@ Flowchart with related input in [action.yml](https://github.com/lukka/run-vcpkg/
```
┌──────────────────────────┐
│ Compute cache key from: │ Inputs:
│ - vcpkg Git commit │ - `appendedCacheKey`
│ - vcpkg Git commit │ - `prependedCacheKey` and `appendedCacheKey`
│ - platform and OS │ - `vcpkgGitCommitId`
│ - user provided key
│ - user provided keys
└─────────────┬────────────┘
Expand Down
8 changes: 4 additions & 4 deletions __tests__/functional.test.ts
Expand Up @@ -48,7 +48,7 @@ describe('run-vcpkg functional tests', () => {
test('vcpkg setup and install must succeed', () => {
process.env.INPUT_VCPKGDIRECTORY = vcpkgDirectory;
process.env.INPUT_VCPKGJSONGLOB = "**/vcpkg.json";
process.env.INPUT_VCPKGGITCOMMITID = "b86c0c35b88e2bf3557ff49dc831689c2f085090";
process.env.INPUT_VCPKGGITCOMMITID = "6ca56aeb457f033d344a7106cb3f9f1abf8f4e98";
process.env.INPUT_RUNVCPKGINSTALL = "true";
process.env.INPUT_RUNVCPKGFORMATSTRING = runvcpkglib.VcpkgRunner.VCPKGINSTALLCMDDEFAULT;

Expand All @@ -62,7 +62,7 @@ describe('run-vcpkg functional tests', () => {
test('vcpkg setup and no install must succeed', () => {
process.env.INPUT_VCPKGDIRECTORY = vcpkgDirectory;
process.env.INPUT_VCPKGJSONGLOB = "**/vcpkg.json";
process.env.INPUT_VCPKGGITCOMMITID = "b86c0c35b88e2bf3557ff49dc831689c2f085090";
process.env.INPUT_VCPKGGITCOMMITID = "6ca56aeb457f033d344a7106cb3f9f1abf8f4e98";
process.env.INPUT_RUNVCPKGINSTALL = "false";
process.env.INPUT_RUNVCPKGFORMATSTRING = "['invalid command']";

Expand All @@ -77,7 +77,7 @@ describe('run-vcpkg functional tests', () => {
delete process.env.INPUT_VCPKGDIRECTORY;
console.log(process.env.INPUT_VCPKGDIRECTORY);
delete process.env.INPUT_VCPKGJSONGLOB;
process.env.INPUT_VCPKGGITCOMMITID = "b86c0c35b88e2bf3557ff49dc831689c2f085090";
process.env.INPUT_VCPKGGITCOMMITID = "6ca56aeb457f033d344a7106cb3f9f1abf8f4e98";
process.env.INPUT_RUNVCPKGINSTALL = "false";
process.env.INPUT_RUNVCPKGFORMATSTRING = runvcpkglib.VcpkgRunner.VCPKGINSTALLCMDDEFAULT;

Expand All @@ -102,7 +102,7 @@ describe('run-vcpkg functional tests', () => {
await actionLib.rmRF(await runvcpkglib.getDefaultVcpkgInstallDirectory(baseLibUtils.baseLib));
await actionLib.rmRF(await runvcpkglib.getDefaultVcpkgCacheDirectory(baseLibUtils.baseLib));

process.env.INPUT_VCPKGGITCOMMITID = "b86c0c35b88e2bf3557ff49dc831689c2f085090";
process.env.INPUT_VCPKGGITCOMMITID = "6ca56aeb457f033d344a7106cb3f9f1abf8f4e98";
process.env.INPUT_RUNVCPKGINSTALL = "true";
process.env.INPUT_RUNVCPKGFORMATSTRING = runvcpkglib.VcpkgRunner.VCPKGINSTALLCMDDEFAULT;

Expand Down
44 changes: 25 additions & 19 deletions __tests__/unit.test.ts
Expand Up @@ -157,6 +157,7 @@ test('run-vcpkg: cache hit', async () => {
function (a, b, c): Promise<string> { return Promise.resolve(primaryHitKey); });
process.env.INPUT_VCPKGDIRECTORY = "/var/tmp/vcpkg";
process.env.INPUT_APPENDEDCACHEKEY = "appendedCacheKey";
process.env.INPUT_PREPENDEDCACHEKEY = "prependedCacheKey";

// Act.
const vcpkg: vcpkgaction.VcpkgAction = new vcpkgaction.VcpkgAction(baseUtil);
Expand Down Expand Up @@ -299,10 +300,10 @@ test('getVcpkgCommitId() tests', async () => {
test('computeCacheKey(): vcpkg not as a submodule (no commit id user provided and no vcpkg.json found)', async () => {
// Arrange.
const expected: baseutil.KeySet = {
"primary": "runnerOS=imageos42-vcpkgGitCommit=1234_appendedKey=appendedCacheKey",
"primary": "prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=1234_appendedKey=appendedCacheKey",
"restore":
[
"runnerOS=imageos42-vcpkgGitCommit=1234"
"prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=1234"
]
};
process.env.ImageOS = "imageos";
Expand All @@ -321,7 +322,8 @@ test('computeCacheKey(): vcpkg not as a submodule (no commit id user provided an
null,
".",
"",
"appendedCacheKey")).toStrictEqual(expected);
"appendedCacheKey",
"prependedCacheKey")).toStrictEqual(expected);
expect(warningMock).toBeCalledTimes(0);

// Cleanup.
Expand All @@ -332,11 +334,11 @@ test('computeCacheKey(): vcpkg not as a submodule (no commit id user provided an
test('computeCacheKey(): vcpkg not as a submodule (no commit id user provided)', async () => {
// Arrange.
const expected: baseutil.KeySet = {
"primary": "runnerOS=imageos42-vcpkgGitCommit=1234_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"primary": "prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=1234_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"restore":
[
"runnerOS=imageos42-vcpkgGitCommit=1234_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"runnerOS=imageos42-vcpkgGitCommit=1234"
"prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=1234_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=1234"
]
};
process.env.ImageOS = "imageos";
Expand All @@ -353,7 +355,8 @@ test('computeCacheKey(): vcpkg not as a submodule (no commit id user provided)',
"hash-of-vcpkg-configuration.json",
".",
"",
"appendedCacheKey")).toStrictEqual(expected);
"appendedCacheKey",
"prependedCacheKey")).toStrictEqual(expected);
expect(warningMock).toBeCalledTimes(0);

// Cleanup.
Expand All @@ -363,11 +366,11 @@ test('computeCacheKey(): vcpkg not as a submodule (no commit id user provided)',
test('computeCacheKey(): vcpkg as a submodule (no commit id user provided)', async () => {
// Arrange.
const expected: baseutil.KeySet = {
"primary": "runnerOS=imageos42-vcpkgGitCommit=5678_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"primary": "prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=5678_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"restore":
[
"runnerOS=imageos42-vcpkgGitCommit=5678_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"runnerOS=imageos42-vcpkgGitCommit=5678"
"prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=5678_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=5678"
]
};
process.env.ImageOS = "imageos";
Expand All @@ -384,7 +387,8 @@ test('computeCacheKey(): vcpkg as a submodule (no commit id user provided)', asy
"hash-of-vcpkg-configuration.json",
".",
"",
"appendedCacheKey")).toStrictEqual(expected);
"appendedCacheKey",
"prependedCacheKey")).toStrictEqual(expected);
expect(warningMock).toBeCalledTimes(0);

// Cleanup.
Expand All @@ -394,11 +398,11 @@ test('computeCacheKey(): vcpkg as a submodule (no commit id user provided)', asy
test('computeCacheKey(): vcpkg as a submodule, with user provided Git commit id, it must trigger a warning', async () => {
// Arrange.
const expected: baseutil.KeySet = {
"primary": "runnerOS=imageos42-vcpkgGitCommit=0912_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"primary": "prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=0912_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"restore":
[
"runnerOS=imageos42-vcpkgGitCommit=0912_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"runnerOS=imageos42-vcpkgGitCommit=0912"
"prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=0912_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=0912"
]
};
process.env.ImageOS = "imageos";
Expand All @@ -415,18 +419,19 @@ test('computeCacheKey(): vcpkg as a submodule, with user provided Git commit id,
"hash-of-vcpkg-configuration.json",
path.resolve("."),
"vcpkgcommitid",
"appendedCacheKey")).toStrictEqual(expected);
"appendedCacheKey",
"prependedCacheKey")).toStrictEqual(expected);
expect(warningMock).toBeCalledTimes(1);
vcpkgCommitIdMock.mockClear();
});

test('computeCacheKey(): vcpkg with user provided commit it must not trigger a warning', async () => {
// Arrange.
const expected: baseutil.KeySet = {
"primary": "runnerOS=imageos42-vcpkgGitCommit=userId_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"primary": "prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=userId_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"restore": [
"runnerOS=imageos42-vcpkgGitCommit=userId_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"runnerOS=imageos42-vcpkgGitCommit=userId"]
"prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=userId_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"prependedKey=prependedCacheKey-runnerOS=imageos42-vcpkgGitCommit=userId"]
};
process.env.ImageOS = "imageos";
process.env.ImageVersion = "42";
Expand All @@ -442,6 +447,7 @@ test('computeCacheKey(): vcpkg with user provided commit it must not trigger a w
"hash-of-vcpkg-configuration.json",
"/Users/luca/github/run-vcpkg/__tests__/assets/",
"userId",
"appendedCacheKey")).toStrictEqual(expected);
"appendedCacheKey",
"prependedCacheKey")).toStrictEqual(expected);
expect(warningMock).toBeCalledTimes(0);
});
3 changes: 3 additions & 0 deletions action.yml
Expand Up @@ -16,6 +16,9 @@ inputs:
default: false
required: false
description: "Run the installation of package by running `vcpkg install` on the directory of the discovered 'vcpkg.json' file. Default is false."
prependedCacheKey:
required: false
description: "Specify a value to prepend to the cache key."
appendedCacheKey:
required: false
description: "Specify a value to append to the cache key."
Expand Down

0 comments on commit 34684ef

Please sign in to comment.