mirror of
https://code.forgejo.org/actions/cache.git
synced 2024-11-05 10:12:55 +01:00
Add request header and debug statements
This commit is contained in:
parent
21dc9a47e6
commit
994e3b75fc
4 changed files with 22 additions and 4 deletions
6
dist/restore/index.js
vendored
6
dist/restore/index.js
vendored
|
@ -1579,7 +1579,7 @@ function reserveCache(key) {
|
||||||
const reserveCacheRequest = {
|
const reserveCacheRequest = {
|
||||||
key
|
key
|
||||||
};
|
};
|
||||||
const response = yield restClient.create("caches", reserveCacheRequest);
|
const response = yield restClient.create("caches", reserveCacheRequest, getRequestOptions());
|
||||||
return _c = (_b = (_a = response) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.cacheId, (_c !== null && _c !== void 0 ? _c : -1);
|
return _c = (_b = (_a = response) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.cacheId, (_c !== null && _c !== void 0 ? _c : -1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1600,6 +1600,7 @@ function bufferToStream(buffer) {
|
||||||
}
|
}
|
||||||
function uploadChunk(restClient, resourceUrl, data, offset) {
|
function uploadChunk(restClient, resourceUrl, data, offset) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.debug(`Uploading chunk of size ${data.byteLength} bytes at offset ${offset}`);
|
||||||
const requestOptions = getRequestOptions();
|
const requestOptions = getRequestOptions();
|
||||||
requestOptions.additionalHeaders = {
|
requestOptions.additionalHeaders = {
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
|
@ -1619,6 +1620,7 @@ function commitCache(restClient, cacheId, filesize) {
|
||||||
function saveCache(cacheId, archivePath) {
|
function saveCache(cacheId, archivePath) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const restClient = createRestClient();
|
const restClient = createRestClient();
|
||||||
|
core.debug("Uploading chunks");
|
||||||
// Upload Chunks
|
// Upload Chunks
|
||||||
const stream = fs.createReadStream(archivePath);
|
const stream = fs.createReadStream(archivePath);
|
||||||
let streamIsClosed = false;
|
let streamIsClosed = false;
|
||||||
|
@ -1633,11 +1635,13 @@ function saveCache(cacheId, archivePath) {
|
||||||
uploads.push(uploadChunk(restClient, resourceUrl, chunk, offset));
|
uploads.push(uploadChunk(restClient, resourceUrl, chunk, offset));
|
||||||
offset += MAX_CHUNK_SIZE;
|
offset += MAX_CHUNK_SIZE;
|
||||||
}
|
}
|
||||||
|
core.debug("Awaiting all uplaods");
|
||||||
const responses = yield Promise.all(uploads);
|
const responses = yield Promise.all(uploads);
|
||||||
const failedResponse = responses.find(x => !isSuccessStatusCode(x.statusCode));
|
const failedResponse = responses.find(x => !isSuccessStatusCode(x.statusCode));
|
||||||
if (failedResponse) {
|
if (failedResponse) {
|
||||||
throw new Error(`Cache service responded with ${failedResponse.statusCode} during chunk upload.`);
|
throw new Error(`Cache service responded with ${failedResponse.statusCode} during chunk upload.`);
|
||||||
}
|
}
|
||||||
|
core.debug("Commiting cache");
|
||||||
// Commit Cache
|
// Commit Cache
|
||||||
const cacheSize = utils.getArchiveFileSize(archivePath);
|
const cacheSize = utils.getArchiveFileSize(archivePath);
|
||||||
const commitCacheResponse = yield commitCache(restClient, cacheId, cacheSize);
|
const commitCacheResponse = yield commitCache(restClient, cacheId, cacheSize);
|
||||||
|
|
9
dist/save/index.js
vendored
9
dist/save/index.js
vendored
|
@ -1579,7 +1579,7 @@ function reserveCache(key) {
|
||||||
const reserveCacheRequest = {
|
const reserveCacheRequest = {
|
||||||
key
|
key
|
||||||
};
|
};
|
||||||
const response = yield restClient.create("caches", reserveCacheRequest);
|
const response = yield restClient.create("caches", reserveCacheRequest, getRequestOptions());
|
||||||
return _c = (_b = (_a = response) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.cacheId, (_c !== null && _c !== void 0 ? _c : -1);
|
return _c = (_b = (_a = response) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.cacheId, (_c !== null && _c !== void 0 ? _c : -1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1600,6 +1600,7 @@ function bufferToStream(buffer) {
|
||||||
}
|
}
|
||||||
function uploadChunk(restClient, resourceUrl, data, offset) {
|
function uploadChunk(restClient, resourceUrl, data, offset) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.debug(`Uploading chunk of size ${data.byteLength} bytes at offset ${offset}`);
|
||||||
const requestOptions = getRequestOptions();
|
const requestOptions = getRequestOptions();
|
||||||
requestOptions.additionalHeaders = {
|
requestOptions.additionalHeaders = {
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
|
@ -1619,6 +1620,7 @@ function commitCache(restClient, cacheId, filesize) {
|
||||||
function saveCache(cacheId, archivePath) {
|
function saveCache(cacheId, archivePath) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const restClient = createRestClient();
|
const restClient = createRestClient();
|
||||||
|
core.debug("Uploading chunks");
|
||||||
// Upload Chunks
|
// Upload Chunks
|
||||||
const stream = fs.createReadStream(archivePath);
|
const stream = fs.createReadStream(archivePath);
|
||||||
let streamIsClosed = false;
|
let streamIsClosed = false;
|
||||||
|
@ -1633,11 +1635,13 @@ function saveCache(cacheId, archivePath) {
|
||||||
uploads.push(uploadChunk(restClient, resourceUrl, chunk, offset));
|
uploads.push(uploadChunk(restClient, resourceUrl, chunk, offset));
|
||||||
offset += MAX_CHUNK_SIZE;
|
offset += MAX_CHUNK_SIZE;
|
||||||
}
|
}
|
||||||
|
core.debug("Awaiting all uplaods");
|
||||||
const responses = yield Promise.all(uploads);
|
const responses = yield Promise.all(uploads);
|
||||||
const failedResponse = responses.find(x => !isSuccessStatusCode(x.statusCode));
|
const failedResponse = responses.find(x => !isSuccessStatusCode(x.statusCode));
|
||||||
if (failedResponse) {
|
if (failedResponse) {
|
||||||
throw new Error(`Cache service responded with ${failedResponse.statusCode} during chunk upload.`);
|
throw new Error(`Cache service responded with ${failedResponse.statusCode} during chunk upload.`);
|
||||||
}
|
}
|
||||||
|
core.debug("Commiting cache");
|
||||||
// Commit Cache
|
// Commit Cache
|
||||||
const cacheSize = utils.getArchiveFileSize(archivePath);
|
const cacheSize = utils.getArchiveFileSize(archivePath);
|
||||||
const commitCacheResponse = yield commitCache(restClient, cacheId, cacheSize);
|
const commitCacheResponse = yield commitCache(restClient, cacheId, cacheSize);
|
||||||
|
@ -2968,11 +2972,13 @@ function run() {
|
||||||
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
core.debug("Reserving Cache");
|
||||||
const cacheId = yield cacheHttpClient.reserveCache(primaryKey);
|
const cacheId = yield cacheHttpClient.reserveCache(primaryKey);
|
||||||
if (cacheId < 0) {
|
if (cacheId < 0) {
|
||||||
core.info(`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`);
|
core.info(`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
core.debug(`Cache ID: ${cacheId}`);
|
||||||
const cachePath = utils.resolvePath(core.getInput(constants_1.Inputs.Path, { required: true }));
|
const cachePath = utils.resolvePath(core.getInput(constants_1.Inputs.Path, { required: true }));
|
||||||
core.debug(`Cache Path: ${cachePath}`);
|
core.debug(`Cache Path: ${cachePath}`);
|
||||||
const archivePath = path.join(yield utils.createTempDirectory(), "cache.tgz");
|
const archivePath = path.join(yield utils.createTempDirectory(), "cache.tgz");
|
||||||
|
@ -3001,6 +3007,7 @@ function run() {
|
||||||
utils.logWarning(`Cache size of ~${Math.round(archiveFileSize / (1024 * 1024 * 1024))} GB (${archiveFileSize} B) is over the 2GB limit, not saving cache.`);
|
utils.logWarning(`Cache size of ~${Math.round(archiveFileSize / (1024 * 1024 * 1024))} GB (${archiveFileSize} B) is over the 2GB limit, not saving cache.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
core.debug("Saving Cache");
|
||||||
yield cacheHttpClient.saveCache(cacheId, archivePath);
|
yield cacheHttpClient.saveCache(cacheId, archivePath);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
|
@ -120,7 +120,8 @@ export async function reserveCache(
|
||||||
};
|
};
|
||||||
const response = await restClient.create<ReserverCacheResponse>(
|
const response = await restClient.create<ReserverCacheResponse>(
|
||||||
"caches",
|
"caches",
|
||||||
reserveCacheRequest
|
reserveCacheRequest,
|
||||||
|
getRequestOptions()
|
||||||
);
|
);
|
||||||
|
|
||||||
return response?.result?.cacheId ?? -1;
|
return response?.result?.cacheId ?? -1;
|
||||||
|
@ -149,6 +150,7 @@ async function uploadChunk(
|
||||||
data: Buffer,
|
data: Buffer,
|
||||||
offset: number
|
offset: number
|
||||||
): Promise<IRestResponse<void>> {
|
): Promise<IRestResponse<void>> {
|
||||||
|
core.debug(`Uploading chunk of size ${data.byteLength} bytes at offset ${offset}`);
|
||||||
const requestOptions = getRequestOptions();
|
const requestOptions = getRequestOptions();
|
||||||
requestOptions.additionalHeaders = {
|
requestOptions.additionalHeaders = {
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
|
@ -179,6 +181,7 @@ export async function saveCache(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const restClient = createRestClient();
|
const restClient = createRestClient();
|
||||||
|
|
||||||
|
core.debug("Uploading chunks");
|
||||||
// Upload Chunks
|
// Upload Chunks
|
||||||
const stream = fs.createReadStream(archivePath);
|
const stream = fs.createReadStream(archivePath);
|
||||||
let streamIsClosed = false;
|
let streamIsClosed = false;
|
||||||
|
@ -195,6 +198,7 @@ export async function saveCache(
|
||||||
offset += MAX_CHUNK_SIZE;
|
offset += MAX_CHUNK_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.debug("Awaiting all uplaods");
|
||||||
const responses = await Promise.all(uploads);
|
const responses = await Promise.all(uploads);
|
||||||
|
|
||||||
const failedResponse = responses.find(
|
const failedResponse = responses.find(
|
||||||
|
@ -206,6 +210,7 @@ export async function saveCache(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.debug("Commiting cache");
|
||||||
// Commit Cache
|
// Commit Cache
|
||||||
const cacheSize = utils.getArchiveFileSize(archivePath);
|
const cacheSize = utils.getArchiveFileSize(archivePath);
|
||||||
const commitCacheResponse = await commitCache(
|
const commitCacheResponse = await commitCache(
|
||||||
|
|
|
@ -35,12 +35,13 @@ async function run(): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.debug("Reserving Cache");
|
||||||
const cacheId = await cacheHttpClient.reserveCache(primaryKey);
|
const cacheId = await cacheHttpClient.reserveCache(primaryKey);
|
||||||
if (cacheId < 0) {
|
if (cacheId < 0) {
|
||||||
core.info(`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`);
|
core.info(`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
core.debug(`Cache ID: ${cacheId}`);
|
||||||
const cachePath = utils.resolvePath(
|
const cachePath = utils.resolvePath(
|
||||||
core.getInput(Inputs.Path, { required: true })
|
core.getInput(Inputs.Path, { required: true })
|
||||||
);
|
);
|
||||||
|
@ -83,6 +84,7 @@ async function run(): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.debug("Saving Cache");
|
||||||
await cacheHttpClient.saveCache(cacheId, archivePath);
|
await cacheHttpClient.saveCache(cacheId, archivePath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
utils.logWarning(error.message);
|
utils.logWarning(error.message);
|
||||||
|
|
Loading…
Reference in a new issue