From d391aad55caa911315da29a112d63a395b1382d7 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:16:41 +0200 Subject: [PATCH] remove uuid package and switch to crypto Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- __tests__/context.test.ts | 9 ++++++--- package.json | 3 +-- src/context.ts | 6 +++--- src/main.ts | 4 ++-- yarn.lock | 10 ---------- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 8a2b367..259123f 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -1,7 +1,6 @@ import {beforeEach, describe, expect, jest, test} from '@jest/globals'; import * as fs from 'fs'; import * as path from 'path'; -import * as uuid from 'uuid'; import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx'; import {Context} from '@docker/actions-toolkit/lib/context'; import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; @@ -26,8 +25,12 @@ jest.spyOn(Context, 'tmpName').mockImplementation((): string => { return tmpName; }); -jest.mock('uuid'); -jest.spyOn(uuid, 'v4').mockReturnValue('9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'); +jest.mock('crypto', () => { + return { + ...(jest.requireActual('crypto') as object), + randomUUID: jest.fn(() => '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d') + }; +}); jest.spyOn(Docker, 'context').mockImplementation((): Promise => { return Promise.resolve('default'); diff --git a/package.json b/package.json index 6d292a6..0716ae6 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,7 @@ "dependencies": { "@actions/core": "^1.11.1", "@docker/actions-toolkit": "^0.39.0", - "js-yaml": "^4.1.0", - "uuid": "^10.0.0" + "js-yaml": "^4.1.0" }, "devDependencies": { "@types/js-yaml": "^4.0.9", diff --git a/src/context.ts b/src/context.ts index 4fb8d47..fc09cfb 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,4 +1,4 @@ -import * as uuid from 'uuid'; +import * as crypto from 'crypto'; import * as core from '@actions/core'; import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; @@ -47,7 +47,7 @@ export async function getInputs(): Promise { } export async function getBuilderName(driver: string): Promise { - return driver == 'docker' ? await Docker.context() : `builder-${uuid.v4()}`; + return driver == 'docker' ? await Docker.context() : `builder-${crypto.randomUUID()}`; } export async function getCreateArgs(inputs: Inputs, toolkit: Toolkit): Promise> { @@ -84,7 +84,7 @@ export async function getAppendArgs(inputs: Inputs, node: Node, toolkit: Toolkit if (node.name) { args.push('--node', node.name); } else if (inputs.driver == 'kubernetes' && (await toolkit.buildx.versionSatisfies('<0.11.0'))) { - args.push('--node', `node-${uuid.v4()}`); + args.push('--node', `node-${crypto.randomUUID()}`); } if (node['driver-opts'] && (await toolkit.buildx.versionSatisfies('>=0.3.0'))) { await Util.asyncForEach(node['driver-opts'], async (driverOpt: string) => { diff --git a/src/main.ts b/src/main.ts index e214991..698978d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,6 @@ +import * as crypto from 'crypto'; import * as fs from 'fs'; import * as yaml from 'js-yaml'; -import * as uuid from 'uuid'; import * as core from '@actions/core'; import * as actionsToolkit from '@docker/actions-toolkit'; @@ -98,7 +98,7 @@ actionsToolkit.run( }); }); if (defaultContextWithTLS) { - const tmpDockerContext = `buildx-${uuid.v4()}`; + const tmpDockerContext = `buildx-${crypto.randomUUID()}`; await core.group(`Creating temp docker context (TLS data loaded in default one)`, async () => { await Docker.getExecOutput(['context', 'create', tmpDockerContext], { ignoreReturnCode: true diff --git a/yarn.lock b/yarn.lock index 66e5154..0364350 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3205,7 +3205,6 @@ __metadata: ts-jest: ^29.1.2 ts-node: ^10.9.2 typescript: ^5.4.5 - uuid: ^10.0.0 languageName: unknown linkType: soft @@ -6690,15 +6689,6 @@ __metadata: languageName: node linkType: hard -"uuid@npm:^10.0.0": - version: 10.0.0 - resolution: "uuid@npm:10.0.0" - bin: - uuid: dist/bin/uuid - checksum: 4b81611ade2885d2313ddd8dc865d93d8dccc13ddf901745edca8f86d99bc46d7a330d678e7532e7ebf93ce616679fb19b2e3568873ac0c14c999032acb25869 - languageName: node - linkType: hard - "uuid@npm:^3.3.2, uuid@npm:^3.3.3": version: 3.4.0 resolution: "uuid@npm:3.4.0"