-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add tool-cache #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tool-cache #12
Changes from 1 commit
20bb325
044ccbe
9ca4353
2c78503
21da019
911e847
87cf56d
7e6cc16
f27fda8
a08760e
eb02e1f
17167af
d994756
e3cbf7b
1ad4b89
2d58290
950b8a8
4f35290
020aa68
6e5e3c3
2e8d81f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,11 +8,13 @@ import * as semver from 'semver' | |
| import * as uuidV4 from 'uuid/v4' | ||
| import {exec} from '@actions/exec/lib/exec' | ||
| import {ExecOptions} from '@actions/exec/lib/interfaces' | ||
| import {ok} from 'assert' | ||
|
|
||
| // Add index signature so that we can attach additional fields without breaking type checking (e.g. httpStatusCode) | ||
| interface Error { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| [key: string]: any | ||
| class HTTPError extends Error { | ||
| constructor(readonly httpStatusCode: number | undefined) { | ||
| super(`Unexpected HTTP response: ${httpStatusCode}`) | ||
| Object.setPrototypeOf(this, new.target.prototype) | ||
| } | ||
| } | ||
|
|
||
| const IS_WINDOWS = process.platform === 'win32' | ||
|
|
@@ -30,7 +32,11 @@ if (!tempDirectory || !cacheRoot) { | |
| // On windows use the USERPROFILE env variable | ||
| baseLocation = process.env['USERPROFILE'] || 'C:\\' | ||
| } else { | ||
| baseLocation = '/home' | ||
| if (process.platform === 'darwin') { | ||
| baseLocation = '/Users' | ||
| } else { | ||
| baseLocation = '/home' | ||
| } | ||
| } | ||
| if (!tempDirectory) { | ||
| tempDirectory = path.join(baseLocation, 'actions', 'temp') | ||
|
|
@@ -47,13 +53,14 @@ if (!tempDirectory || !cacheRoot) { | |
| * @returns path to downloaded tool | ||
| */ | ||
| export async function downloadTool(url: string): Promise<string> { | ||
| // Wrap in a promise so that we can resolve from within stream callbacks | ||
| return new Promise<string>(async (resolve, reject) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to construct a promise here manually, do we? If so, I think a comment is warranted. Keep in mind that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrapped it so that I can resolve from within the stream callbacks. e.g. If I just return normally there, it just returns from the callback. Is there an easier way to handle that? Added a comment for now |
||
| try { | ||
| const http: httpm.HttpClient = new httpm.HttpClient(userAgent, [], { | ||
| const http = new httpm.HttpClient(userAgent, [], { | ||
| allowRetries: true, | ||
| maxRetries: 3 | ||
| }) | ||
| const destPath: string = path.join(tempDirectory, uuidV4()) | ||
| const destPath = path.join(tempDirectory, uuidV4()) | ||
|
|
||
| await io.mkdirP(tempDirectory) | ||
| core.debug(`Downloading ${url}`) | ||
|
|
@@ -66,15 +73,12 @@ export async function downloadTool(url: string): Promise<string> { | |
| const response: httpm.HttpClientResponse = await http.get(url) | ||
|
|
||
| if (response.message.statusCode !== 200) { | ||
| const err: Error = new Error( | ||
| `Unexpected HTTP response: ${response.message.statusCode}` | ||
| ) | ||
| const err = new HTTPError(response.message.statusCode) | ||
| core.debug( | ||
| `Failed to download from "${url}". Code(${ | ||
| response.message.statusCode | ||
| }) Message(${response.message.statusMessage})` | ||
| ) | ||
| err['httpStatusCode'] = response.message.statusCode | ||
| throw err | ||
| } | ||
|
|
||
|
|
@@ -113,40 +117,35 @@ export async function downloadTool(url: string): Promise<string> { | |
| * @returns path to the destination directory | ||
| */ | ||
| export async function extract7z(file: string, dest?: string): Promise<string> { | ||
| if (!IS_WINDOWS) { | ||
| throw new Error('extract7z() not supported on current OS') | ||
| } | ||
|
|
||
| if (!file) { | ||
| throw new Error("parameter 'file' is required") | ||
| } | ||
| ok(IS_WINDOWS, 'extract7z() not supported on current OS') | ||
| ok(file, 'parameter "file" is required') | ||
|
|
||
| dest = dest || (await _createExtractFolder(dest)) | ||
|
|
||
| const originalCwd = process.cwd() | ||
| process.chdir(dest) | ||
| const escapedScript = path | ||
| .join(__dirname, '..', 'scripts', 'Invoke-7zdec.ps1') | ||
| .replace(/'/g, "''") | ||
| .replace(/"|\n|\r/g, '') // double-up single quotes, remove double quotes and newlines | ||
| const escapedFile = file.replace(/'/g, "''").replace(/"|\n|\r/g, '') | ||
| const escapedTarget = dest.replace(/'/g, "''").replace(/"|\n|\r/g, '') | ||
| const command = `& '${escapedScript}' -Source '${escapedFile}' -Target '${escapedTarget}'` | ||
| const args: string[] = [ | ||
| '-NoLogo', | ||
| '-Sta', | ||
| '-NoProfile', | ||
| '-NonInteractive', | ||
| '-ExecutionPolicy', | ||
| 'Unrestricted', | ||
| '-Command', | ||
| command | ||
| ] | ||
| const options: ExecOptions = { | ||
| silent: true | ||
| } | ||
| try { | ||
damccorm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| process.chdir(dest) | ||
| const escapedScript = path | ||
| .join(__dirname, '..', 'scripts', 'Invoke-7zdec.ps1') | ||
| .replace(/'/g, "''") | ||
| .replace(/"|\n|\r/g, '') // double-up single quotes, remove double quotes and newlines | ||
| const escapedFile = file.replace(/'/g, "''").replace(/"|\n|\r/g, '') | ||
| const escapedTarget = dest.replace(/'/g, "''").replace(/"|\n|\r/g, '') | ||
| const command = `& '${escapedScript}' -Source '${escapedFile}' -Target '${escapedTarget}'` | ||
| const powershellPath: string = await io.which('powershell', true) | ||
| const args: string[] = [ | ||
| '-NoLogo', | ||
| '-Sta', | ||
| '-NoProfile', | ||
| '-NonInteractive', | ||
| '-ExecutionPolicy', | ||
| 'Unrestricted', | ||
| '-Command', | ||
| command | ||
| ] | ||
| const options: ExecOptions = { | ||
| silent: true | ||
| } | ||
| await exec(`"${powershellPath}"`, args, options) | ||
| } finally { | ||
| process.chdir(originalCwd) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.