diff --git a/package-lock.json b/package-lock.json index bac0672..14ef396 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,8 +14,6 @@ "@actions/github": "^6.0.0", "@types/fs-extra": "^11.0.4", "archiver": "^6.0.1", - "axios": "^1.6.2", - "axios-debug-log": "^1.0.0", "fs-extra": "^11.2.0", "tar": "^6.2.0" }, @@ -1565,14 +1563,6 @@ "@babel/types": "^7.20.7" } }, - "node_modules/@types/debug": { - "version": "4.1.12", - "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", - "integrity": "sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==", - "dependencies": { - "@types/ms": "*" - } - }, "node_modules/@types/eslint": { "version": "8.44.2", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.2.tgz", @@ -1671,11 +1661,6 @@ "integrity": "sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==", "dev": true }, - "node_modules/@types/ms": { - "version": "0.7.34", - "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.34.tgz", - "integrity": "sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==" - }, "node_modules/@types/node": { "version": "20.11.13", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.13.tgz", @@ -2383,7 +2368,8 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true }, "node_modules/available-typed-arrays": { "version": "1.0.5", @@ -2410,24 +2396,13 @@ "version": "1.6.2", "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", + "dev": true, "dependencies": { "follow-redirects": "^1.15.0", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } }, - "node_modules/axios-debug-log": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/axios-debug-log/-/axios-debug-log-1.0.0.tgz", - "integrity": "sha512-ZjMaEBEij9w+Vbk2Uc3XflchTT7j9rZdYD/snN+XQ5FRDq1QjZNhh0Izb3KSyarU5vTkiCvJyg1xDiQBHZZB9w==", - "dependencies": { - "@types/debug": "^4.0.0", - "debug": "^4.0.0" - }, - "peerDependencies": { - "axios": ">=1.0.0" - } - }, "node_modules/axobject-query": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz", @@ -2814,6 +2789,7 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -2929,6 +2905,7 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, "dependencies": { "ms": "2.1.2" }, @@ -2990,6 +2967,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, "engines": { "node": ">=0.4.0" } @@ -4044,6 +4022,7 @@ "version": "1.15.3", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "dev": true, "funding": [ { "type": "individual", @@ -4072,6 +4051,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -5908,6 +5888,7 @@ "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true, "engines": { "node": ">= 0.6" } @@ -5916,6 +5897,7 @@ "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, "dependencies": { "mime-db": "1.52.0" }, @@ -6012,7 +5994,8 @@ "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true }, "node_modules/natural-compare": { "version": "1.4.0", @@ -6508,7 +6491,8 @@ "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "dev": true }, "node_modules/punycode": { "version": "2.3.1", diff --git a/package.json b/package.json index 3479f39..4bff463 100644 --- a/package.json +++ b/package.json @@ -72,8 +72,6 @@ "@actions/github": "^6.0.0", "@types/fs-extra": "^11.0.4", "archiver": "^6.0.1", - "axios": "^1.6.2", - "axios-debug-log": "^1.0.0", "fs-extra": "^11.2.0", "tar": "^6.2.0" }, diff --git a/src/ghcr-client.ts b/src/ghcr-client.ts index 6e61de1..0ec2832 100644 --- a/src/ghcr-client.ts +++ b/src/ghcr-client.ts @@ -1,9 +1,9 @@ import * as core from '@actions/core' import { FileMetadata } from './fs-helper' import * as ociContainer from './oci-container' -import axios from 'axios' import * as fsHelper from './fs-helper' -import axiosDebugLog from 'axios-debug-log' + +let showDebugLog = false // Publish the OCI artifact and return the URL where it can be downloaded export async function publishOCIArtifact( @@ -17,7 +17,7 @@ export async function publishOCIArtifact( debugRequests = false ): Promise<{ packageURL: URL; manifestDigest: string }> { if (debugRequests) { - configureRequestDebugLogging() + showDebugLog = true } const b64Token = Buffer.from(token).toString('base64') @@ -95,14 +95,12 @@ async function uploadLayer( uploadBlobEndpoint: string, b64Token: string ): Promise { - const checkExistsResponse = await axios.head( + const checkExistsResponse = await fetchWithDebug( checkBlobEndpoint + layer.digest, { + method: 'HEAD', headers: { Authorization: `Bearer ${b64Token}` - }, - validateStatus: () => { - return true // Allow non 2xx responses } } ) @@ -123,13 +121,12 @@ async function uploadLayer( core.info(`Uploading layer ${layer.digest}.`) - const initiateUploadResponse = await axios.post(uploadBlobEndpoint, layer, { + const initiateUploadResponse = await fetchWithDebug(uploadBlobEndpoint, { + method: 'POST', headers: { Authorization: `Bearer ${b64Token}` }, - validateStatus: () => { - return true // Allow non 2xx responses - } + body: JSON.stringify(layer) }) if (initiateUploadResponse.status !== 202) { @@ -141,7 +138,7 @@ async function uploadLayer( ) } - const locationResponseHeader = initiateUploadResponse.headers['location'] + const locationResponseHeader = initiateUploadResponse.headers.get('location') if (locationResponseHeader === undefined) { throw new Error( `No location header in response from upload post ${uploadBlobEndpoint} for layer ${layer.digest}` @@ -159,16 +156,15 @@ async function uploadLayer( data = fsHelper.readFileContents(file.path) } - const putResponse = await axios.put(uploadBlobUrl, data, { + const putResponse = await fetchWithDebug(uploadBlobUrl, { + method: 'PUT', headers: { Authorization: `Bearer ${b64Token}`, 'Content-Type': 'application/octet-stream', 'Accept-Encoding': 'gzip', 'Content-Length': layer.size.toString() }, - validateStatus: () => { - return true // Allow non 2xx responses - } + body: data }) if (putResponse.status !== 201) { @@ -186,14 +182,13 @@ async function uploadManifest( ): Promise { core.info(`Uploading manifest to ${manifestEndpoint}.`) - const putResponse = await axios.put(manifestEndpoint, manifestJSON, { + const putResponse = await fetchWithDebug(manifestEndpoint, { + method: 'PUT', headers: { Authorization: `Bearer ${b64Token}`, 'Content-Type': 'application/vnd.oci.image.manifest.v1+json' }, - validateStatus: () => { - return true // Allow non 2xx responses - } + body: manifestJSON }) if (putResponse.status !== 201) { @@ -202,8 +197,8 @@ async function uploadManifest( ) } - const digestResponseHeader = putResponse.headers['docker-content-digest'] - if (digestResponseHeader === undefined) { + const digestResponseHeader = putResponse.headers.get('docker-content-digest') + if (digestResponseHeader === undefined || digestResponseHeader === null) { throw new Error( `No digest header in response from PUT manifest ${manifestEndpoint}` ) @@ -212,16 +207,23 @@ async function uploadManifest( return digestResponseHeader } -function configureRequestDebugLogging(): void { - axiosDebugLog({ - request: (debug, config) => { - core.debug(`Request with ${config}`) - }, - response: (debug, response) => { - core.debug(`Response with ${response}`) - }, - error: (debug, error) => { +const fetchWithDebug = async ( + url: string, + config: RequestInit = {} +): Promise => { + if (showDebugLog) { + core.debug(`Request with ${JSON.stringify(config)}`) + } + try { + const response = await fetch(url, config) + if (showDebugLog) { + core.debug(`Response with ${JSON.stringify(response)}`) + } + return response + } catch (error) { + if (showDebugLog) { core.debug(`Error with ${error}`) } - }) + throw error + } }