Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions actions/submit-signing-request/helper-artifact-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ export class HelperArtifactDownload {
core.info(`The signed artifact has been successfully downloaded from SignPath and extracted to ${targetDirectory}`);
}

private resolveOrCreateDirectory(relativePath:string): string {
const absolutePath = path.join(process.env.GITHUB_WORKSPACE as string, relativePath)
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);

if (!fs.existsSync(absolutePath)) {
core.info(`Directory "${absolutePath}" does not exist and will be created`);
fs.mkdirSync(absolutePath, { recursive: true });
}
return absolutePath;
}
}
}
Original file line number Diff line number Diff line change
@@ -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 })
}
})
})
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading