diff --git a/dist/index.mjs b/dist/index.mjs index 0df5780..8096b2f 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -81513,6 +81513,12 @@ async function main() { await _yarn_mjs__WEBPACK_IMPORTED_MODULE_4__/* ["default"].enable */ .Z.enable(); }); + const version = await _actions_core__WEBPACK_IMPORTED_MODULE_1__.group("Getting Yarn version", async () => { + const version = await _yarn_mjs__WEBPACK_IMPORTED_MODULE_4__/* ["default"].version */ .Z.version(); + _actions_core__WEBPACK_IMPORTED_MODULE_1__.info(`Yarn version: ${version}`); + return version; + }); + const lockFileHash = await _actions_core__WEBPACK_IMPORTED_MODULE_1__.group( "Calculating lock file hash", async () => { @@ -81529,7 +81535,7 @@ async function main() { const cachePaths = [".yarn", ".pnp.cjs", ".pnp.loader.mjs"]; const cacheKey = lockFileHash !== undefined - ? `yarn-install-action-${os__WEBPACK_IMPORTED_MODULE_3__.type()}-${lockFileHash}` + ? `yarn-install-action-${os__WEBPACK_IMPORTED_MODULE_3__.type()}-${version}-${lockFileHash}` : undefined; if (cacheKey !== undefined) { @@ -81606,7 +81612,12 @@ async function install() { return (0,_actions_exec__WEBPACK_IMPORTED_MODULE_0__.exec)("corepack", ["yarn", "install"], { env }); } -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ disableGlobalCache, enable, install }); +async function version() { + const res = await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_0__.getExecOutput)("corepack", ["yarn", "--version"]); + return res.stdout.trim(); +} + +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ disableGlobalCache, enable, install, version }); /***/ }), diff --git a/src/index.mjs b/src/index.mjs index f78da59..1b69d0c 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -10,6 +10,12 @@ async function main() { await yarn.enable(); }); + const version = await core.group("Getting Yarn version", async () => { + const version = await yarn.version(); + core.info(`Yarn version: ${version}`); + return version; + }); + const lockFileHash = await core.group( "Calculating lock file hash", async () => { @@ -26,7 +32,7 @@ async function main() { const cachePaths = [".yarn", ".pnp.cjs", ".pnp.loader.mjs"]; const cacheKey = lockFileHash !== undefined - ? `yarn-install-action-${os.type()}-${lockFileHash}` + ? `yarn-install-action-${os.type()}-${version}-${lockFileHash}` : undefined; if (cacheKey !== undefined) { diff --git a/src/yarn.mjs b/src/yarn.mjs index eac8392..a36e01b 100644 --- a/src/yarn.mjs +++ b/src/yarn.mjs @@ -1,4 +1,4 @@ -import { exec } from "@actions/exec"; +import { exec, getExecOutput } from "@actions/exec"; async function disableGlobalCache() { return exec("corepack", [ @@ -27,4 +27,9 @@ async function install() { return exec("corepack", ["yarn", "install"], { env }); } -export default { disableGlobalCache, enable, install }; +async function version() { + const res = await getExecOutput("corepack", ["yarn", "--version"]); + return res.stdout.trim(); +} + +export default { disableGlobalCache, enable, install, version }; diff --git a/src/yarn.test.mjs b/src/yarn.test.mjs index 0bfa858..a52da03 100644 --- a/src/yarn.test.mjs +++ b/src/yarn.test.mjs @@ -2,6 +2,7 @@ import { jest } from "@jest/globals"; jest.unstable_mockModule("@actions/exec", () => ({ exec: jest.fn(), + getExecOutput: jest.fn(), })); beforeEach(() => { @@ -50,3 +51,17 @@ it("should install package using Yarn", async () => { }, }); }); + +it("should get Yarn version", async () => { + const { getExecOutput } = await import("@actions/exec"); + const yarn = (await import("./yarn.mjs")).default; + + getExecOutput.mockResolvedValue({ stdout: "1.2.3" }); + + const version = await yarn.version(); + + expect(getExecOutput).toHaveBeenCalledTimes(1); + expect(getExecOutput).toHaveBeenCalledWith("corepack", ["yarn", "--version"]); + + expect(version).toEqual("1.2.3"); +});