Update tests + cleanup

This commit is contained in:
Konrad Pabjan
2023-10-30 14:58:12 -04:00
parent d45e4be1a6
commit fa898e325d
9 changed files with 247 additions and 633 deletions

341
dist/index.js generated vendored
View File

@@ -4090,104 +4090,6 @@ exports.restEndpointMethods = restEndpointMethods;
//# sourceMappingURL=index.js.map
/***/ }),
/***/ 537:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// pkg/dist-src/index.js
var dist_src_exports = {};
__export(dist_src_exports, {
RequestError: () => RequestError
});
module.exports = __toCommonJS(dist_src_exports);
var import_deprecation = __nccwpck_require__(8932);
var import_once = __toESM(__nccwpck_require__(1223));
var logOnceCode = (0, import_once.default)((deprecation) => console.warn(deprecation));
var logOnceHeaders = (0, import_once.default)((deprecation) => console.warn(deprecation));
var RequestError = class extends Error {
constructor(message, statusCode, options) {
super(message);
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
this.name = "HttpError";
this.status = statusCode;
let headers;
if ("headers" in options && typeof options.headers !== "undefined") {
headers = options.headers;
}
if ("response" in options) {
this.response = options.response;
headers = options.response.headers;
}
const requestCopy = Object.assign({}, options.request);
if (options.request.headers.authorization) {
requestCopy.headers = Object.assign({}, options.request.headers, {
authorization: options.request.headers.authorization.replace(
/ .*$/,
" [REDACTED]"
)
});
}
requestCopy.url = requestCopy.url.replace(/\bclient_secret=\w+/g, "client_secret=[REDACTED]").replace(/\baccess_token=\w+/g, "access_token=[REDACTED]");
this.request = requestCopy;
Object.defineProperty(this, "code", {
get() {
logOnceCode(
new import_deprecation.Deprecation(
"[@octokit/request-error] `error.code` is deprecated, use `error.status`."
)
);
return statusCode;
}
});
Object.defineProperty(this, "headers", {
get() {
logOnceHeaders(
new import_deprecation.Deprecation(
"[@octokit/request-error] `error.headers` is deprecated, use `error.response.headers`."
)
);
return headers || {};
}
});
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (0);
/***/ }),
/***/ 6234:
@@ -4664,102 +4566,6 @@ class Deprecation extends Error {
exports.Deprecation = Deprecation;
/***/ }),
/***/ 3703:
/***/ ((module) => {
// Source: 2014-06-11: http://en.wikipedia.org/wiki/HTTP_status_codes
module.exports = {
100: "Continue",
101: "Switching Protocols",
102: "Processing",
200: "OK",
201: "Created",
202: "Accepted",
203: "Non-Authoritative Information",
204: "No Content",
205: "Reset Content",
206: "Partial Content",
207: "Multi-Status",
208: "Already Reported",
226: "IM Used",
300: "Multiple Choices",
301: "Moved Permanently",
302: "Found",
303: "See Other",
304: "Not Modified",
305: "Use Proxy",
306: "Switch Proxy",
307: "Temporary Redirect",
308: "Permanent Redirect",
400: "Bad Request",
401: "Unauthorized",
402: "Payment Required",
403: "Forbidden",
404: "Not Found",
405: "Method Not Allowed",
406: "Not Acceptable",
407: "Proxy Authentication Required",
408: "Request Timeout",
409: "Conflict",
410: "Gone",
411: "Length Required",
412: "Precondition Failed",
413: "Request Entity Too Large",
414: "Request-URI Too Long",
415: "Unsupported Media Type",
416: "Requested Range Not Satisfiable",
417: "Expectation Failed",
418: "I'm a teapot",
419: "Authentication Timeout",
420: "Method Failure",
420: "Enhance Your Calm",
422: "Unprocessable Entity",
423: "Locked",
424: "Failed Dependency",
426: "Upgrade Required",
428: "Precondition Required",
429: "Too Many Requests",
431: "Request Header Fields Too Large",
440: "Login Timeout",
444: "No Response",
449: "Retry With",
450: "Blocked by Windows Parental Controls",
451: "Unavailable For Legal Reasons",
451: "Redirect",
494: "Request Header Too Large",
495: "Cert Error",
496: "No Cert",
497: "HTTP to HTTPS",
499: "Client Closed Request",
500: "Internal Server Error",
501: "Not Implemented",
502: "Bad Gateway",
503: "Service Unavailable",
504: "Gateway Timeout",
505: "HTTP Version Not Supported",
506: "Variant Also Negotiates",
507: "Insufficient Storage",
508: "Loop Detected",
509: "Bandwidth Limit Exceeded",
510: "Not Extended",
511: "Network Authentication Required",
520: "Origin Error",
521: "Web server is down",
522: "Connection timed out",
523: "Proxy Declined Request",
524: "A timeout occurred",
598: "Network read timeout error",
599: "Network connect timeout error"
};
/***/ }),
/***/ 3287:
@@ -9811,59 +9617,6 @@ function wrappy (fn, cb) {
const core = __nccwpck_require__(2186)
const github = __nccwpck_require__(5438)
const hc = __nccwpck_require__(6255)
const { RequestError } = __nccwpck_require__(537)
const HttpStatusMessages = __nccwpck_require__(3703)
// All variables we need from the runtime are loaded here
const getContext = __nccwpck_require__(8454)
async function processRuntimeResponse(res, requestOptions) {
// Parse the response body as JSON
let obj = null
try {
const contents = await res.readBody()
if (contents && contents.length > 0) {
obj = JSON.parse(contents)
}
} catch (error) {
// Invalid resource (contents not json); leaving resulting obj as null
}
// Specific response shape aligned with Octokit
const response = {
url: res.message?.url || requestOptions.url,
status: res.message?.statusCode || 0,
headers: {
...res.message?.headers
},
data: obj
}
// Forcibly throw errors for negative HTTP status codes!
// @actions/http-client doesn't do this by default.
// Mimic the errors thrown by Octokit for consistency.
if (response.status >= 400) {
// Try to get an error message from the response body
const errorMsg =
(typeof response.data === 'string' && response.data) ||
response.data?.error ||
response.data?.message ||
// Try the Node HTTP IncomingMessage's statusMessage property
res.message?.statusMessage ||
// Fallback to the HTTP status message based on the status code
HttpStatusMessages[response.status] ||
// Or if the status code is unexpected...
`Unknown error (${response.status})`
throw new RequestError(errorMsg, response.status, {
response,
request: requestOptions
})
}
return response
}
async function getArtifactMetadata({ githubToken, runId, artifactName }) {
const octokit = github.getOctokit(githubToken)
@@ -9871,22 +9624,29 @@ async function getArtifactMetadata({ githubToken, runId, artifactName }) {
try {
core.info(`Fetching artifact metadata for ${artifactName} in run ${runId}`)
const response = await octokit.request("GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts?name={artifactName}", {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
run_id: runId,
artifactName: artifactName
})
const response = await octokit.request(
'GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts?name={artifactName}',
{
owner: github.context.repo.owner,
repo: github.context.repo.repo,
run_id: runId,
artifactName: artifactName
}
)
const artifactCount = response.data.total_count
core.debug(`List artifact count: ${artifactCount}`)
if (artifactCount === 0) {
throw new Error(`No artifacts found for workflow run ${runId}. Ensure artifacts are uploaded with actions/artifact@v4 or later.`)
throw new Error(
`No artifacts found for workflow run ${runId}. Ensure artifacts are uploaded with actions/artifact@v4 or later.`
)
} else if (artifactCount > 1) {
throw new Error(`Multiple artifact unexpectedly found for workflow run ${runId}. Artifact count is ${artifactCount}.`)
throw new Error(
`Multiple artifact unexpectedly found for workflow run ${runId}. Artifact count is ${artifactCount}.`
)
}
const artifact = response.data.artifacts[0]
core.debug(`Artifact: ${JSON.stringify(artifact)}`)
@@ -9894,7 +9654,7 @@ async function getArtifactMetadata({ githubToken, runId, artifactName }) {
if (!artifactSize) {
core.warning('Artifact size was not found. Unable to verify if artifact size exceeds the allowed size.')
}
return {
id: artifact.id,
size: artifactSize
@@ -9905,61 +9665,6 @@ async function getArtifactMetadata({ githubToken, runId, artifactName }) {
}
}
async function getSignedArtifactMetadata({ runtimeToken, workflowRunId, artifactName }) {
const { runTimeUrl: RUNTIME_URL } = getContext()
const artifactExchangeUrl = `${RUNTIME_URL}_apis/pipelines/workflows/${workflowRunId}/artifacts?api-version=6.0-preview`
const httpClient = new hc.HttpClient()
let data = null
try {
const requestHeaders = {
accept: 'application/json',
authorization: `Bearer ${runtimeToken}`
}
const requestOptions = {
method: 'GET',
url: artifactExchangeUrl,
headers: {
...requestHeaders
},
body: null
}
core.info(`Artifact exchange URL: ${artifactExchangeUrl}`)
const res = await httpClient.get(artifactExchangeUrl, requestHeaders)
// May throw a RequestError (HttpError)
const response = await processRuntimeResponse(res, requestOptions)
data = response.data
core.debug(JSON.stringify(data))
} catch (error) {
core.error('Getting signed artifact URL failed', error)
throw error
}
const artifact = data?.value?.find(artifact => artifact.name === artifactName)
const artifactRawUrl = artifact?.url
if (!artifactRawUrl) {
throw new Error(
'No uploaded artifact was found! Please check if there are any errors at build step, or uploaded artifact name is correct.'
)
}
const signedArtifactUrl = `${artifactRawUrl}&%24expand=SignedContent`
const artifactSize = artifact?.size
if (!artifactSize) {
core.warning('Artifact size was not found. Unable to verify if artifact size exceeds the allowed size.')
}
return {
url: signedArtifactUrl,
size: artifactSize
}
}
async function createPagesDeployment({ githubToken, artifactId, buildVersion, idToken, isPreview = false }) {
const octokit = github.getOctokit(githubToken)
@@ -10025,7 +9730,6 @@ async function cancelPagesDeployment({ githubToken, deploymentId }) {
module.exports = {
getArtifactMetadata,
getSignedArtifactMetadata,
createPagesDeployment,
getPagesDeploymentStatus,
cancelPagesDeployment
@@ -10076,7 +9780,12 @@ const core = __nccwpck_require__(2186)
// All variables we need from the runtime are loaded here
const getContext = __nccwpck_require__(8454)
const { getArtifactMetadata, getPagesDeploymentStatus, createPagesDeployment, cancelPagesDeployment } = __nccwpck_require__(572)
const {
getArtifactMetadata,
getPagesDeploymentStatus,
createPagesDeployment,
cancelPagesDeployment
} = __nccwpck_require__(572)
const temporaryErrorStatus = {
unknown_status: 'Unable to get deployment status.',
@@ -10132,15 +9841,12 @@ class Deployment {
core.debug(`Action ID: ${this.actionsId}`)
core.debug(`Actions Workflow Run ID: ${this.workflowRun}`)
core.info("Getting artifact's metadata...")
const artifactData = await getArtifactMetadata({
githubToken: this.githubToken,
runId: this.workflowRun,
artifactName: this.artifactName
})
console.log(artifactData)
if (artifactData?.size > ONE_GIGABYTE) {
core.warning(
`Uploaded artifact size of ${artifactData?.size} bytes exceeds the allowed size of ${SIZE_LIMIT_DESCRIPTION}. Deployment might fail.`
@@ -10317,6 +10023,7 @@ class Deployment {
module.exports = { Deployment, MAX_TIMEOUT, ONE_GIGABYTE, SIZE_LIMIT_DESCRIPTION }
/***/ }),
/***/ 2877:

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

2
dist/licenses.txt generated vendored
View File

@@ -453,8 +453,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
http-status-messages
is-plain-object
MIT
The MIT License (MIT)