Skip to content

Commit

Permalink
V10fixes (#137)
Browse files Browse the repository at this point in the history
* attempt to get ImageOS env using indexer.

* fix URL input

* pack action

* Add ImageVersion env var to first segment of cache key
  • Loading branch information
lukka authored Mar 11, 2022
1 parent f0ab7e9 commit 5522f28
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
8 changes: 4 additions & 4 deletions __tests__/functional.test.ts
Original file line number Diff line number Diff line change
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 = "025e564979cc01d0fbc5c920aa8a36635efb01bb";
process.env.INPUT_VCPKGGITCOMMITID = "b86c0c35b88e2bf3557ff49dc831689c2f085090";
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 = "025e564979cc01d0fbc5c920aa8a36635efb01bb";
process.env.INPUT_VCPKGGITCOMMITID = "b86c0c35b88e2bf3557ff49dc831689c2f085090";
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 = "025e564979cc01d0fbc5c920aa8a36635efb01bb";
process.env.INPUT_VCPKGGITCOMMITID = "b86c0c35b88e2bf3557ff49dc831689c2f085090";
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 = "025e564979cc01d0fbc5c920aa8a36635efb01bb";
process.env.INPUT_VCPKGGITCOMMITID = "b86c0c35b88e2bf3557ff49dc831689c2f085090";
process.env.INPUT_RUNVCPKGINSTALL = "true";
process.env.INPUT_RUNVCPKGFORMATSTRING = runvcpkglib.VcpkgRunner.VCPKGINSTALLCMDDEFAULT;

Expand Down
41 changes: 23 additions & 18 deletions __tests__/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,14 @@ 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=imageos-vcpkgGitCommit=1234_appendedKey=appendedCacheKey",
"primary": "runnerOS=imageos42-vcpkgGitCommit=1234_appendedKey=appendedCacheKey",
"restore":
[
"runnerOS=imageos-vcpkgGitCommit=1234"
"runnerOS=imageos42-vcpkgGitCommit=1234"
]
};
process.env.ImageOS = "imageos";
process.env.ImageVersion = "42";
const getFileHashMock = jest.spyOn(baseUtil, 'getFileHash').mockImplementation((file: string) => {
return Promise.resolve([null, null]);
});
Expand All @@ -331,22 +332,23 @@ 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=imageos-vcpkgGitCommit=1234_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"primary": "runnerOS=imageos42-vcpkgGitCommit=1234_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"restore":
[
"runnerOS=imageos-vcpkgGitCommit=1234_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"runnerOS=imageos-vcpkgGitCommit=1234"
"runnerOS=imageos42-vcpkgGitCommit=1234_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"runnerOS=imageos42-vcpkgGitCommit=1234"
]
};
process.env.ImageOS = "imageos";
process.env.ImageVersion = "42"
const vcpkgCommitIdMock = jest.spyOn(vcpkgutils.Utils, 'getVcpkgCommitId').
mockImplementationOnce(function (baseUtilLib, path): Promise<[string, boolean]> {
return Promise.resolve(["1234", false]);
});

// Act and Assert.
expect(await vcpkgutils.Utils.computeCacheKeys(
baseUtil,
baseUtil,
"hash-of-vcpkg.json",
"hash-of-vcpkg-configuration.json",
".",
Expand All @@ -361,22 +363,23 @@ 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=imageos-vcpkgGitCommit=5678_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"primary": "runnerOS=imageos42-vcpkgGitCommit=5678_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"restore":
[
"runnerOS=imageos-vcpkgGitCommit=5678_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"runnerOS=imageos-vcpkgGitCommit=5678"
"runnerOS=imageos42-vcpkgGitCommit=5678_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"runnerOS=imageos42-vcpkgGitCommit=5678"
]
};
process.env.ImageOS = "imageos";
process.env.ImageVersion = "42";
const vcpkgCommitIdMock = jest.spyOn(vcpkgutils.Utils, 'getVcpkgCommitId').
mockImplementationOnce(function (baseUtilLib, path): Promise<[string, boolean]> {
return Promise.resolve(["5678", true]);
});

// Act and Assert.
expect(await vcpkgutils.Utils.computeCacheKeys(
baseUtil,
baseUtil,
"hash-of-vcpkg.json",
"hash-of-vcpkg-configuration.json",
".",
Expand All @@ -391,22 +394,23 @@ 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=imageos-vcpkgGitCommit=0912_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"primary": "runnerOS=imageos42-vcpkgGitCommit=0912_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"restore":
[
"runnerOS=imageos-vcpkgGitCommit=0912_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"runnerOS=imageos-vcpkgGitCommit=0912"
"runnerOS=imageos42-vcpkgGitCommit=0912_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"runnerOS=imageos42-vcpkgGitCommit=0912"
]
};
process.env.ImageOS = "imageos";
process.env.ImageVersion = "42";
const vcpkgCommitIdMock = jest.spyOn(vcpkgutils.Utils, 'getVcpkgCommitId').
mockImplementationOnce(function (baseUtilLib, path): Promise<[string, boolean]> {
return Promise.resolve(["0912", true /* is submodule must be true */]);
});

// Act and Assert.
expect(await vcpkgutils.Utils.computeCacheKeys(
baseUtil,
baseUtil,
"hash-of-vcpkg.json",
"hash-of-vcpkg-configuration.json",
path.resolve("."),
Expand All @@ -419,20 +423,21 @@ test('computeCacheKey(): vcpkg as a submodule, with user provided Git commit id,
test('computeCacheKey(): vcpkg with user provided commit it must not trigger a warning', async () => {
// Arrange.
const expected: baseutil.KeySet = {
"primary": "runnerOS=imageos-vcpkgGitCommit=userId_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"primary": "runnerOS=imageos42-vcpkgGitCommit=userId_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json_appendedKey=appendedCacheKey",
"restore": [
"runnerOS=imageos-vcpkgGitCommit=userId_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"runnerOS=imageos-vcpkgGitCommit=userId"]
"runnerOS=imageos42-vcpkgGitCommit=userId_vcpkgJson=hash-of-vcpkg.json-vcpkgConfigurationJson=hash-of-vcpkg-configuration.json",
"runnerOS=imageos42-vcpkgGitCommit=userId"]
};
process.env.ImageOS = "imageos";
process.env.ImageVersion = "42";
const vcpkgCommitIdMock = jest.spyOn(vcpkgutils.Utils, 'getVcpkgCommitId').
mockImplementationOnce(function (baseUtilLib, path): Promise<[string | undefined, boolean]> {
return Promise.resolve([undefined, false]);
});

// Act and assert.
expect(await vcpkgutils.Utils.computeCacheKeys(
baseUtil,
baseUtil,
"hash-of-vcpkg.json",
"hash-of-vcpkg-configuration.json",
"/Users/luca/github/run-vcpkg/__tests__/assets/",
Expand Down
6 changes: 4 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ exports.runVcpkgFormatStringInput = "RUNVCPKGFORMATSTRING";
exports.vcpkgDirectoryInput = "VCPKGDIRECTORY";
exports.vcpkgCommitIdInput = "VCPKGGITCOMMITID";
exports.doNotUpdateVcpkgInput = "DONOTUPDATEVCPKG";
exports.vcpkgUrlInput = "VCPKGURLINPUT";
exports.vcpkgUrlInput = "VCPKGGITURL";
/**
* The input's name for additional content for the cache key.
*/
Expand Down Expand Up @@ -340,7 +340,9 @@ class Utils {
return __awaiter(this, void 0, void 0, function* () {
baseUtilLib.baseLib.debug(`computeCacheKeys()<<`);
const cacheKeySegments = [];
let firstSegment = `runnerOS=${process.env.ImageOS ? process.env.ImageOS : process.platform}`;
// Add to the first segment of the key the values of env vars ImageOS and ImageVersion if available.
let firstSegment = `runnerOS=${process.env['ImageOS'] ? process.env['ImageOS'] : process.platform}`;
firstSegment += process.env['ImageVersion'] || "";
const [commitId, isSubmodule] = yield Utils.getVcpkgCommitId(baseUtilLib, vcpkgDirectory);
if (commitId) {
firstSegment += `-vcpkgGitCommit=${commitId}`;
Expand Down
6 changes: 4 additions & 2 deletions dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ exports.runVcpkgFormatStringInput = "RUNVCPKGFORMATSTRING";
exports.vcpkgDirectoryInput = "VCPKGDIRECTORY";
exports.vcpkgCommitIdInput = "VCPKGGITCOMMITID";
exports.doNotUpdateVcpkgInput = "DONOTUPDATEVCPKG";
exports.vcpkgUrlInput = "VCPKGURLINPUT";
exports.vcpkgUrlInput = "VCPKGGITURL";
/**
* The input's name for additional content for the cache key.
*/
Expand Down Expand Up @@ -403,7 +403,9 @@ class Utils {
return __awaiter(this, void 0, void 0, function* () {
baseUtilLib.baseLib.debug(`computeCacheKeys()<<`);
const cacheKeySegments = [];
let firstSegment = `runnerOS=${process.env.ImageOS ? process.env.ImageOS : process.platform}`;
// Add to the first segment of the key the values of env vars ImageOS and ImageVersion if available.
let firstSegment = `runnerOS=${process.env['ImageOS'] ? process.env['ImageOS'] : process.platform}`;
firstSegment += process.env['ImageVersion'] || "";
const [commitId, isSubmodule] = yield Utils.getVcpkgCommitId(baseUtilLib, vcpkgDirectory);
if (commitId) {
firstSegment += `-vcpkgGitCommit=${commitId}`;
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const runVcpkgFormatStringInput = "RUNVCPKGFORMATSTRING";
export const vcpkgDirectoryInput = "VCPKGDIRECTORY";
export const vcpkgCommitIdInput = "VCPKGGITCOMMITID";
export const doNotUpdateVcpkgInput = "DONOTUPDATEVCPKG";
export const vcpkgUrlInput = "VCPKGURLINPUT";
export const vcpkgUrlInput = "VCPKGGITURL";
/**
* The input's name for additional content for the cache key.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/vcpkg-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export class Utils {
baseUtilLib.baseLib.debug(`computeCacheKeys()<<`);
const cacheKeySegments: string[] = [];

let firstSegment = `runnerOS=${process.env.ImageOS ? process.env.ImageOS : process.platform}`;
// Add to the first segment of the key the values of env vars ImageOS and ImageVersion if available.
let firstSegment = `runnerOS=${process.env['ImageOS'] ? process.env['ImageOS'] : process.platform}`;
firstSegment += process.env['ImageVersion'] || "";

const [commitId, isSubmodule] = await Utils.getVcpkgCommitId(baseUtilLib, vcpkgDirectory);
if (commitId) {
Expand Down

0 comments on commit 5522f28

Please sign in to comment.