From d14afd7973c037fa9f72882decd1eb3befa36135 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Fri, 4 Oct 2024 17:23:42 -0400 Subject: [PATCH] Explicitly import `crypto` (#1842) * Explicitly import `crypto` * Add release notes for 1.11.1 * Fix crypto mock in test * Fix `crypto` mock * Lint --- packages/cache/src/internal/cacheUtils.ts | 1 + packages/core/RELEASES.md | 3 +++ packages/core/__tests__/core.test.ts | 9 +++++---- packages/core/package-lock.json | 18 +++++++++--------- packages/core/package.json | 4 ++-- packages/core/src/file-command.ts | 1 + packages/tool-cache/src/tool-cache.ts | 1 + 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/packages/cache/src/internal/cacheUtils.ts b/packages/cache/src/internal/cacheUtils.ts index d8b7f3e0..4c2a16f3 100644 --- a/packages/cache/src/internal/cacheUtils.ts +++ b/packages/cache/src/internal/cacheUtils.ts @@ -2,6 +2,7 @@ import * as core from '@actions/core' import * as exec from '@actions/exec' import * as glob from '@actions/glob' import * as io from '@actions/io' +import * as crypto from 'crypto' import * as fs from 'fs' import * as path from 'path' import * as semver from 'semver' diff --git a/packages/core/RELEASES.md b/packages/core/RELEASES.md index 5bc0e31e..69701660 100644 --- a/packages/core/RELEASES.md +++ b/packages/core/RELEASES.md @@ -1,5 +1,8 @@ # @actions/core Releases +### 1.11.1 +- Fix uses of `crypto.randomUUID` on Node 18 and earlier [#1842](https://github.com/actions/toolkit/pull/1842) + ### 1.11.0 - Add platform info utilities [#1551](https://github.com/actions/toolkit/pull/1551) - Remove dependency on `uuid` package [#1824](https://github.com/actions/toolkit/pull/1824) diff --git a/packages/core/__tests__/core.test.ts b/packages/core/__tests__/core.test.ts index 7fcb3759..2928788d 100644 --- a/packages/core/__tests__/core.test.ts +++ b/packages/core/__tests__/core.test.ts @@ -46,6 +46,11 @@ const testEnvVars = { const UUID = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d' const DELIMITER = `ghadelimiter_${UUID}` +jest.mock('crypto', () => ({ + ...jest.requireActual('crypto'), + randomUUID: jest.fn(() => UUID) +})) + const TEMP_DIR = path.join(__dirname, '_temp') describe('@actions/core', () => { @@ -66,10 +71,6 @@ describe('@actions/core', () => { process.env[key] = testEnvVars[key as keyof typeof testEnvVars] } process.stdout.write = jest.fn() - - jest.spyOn(crypto, 'randomUUID').mockImplementation(() => { - return UUID - }) }) afterEach(() => { diff --git a/packages/core/package-lock.json b/packages/core/package-lock.json index fb11ec9e..95cf58d2 100644 --- a/packages/core/package-lock.json +++ b/packages/core/package-lock.json @@ -1,19 +1,19 @@ { "name": "@actions/core", - "version": "1.11.0", + "version": "1.11.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@actions/core", - "version": "1.11.0", + "version": "1.11.1", "license": "MIT", "dependencies": { "@actions/exec": "^1.1.1", "@actions/http-client": "^2.0.1" }, "devDependencies": { - "@types/node": "^12.0.2" + "@types/node": "^16.18.112" } }, "node_modules/@actions/exec": { @@ -38,9 +38,9 @@ "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==" }, "node_modules/@types/node": { - "version": "12.0.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.2.tgz", - "integrity": "sha512-5tabW/i+9mhrfEOUcLDu2xBPsHJ+X5Orqy9FKpale3SjDA17j5AEpYq5vfy3oAeAHGcvANRCO3NV3d2D6q3NiA==", + "version": "16.18.112", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.112.tgz", + "integrity": "sha512-EKrbKUGJROm17+dY/gMi31aJlGLJ75e1IkTojt9n6u+hnaTBDs+M1bIdOawpk2m6YUAXq/R2W0SxCng1tndHCg==", "dev": true }, "node_modules/tunnel": { @@ -75,9 +75,9 @@ "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==" }, "@types/node": { - "version": "12.0.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.2.tgz", - "integrity": "sha512-5tabW/i+9mhrfEOUcLDu2xBPsHJ+X5Orqy9FKpale3SjDA17j5AEpYq5vfy3oAeAHGcvANRCO3NV3d2D6q3NiA==", + "version": "16.18.112", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.112.tgz", + "integrity": "sha512-EKrbKUGJROm17+dY/gMi31aJlGLJ75e1IkTojt9n6u+hnaTBDs+M1bIdOawpk2m6YUAXq/R2W0SxCng1tndHCg==", "dev": true }, "tunnel": { diff --git a/packages/core/package.json b/packages/core/package.json index 6bc7f70b..6d60010e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@actions/core", - "version": "1.11.0", + "version": "1.11.1", "description": "Actions core lib", "keywords": [ "github", @@ -40,6 +40,6 @@ "@actions/http-client": "^2.0.1" }, "devDependencies": { - "@types/node": "^12.0.2" + "@types/node": "^16.18.112" } } \ No newline at end of file diff --git a/packages/core/src/file-command.ts b/packages/core/src/file-command.ts index 6750e857..30c9519e 100644 --- a/packages/core/src/file-command.ts +++ b/packages/core/src/file-command.ts @@ -3,6 +3,7 @@ // We use any as a valid input type /* eslint-disable @typescript-eslint/no-explicit-any */ +import * as crypto from 'crypto' import * as fs from 'fs' import * as os from 'os' import {toCommandValue} from './utils' diff --git a/packages/tool-cache/src/tool-cache.ts b/packages/tool-cache/src/tool-cache.ts index f7a7545b..961c26b8 100644 --- a/packages/tool-cache/src/tool-cache.ts +++ b/packages/tool-cache/src/tool-cache.ts @@ -1,5 +1,6 @@ import * as core from '@actions/core' import * as io from '@actions/io' +import * as crypto from 'crypto' import * as fs from 'fs' import * as mm from './manifest' import * as os from 'os'