From 2ab03f1dd5cc71e466b283b7c781b696c6e3fb6a Mon Sep 17 00:00:00 2001 From: Volodymyr Bobko Date: Fri, 11 Apr 2025 13:51:14 +0200 Subject: [PATCH 1/3] SIGN-7496 - enhance directory resolution logic in HelperArtifactDownload --- actions/submit-signing-request/helper-artifact-download.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/actions/submit-signing-request/helper-artifact-download.ts b/actions/submit-signing-request/helper-artifact-download.ts index 4778b01..a2b149a 100644 --- a/actions/submit-signing-request/helper-artifact-download.ts +++ b/actions/submit-signing-request/helper-artifact-download.ts @@ -68,11 +68,14 @@ export class HelperArtifactDownload { } private resolveOrCreateDirectory(relativePath:string): string { - const absolutePath = path.join(process.env.GITHUB_WORKSPACE as string, relativePath) + const workingDirectory = process.env.GITHUB_WORKSPACE as string; + const absolutePath = path.isAbsolute(relativePath) ? relativePath : + path.join(workingDirectory as string, relativePath); + if (!fs.existsSync(absolutePath)) { core.info(`Directory "${absolutePath}" does not exist and will be created`); fs.mkdirSync(absolutePath, { recursive: true }); } return absolutePath; } -} \ No newline at end of file +} From 892d8c6cc9d1bb4e27ef85b08fa22ae7f5004e99 Mon Sep 17 00:00:00 2001 From: Taha Al Khashmany Date: Wed, 23 Apr 2025 16:18:05 +0200 Subject: [PATCH 2/3] SIGN-7496 Improve naming --- actions/submit-signing-request/helper-artifact-download.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/actions/submit-signing-request/helper-artifact-download.ts b/actions/submit-signing-request/helper-artifact-download.ts index a2b149a..ca14e18 100644 --- a/actions/submit-signing-request/helper-artifact-download.ts +++ b/actions/submit-signing-request/helper-artifact-download.ts @@ -67,10 +67,10 @@ export class HelperArtifactDownload { core.info(`The signed artifact has been successfully downloaded from SignPath and extracted to ${targetDirectory}`); } - private resolveOrCreateDirectory(relativePath:string): string { + private resolveOrCreateDirectory(directoryPath:string): string { const workingDirectory = process.env.GITHUB_WORKSPACE as string; - const absolutePath = path.isAbsolute(relativePath) ? relativePath : - path.join(workingDirectory as string, relativePath); + const absolutePath = path.isAbsolute(directoryPath) ? directoryPath : + path.join(workingDirectory as string, directoryPath); if (!fs.existsSync(absolutePath)) { core.info(`Directory "${absolutePath}" does not exist and will be created`); From 3c29ba245cb52098b46b5e268c027f3d7aa80995 Mon Sep 17 00:00:00 2001 From: Taha Al Khashmany Date: Thu, 24 Apr 2025 14:40:42 +0200 Subject: [PATCH 3/3] SIGN-7469 Add unit test --- .../helper-artifact-download.ts | 2 +- .../tests/helper-artifact-download.test.ts | 51 +++++++++++++++++++ package-lock.json | 14 +++++ package.json | 1 + 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 actions/submit-signing-request/tests/helper-artifact-download.test.ts diff --git a/actions/submit-signing-request/helper-artifact-download.ts b/actions/submit-signing-request/helper-artifact-download.ts index ca14e18..ce97e6e 100644 --- a/actions/submit-signing-request/helper-artifact-download.ts +++ b/actions/submit-signing-request/helper-artifact-download.ts @@ -67,7 +67,7 @@ export class HelperArtifactDownload { core.info(`The signed artifact has been successfully downloaded from SignPath and extracted to ${targetDirectory}`); } - private resolveOrCreateDirectory(directoryPath:string): string { + public resolveOrCreateDirectory(directoryPath:string): string { const workingDirectory = process.env.GITHUB_WORKSPACE as string; const absolutePath = path.isAbsolute(directoryPath) ? directoryPath : path.join(workingDirectory as string, directoryPath); diff --git a/actions/submit-signing-request/tests/helper-artifact-download.test.ts b/actions/submit-signing-request/tests/helper-artifact-download.test.ts new file mode 100644 index 0000000..a973255 --- /dev/null +++ b/actions/submit-signing-request/tests/helper-artifact-download.test.ts @@ -0,0 +1,51 @@ +import { assert, expect } from "chai"; +import { HelperArtifactDownload } from "../helper-artifact-download" +import * as path from 'path'; +import * as os from 'os'; +import * as uuid from 'uuid'; +import * as fs from 'fs' +import { HelperInputOutput } from "../helper-input-output"; + +describe("Artifact path resolving tests", () => { + before(() => { process.env.GITHUB_WORKSPACE = __dirname; }); + after(() => { process.env.GITHUB_WORKSPACE = undefined; }); + + [".", "..", "fake", "fake/path"].forEach(relativePathBase => { + it("Should resolve relative paths to absolute paths", () => { + const sut = new HelperArtifactDownload(new HelperInputOutput()); + const dirName = uuid.v4(); + const relativePath = path.join(relativePathBase, dirName); + const expectedAbsolutePath = path.join(__dirname, relativePath); + + let actualResolvedPath: fs.PathLike = ""; + try { + // ACT + actualResolvedPath = sut.resolveOrCreateDirectory(relativePath); + + // ASSERT + assert.equal(actualResolvedPath, expectedAbsolutePath); + } + finally { + fs.rmSync(actualResolvedPath, { force: true, recursive: true }) + } + }) + }) + + it("Should detect and recognize absolute paths", () => { + const sut = new HelperArtifactDownload(new HelperInputOutput()); + const dirName = uuid.v4(); + const expectedAbsolutePath = path.join(__dirname, dirName); + + let actualResolvedPath: fs.PathLike = ""; + try { + // ACT + actualResolvedPath = sut.resolveOrCreateDirectory(expectedAbsolutePath); + + // ASSERT + assert.equal(actualResolvedPath, expectedAbsolutePath); + } + finally { + fs.rmSync(actualResolvedPath, { force: true, recursive: true }) + } + }) +}) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ee73b35..4f1d5f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "@types/node": "^18.7.23", "@types/q": "^1.5.5", "@types/sinon": "^10.0.13", + "@types/uuid": "^10.0.0", "@vercel/ncc": "^0.36.1", "chai": "^4.3.7", "minimist": "^1.2.6", @@ -393,6 +394,13 @@ "integrity": "sha512-mQkU2jY8jJEF7YHjHvsQO8+3ughTL1mcnn96igfhONmR+fUPSKIkefQYpSe8bsly2Ep7oQbn/6VG5/9/0qcArQ==", "dev": true }, + "node_modules/@types/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@vercel/ncc": { "version": "0.36.1", "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.36.1.tgz", @@ -3373,6 +3381,12 @@ "integrity": "sha512-mQkU2jY8jJEF7YHjHvsQO8+3ughTL1mcnn96igfhONmR+fUPSKIkefQYpSe8bsly2Ep7oQbn/6VG5/9/0qcArQ==", "dev": true }, + "@types/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==", + "dev": true + }, "@vercel/ncc": { "version": "0.36.1", "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.36.1.tgz", diff --git a/package.json b/package.json index c956ba6..a859697 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@types/node": "^18.7.23", "@types/q": "^1.5.5", "@types/sinon": "^10.0.13", + "@types/uuid": "^10.0.0", "@vercel/ncc": "^0.36.1", "chai": "^4.3.7", "minimist": "^1.2.6",