Skip to content

Commit

Permalink
sets ACTIONS_CACHE_URL and ACTIONS_RUNTIME_TOKEN
Browse files Browse the repository at this point in the history
  • Loading branch information
lukka committed Apr 5, 2023
1 parent a400452 commit e987ddb
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 73 deletions.
43 changes: 26 additions & 17 deletions README.md
Expand Up @@ -26,12 +26,18 @@ Take a look at this [C++ project template](https://github.com/lukka/CppCMakeVcpk
# [The **run-vcpkg@v11** action](https://github.com/marketplace/actions/run-vcpkg)

The **run-vcpkg** action setups (and optionally runs) [vcpkg](https://github.com/microsoft/vcpkg) to install the packages specified in the `vcpkg.json` manifest file.

Special features which provide added value over a pure workflow are:
- automatic caching of vcpkg itself onto GitHub Action's cache: this storing/restoring the vcpkg executable and its data files to speed subsequent workflow runs. For the vcpkg's packages, caching is delegated to vcpkg itself instead.
- automatic caching leveraging `vcpkg` ability to store its [Binary Caching](https://learn.microsoft.com/en-us/vcpkg/users/binarycaching)) onto the [GitHub Action cache](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows) so that packages are built only once and reused in subsequent workflow runs. The user can customize the behavior by setting the environment variable `VCPKG_BINARY_SOURCES` *before* vcpkg runs.
- automatic dump of log files created by `CMake` (e.g., `CMakeOutput.log`) and `vcpkg`. The content of those files flow into the workflow output log. Customizable by the user.
It leverages the vcpkg's Binary Caching backed to GitHub Action cache, delegating cache and key management to vpckg.

Special features which provide added value over a __pure__ workflow are:
- automatic caching leveraging `vcpkg`'s ability to store its [Binary Caching](https://learn.microsoft.com/en-us/vcpkg/users/binarycaching)) artifacts onto the [GitHub Action cache](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows) so that packages are built only once and reused in subsequent workflow runs. The user can customize the behavior by setting the environment variable `VCPKG_BINARY_SOURCES` *before* vcpkg runs.
- set the environment variables `ACTIONS_CACHE_URL` and `ACTIONS_RUNTIME_TOKEN` to let user easily running vcpkg
in a `run` step such as `- run: vcpkg install` or `- run: vcpkg integrate install` without forcing the
users to set the variables manually.
- automatic dump of log files created by `CMake` (e.g., `CMakeOutput.log`) and `vcpkg`. The content of those files flow into the workflow output log. Customizable by the user by setting the input `logCollectionRegExps`.
- automatic parsing of `CMake`, `vcpkg` and `gcc`, `clang`, `msvc` errors, reporting them contextually in the workflow summary by means of annotations.
- although disabled by default, `run-vcpkg` can cache vcpkg's executable and data files to speed subsequent workflow runs. Since bootstrapping vcpkg already downloads a prebuilt binary saving the time spent to build vcpkg,
this form of caching is useful only when the prebuilt executable is not served as it happens for the ARM platform.
Note this cache does not contain the libraries built by vcpkg.

The provided [samples](#samples) use [GitHub hosted runners](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners).

Expand Down Expand Up @@ -124,38 +130,41 @@ Flowchart with related input in [action.yml](https://github.com/lukka/run-vcpkg/

```
┌──────────────────────────┐
| If running in GH Runner,| Environment variables:
| set the env vars: | - If any env var is
| - VCPKG_BINARY_SOURCES | already defined
| - ACTIONS_CACHE_URL | it will not be overridden.
| - ACTIONS_RUNTIME_TOKEN |
└─────────────┬────────────┘
┌──────────────────────────┐
| Skipped by default. |
│ Compute cache key from: │ Inputs:
│ - vcpkg Git commit │ - `vcpkgGitCommitId`
│ - platform and OS │ - `doNotCache`: set to false
└─────────────┬────────────┘ to run this block.
┌─────────────────────────┐ Inputs:
│ Locate vcpkg.json. │ - `vcpkgJsonGlob`
└────────────┬────────────┘ - `vcpkgJsonIgnores`
┌─────────────────────────┐ Inputs:
| Skipped by default. |
│ Restore vcpkg │ - `vcpkgDirectory`
│ from the GH cache. │ - `doNotCache`: set to false
└────────────┬────────────┘ to run this block.
| Skipped by default. | - `vcpkgDirectory`
│ Restore vcpkg │ - `doNotCache`: set to false
│ from the GH cache. │ to run this block.
└────────────┬────────────┘
┌─────────────────────────┐
│ If vcpkg is not a │ Inputs:
┌─────────────────────────┐ Inputs:
│ If vcpkg is not a │ - `vcpkgDirectory`
│ submodule, fetch it │ - `vcpkgGitCommitId`
│ │ - `vcpkgGitURL`
└────────────┬────────────┘ - `doNotUpdateVcpkg`
│ - `vcpkgDirectory`
┌─────────────────────────┐
│ Rebuild vcpkg executable│ Inputs:
│ if not in sync with │ - `vcpkgGitCommitId`
│ sources. │ - `vcpkgGitURL`
└────────────┬────────────┘
<Is `runVcpkgInstall:true`>┐ Inputs:
────┬──── No│ - `runVcpkgInstall`
Expand All @@ -182,7 +191,7 @@ Flowchart with related input in [action.yml](https://github.com/lukka/run-vcpkg/
| Skipped by default. |
│ If no cache-hit, │ Inputs:
│ store vcpkg onto │ - `doNotCache`: set to false to
│ GH cache │ run this block.
│ GH cache. │ run this block.
└────────────┬────────────┘
|
Expand Down
33 changes: 29 additions & 4 deletions dist/index.js
Expand Up @@ -42617,6 +42617,26 @@ class BaseUtilLib {
this.baseLib.info(`Set the step output variable '${name}' to value '${value}''`);
this.baseLib.setOutput(name, value);
}
/**
* Set a workflow variable if not set already.
* @param name The name of the variable.
* @param value The value.
*/
setVariableIfUndefined(name, value) {
this.baseLib.debug(`setVariableIfUndefined()<<`);
if (!process.env[name]) {
if (!value) {
this.baseLib.warning(`Cannot set '${name}' variable because the provided value is null.`);
}
else {
this.setVariableVerbose(name, value);
}
}
else {
this.baseLib.debug(`${name} is already set to: '${value}'`);
}
this.baseLib.debug(`setVariableIfUndefined()>>`);
}
}
exports.BaseUtilLib = BaseUtilLib;
class Matcher {
Expand Down Expand Up @@ -44004,7 +44024,7 @@ __exportStar(__nccwpck_require__(6188), exports);
// Released under the term specified in file LICENSE.txt
// SPDX short identifier: MIT
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.VCPKG_BINARY_SOURCES = exports.VCPKG_INSTALLED_DIR = exports.VCPKG_JSON = exports.VCPKGDEFAULTTRIPLET = exports.VCPKGROOT = exports.vcpkgLastBuiltCommitId = exports.RUNVCPKG_VCPKG_DEFAULT_TRIPLET = exports.RUNVCPKG_VCPKG_ROOT = void 0;
exports.ACTIONS_RUNTIME_TOKEN = exports.ACTIONS_CACHE_URL = exports.VCPKG_BINARY_SOURCES = exports.VCPKG_INSTALLED_DIR = exports.VCPKG_JSON = exports.VCPKGDEFAULTTRIPLET = exports.VCPKGROOT = exports.vcpkgLastBuiltCommitId = exports.RUNVCPKG_VCPKG_DEFAULT_TRIPLET = exports.RUNVCPKG_VCPKG_ROOT = void 0;
exports.RUNVCPKG_VCPKG_ROOT = "RUNVCPKG_VCPKG_ROOT";
exports.RUNVCPKG_VCPKG_DEFAULT_TRIPLET = "RUNVCPKG_VCPKG_DEFAULT_TRIPLET";
exports.vcpkgLastBuiltCommitId = 'vcpkgLastBuiltCommitId';
Expand All @@ -44013,6 +44033,8 @@ exports.VCPKGDEFAULTTRIPLET = "VCPKG_DEFAULT_TRIPLET";
exports.VCPKG_JSON = "vcpkg.json";
exports.VCPKG_INSTALLED_DIR = "VCPKG_INSTALLED_DIR";
exports.VCPKG_BINARY_SOURCES = `VCPKG_BINARY_SOURCES`;
exports.ACTIONS_CACHE_URL = `ACTIONS_CACHE_URL`;
exports.ACTIONS_RUNTIME_TOKEN = `ACTIONS_RUNTIME_TOKEN`;
//# sourceMappingURL=vcpkg-globals.js.map

/***/ }),
Expand Down Expand Up @@ -44137,9 +44159,12 @@ class VcpkgRunner {
// If running in a GitHub Runner, enable the GH's cache provider for the vcpkg's binary cache.
if (process.env['GITHUB_ACTIONS'] === 'true') {
yield this.baseUtils.wrapOp(`Setup to run on GitHub Action runners`, () => __awaiter(this, void 0, void 0, function* () {
// Allow users to define the vcpkg's binary source explicitly in the workflow, in that case don't override it.
if (!process.env[globals.VCPKG_BINARY_SOURCES])
this.baseUtils.setVariableVerbose(globals.VCPKG_BINARY_SOURCES, VcpkgRunner.VCPKG_BINARY_SOURCES_GHA);
// Allow users to define the vcpkg's binary source explicitly in the workflow, in that case do not override it.
this.baseUtils.setVariableIfUndefined(globals.VCPKG_BINARY_SOURCES, VcpkgRunner.VCPKG_BINARY_SOURCES_GHA);
if (process.env.ACTIONS_CACHE_URL)
this.baseUtils.setVariableVerbose(globals.ACTIONS_CACHE_URL, process.env.ACTIONS_CACHE_URL);
if (process.env.ACTIONS_RUNTIME_TOKEN)
this.baseUtils.setVariableVerbose(globals.ACTIONS_RUNTIME_TOKEN, process.env.ACTIONS_RUNTIME_TOKEN);
}));
}
// Ensuring `this.vcpkgDestPath` is existent, since is going to be used as current working directory.
Expand Down
94 changes: 47 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -43,11 +43,11 @@
"@actions/exec": "^1.1.1",
"@actions/github": "^5.0.3",
"@actions/io": "^1.1.2",
"@lukka/action-lib": "3.5.2",
"@lukka/assets-lib": "3.5.2",
"@lukka/base-lib": "3.5.2",
"@lukka/base-util-lib": "3.5.2",
"@lukka/run-vcpkg-lib": "3.5.2",
"@lukka/action-lib": "3.5.5",
"@lukka/assets-lib": "3.5.5",
"@lukka/base-lib": "3.5.5",
"@lukka/base-util-lib": "3.5.5",
"@lukka/run-vcpkg-lib": "3.5.5",
"@types/adm-zip": "^0.4.32",
"@types/follow-redirects": "^1.14.1",
"@types/jest": "^26.0.14",
Expand Down

0 comments on commit e987ddb

Please sign in to comment.