Skip to content

Commit

Permalink
remove uuid package and switch to crypto
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Oct 3, 2024
1 parent 5334dd0 commit e0e5ecf
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 29 deletions.
4 changes: 1 addition & 3 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -26,8 +25,7 @@ jest.spyOn(Context, 'tmpName').mockImplementation((): string => {
return tmpName;
});

jest.mock('uuid');
jest.spyOn(uuid, 'v4').mockReturnValue('9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d');
jest.spyOn(crypto, 'randomUUID').mockReturnValue('9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d');

jest.spyOn(Docker, 'context').mockImplementation((): Promise<string> => {
return Promise.resolve('default');
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@docker/actions-toolkit": "^0.35.0",
"js-yaml": "^4.1.0",
"uuid": "^10.0.0"
"js-yaml": "^4.1.0"
},
"devDependencies": {
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.12.12",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^7.9.0",
"@typescript-eslint/parser": "^7.9.0",
"@vercel/ncc": "^0.38.1",
Expand Down
5 changes: 2 additions & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as uuid from 'uuid';
import * as core from '@actions/core';

import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
Expand Down Expand Up @@ -47,7 +46,7 @@ export async function getInputs(): Promise<Inputs> {
}

export async function getBuilderName(driver: string): Promise<string> {
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<Array<string>> {
Expand Down Expand Up @@ -84,7 +83,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) => {
Expand Down
3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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';

Expand Down Expand Up @@ -98,7 +97,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
Expand Down
18 changes: 0 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2124,13 +2124,6 @@ __metadata:
languageName: node
linkType: hard

"@types/uuid@npm:^10.0.0":
version: 10.0.0
resolution: "@types/uuid@npm:10.0.0"
checksum: e3958f8b0fe551c86c14431f5940c3470127293280830684154b91dc7eb3514aeb79fe3216968833cf79d4d1c67f580f054b5be2cd562bebf4f728913e73e944
languageName: node
linkType: hard

"@types/yargs-parser@npm:*":
version: 20.2.0
resolution: "@types/yargs-parser@npm:20.2.0"
Expand Down Expand Up @@ -3171,7 +3164,6 @@ __metadata:
"@docker/actions-toolkit": ^0.35.0
"@types/js-yaml": ^4.0.9
"@types/node": ^20.12.12
"@types/uuid": ^10.0.0
"@typescript-eslint/eslint-plugin": ^7.9.0
"@typescript-eslint/parser": ^7.9.0
"@vercel/ncc": ^0.38.1
Expand All @@ -3185,7 +3177,6 @@ __metadata:
ts-jest: ^29.1.2
ts-node: ^10.9.2
typescript: ^5.4.5
uuid: ^10.0.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -6670,15 +6661,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"
Expand Down

0 comments on commit e0e5ecf

Please sign in to comment.