Compare commits

...

2 Commits

Author SHA1 Message Date
Yanks Yoon aed3e57b8a
Merge bacb5b323b into 3eadd8b791 2024-09-26 14:13:44 -05:00
charlie4284 bacb5b323b
retry upload artifact 2024-03-26 21:41:22 +09:00
4 changed files with 139 additions and 83 deletions

35
dist/merge/index.js vendored
View File

@ -126207,16 +126207,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.uploadArtifact = void 0; exports.uploadArtifact = void 0;
const core = __importStar(__nccwpck_require__(42186)); const core = __importStar(__nccwpck_require__(42186));
const github = __importStar(__nccwpck_require__(95438)); const github = __importStar(__nccwpck_require__(95438));
const artifact_1 = __importDefault(__nccwpck_require__(79450)); const artifact_1 = __importStar(__nccwpck_require__(79450));
function uploadArtifact(artifactName, filesToUpload, rootDirectory, options) { function deleteArtifactIfExists(artifactName) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try {
yield artifact_1.default.deleteArtifact(artifactName);
}
catch (error) {
if (error instanceof artifact_1.ArtifactNotFoundError) {
core.debug(`Skipping deletion of '${artifactName}', it does not exist`);
return;
}
// Best effort, we don't want to fail the action if this fails
core.debug(`Unable to delete artifact: ${error.message}`);
}
});
}
function uploadArtifact(artifactName, filesToUpload, rootDirectory, options, overwrite = false, retryAttempts = 3) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (overwrite) {
yield deleteArtifactIfExists(artifactName);
}
const uploadResponse = yield artifact_1.default.uploadArtifact(artifactName, filesToUpload, rootDirectory, options); const uploadResponse = yield artifact_1.default.uploadArtifact(artifactName, filesToUpload, rootDirectory, options);
core.info(`Artifact ${artifactName} has been successfully uploaded! Final size is ${uploadResponse.size} bytes. Artifact ID is ${uploadResponse.id}`); core.info(`Artifact ${artifactName} has been successfully uploaded! Final size is ${uploadResponse.size} bytes. Artifact ID is ${uploadResponse.id}`);
core.setOutput('artifact-id', uploadResponse.id); core.setOutput('artifact-id', uploadResponse.id);
@ -126224,6 +126240,15 @@ function uploadArtifact(artifactName, filesToUpload, rootDirectory, options) {
const artifactURL = `${github.context.serverUrl}/${repository.owner}/${repository.repo}/actions/runs/${github.context.runId}/artifacts/${uploadResponse.id}`; const artifactURL = `${github.context.serverUrl}/${repository.owner}/${repository.repo}/actions/runs/${github.context.runId}/artifacts/${uploadResponse.id}`;
core.info(`Artifact download URL: ${artifactURL}`); core.info(`Artifact download URL: ${artifactURL}`);
core.setOutput('artifact-url', artifactURL); core.setOutput('artifact-url', artifactURL);
}
catch (error) {
if (error instanceof artifact_1.InvalidResponseError &&
error.message.includes('Conflict: an artifact with this name already exists on the workflow run') &&
overwrite &&
retryAttempts) {
uploadArtifact(artifactName, filesToUpload, rootDirectory, options, overwrite, retryAttempts - 1);
}
}
}); });
} }
exports.uploadArtifact = uploadArtifact; exports.uploadArtifact = uploadArtifact;

56
dist/upload/index.js vendored
View File

@ -125962,16 +125962,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.uploadArtifact = void 0; exports.uploadArtifact = void 0;
const core = __importStar(__nccwpck_require__(42186)); const core = __importStar(__nccwpck_require__(42186));
const github = __importStar(__nccwpck_require__(95438)); const github = __importStar(__nccwpck_require__(95438));
const artifact_1 = __importDefault(__nccwpck_require__(79450)); const artifact_1 = __importStar(__nccwpck_require__(79450));
function uploadArtifact(artifactName, filesToUpload, rootDirectory, options) { function deleteArtifactIfExists(artifactName) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try {
yield artifact_1.default.deleteArtifact(artifactName);
}
catch (error) {
if (error instanceof artifact_1.ArtifactNotFoundError) {
core.debug(`Skipping deletion of '${artifactName}', it does not exist`);
return;
}
// Best effort, we don't want to fail the action if this fails
core.debug(`Unable to delete artifact: ${error.message}`);
}
});
}
function uploadArtifact(artifactName, filesToUpload, rootDirectory, options, overwrite = false, retryAttempts = 3) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (overwrite) {
yield deleteArtifactIfExists(artifactName);
}
const uploadResponse = yield artifact_1.default.uploadArtifact(artifactName, filesToUpload, rootDirectory, options); const uploadResponse = yield artifact_1.default.uploadArtifact(artifactName, filesToUpload, rootDirectory, options);
core.info(`Artifact ${artifactName} has been successfully uploaded! Final size is ${uploadResponse.size} bytes. Artifact ID is ${uploadResponse.id}`); core.info(`Artifact ${artifactName} has been successfully uploaded! Final size is ${uploadResponse.size} bytes. Artifact ID is ${uploadResponse.id}`);
core.setOutput('artifact-id', uploadResponse.id); core.setOutput('artifact-id', uploadResponse.id);
@ -125979,6 +125995,15 @@ function uploadArtifact(artifactName, filesToUpload, rootDirectory, options) {
const artifactURL = `${github.context.serverUrl}/${repository.owner}/${repository.repo}/actions/runs/${github.context.runId}/artifacts/${uploadResponse.id}`; const artifactURL = `${github.context.serverUrl}/${repository.owner}/${repository.repo}/actions/runs/${github.context.runId}/artifacts/${uploadResponse.id}`;
core.info(`Artifact download URL: ${artifactURL}`); core.info(`Artifact download URL: ${artifactURL}`);
core.setOutput('artifact-url', artifactURL); core.setOutput('artifact-url', artifactURL);
}
catch (error) {
if (error instanceof artifact_1.InvalidResponseError &&
error.message.includes('Conflict: an artifact with this name already exists on the workflow run') &&
overwrite &&
retryAttempts) {
uploadArtifact(artifactName, filesToUpload, rootDirectory, options, overwrite, retryAttempts - 1);
}
}
}); });
} }
exports.uploadArtifact = uploadArtifact; exports.uploadArtifact = uploadArtifact;
@ -126177,26 +126202,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.run = void 0; exports.run = void 0;
const core = __importStar(__nccwpck_require__(42186)); const core = __importStar(__nccwpck_require__(42186));
const artifact_1 = __importStar(__nccwpck_require__(79450));
const search_1 = __nccwpck_require__(8725); const search_1 = __nccwpck_require__(8725);
const input_helper_1 = __nccwpck_require__(67022); const input_helper_1 = __nccwpck_require__(67022);
const constants_1 = __nccwpck_require__(86154); const constants_1 = __nccwpck_require__(86154);
const upload_artifact_1 = __nccwpck_require__(56680); const upload_artifact_1 = __nccwpck_require__(56680);
function deleteArtifactIfExists(artifactName) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield artifact_1.default.deleteArtifact(artifactName);
}
catch (error) {
if (error instanceof artifact_1.ArtifactNotFoundError) {
core.debug(`Skipping deletion of '${artifactName}', it does not exist`);
return;
}
// Best effort, we don't want to fail the action if this fails
core.debug(`Unable to delete artifact: ${error.message}`);
}
});
}
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const inputs = (0, input_helper_1.getInputs)(); const inputs = (0, input_helper_1.getInputs)();
@ -126222,9 +126231,6 @@ function run() {
const s = searchResult.filesToUpload.length === 1 ? '' : 's'; const s = searchResult.filesToUpload.length === 1 ? '' : 's';
core.info(`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`); core.info(`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`);
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`); core.debug(`Root artifact directory is ${searchResult.rootDirectory}`);
if (inputs.overwrite) {
yield deleteArtifactIfExists(inputs.artifactName);
}
const options = {}; const options = {};
if (inputs.retentionDays) { if (inputs.retentionDays) {
options.retentionDays = inputs.retentionDays; options.retentionDays = inputs.retentionDays;
@ -126232,7 +126238,7 @@ function run() {
if (typeof inputs.compressionLevel !== 'undefined') { if (typeof inputs.compressionLevel !== 'undefined') {
options.compressionLevel = inputs.compressionLevel; options.compressionLevel = inputs.compressionLevel;
} }
yield (0, upload_artifact_1.uploadArtifact)(inputs.artifactName, searchResult.filesToUpload, searchResult.rootDirectory, options); yield (0, upload_artifact_1.uploadArtifact)(inputs.artifactName, searchResult.filesToUpload, searchResult.rootDirectory, options, inputs.overwrite);
} }
}); });
} }

View File

@ -1,13 +1,39 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import * as github from '@actions/github' import * as github from '@actions/github'
import artifact, {UploadArtifactOptions} from '@actions/artifact' import artifact, {
UploadArtifactOptions,
ArtifactNotFoundError,
InvalidResponseError
} from '@actions/artifact'
import {UploadInputs} from '../upload/upload-inputs'
import {MergeInputs} from '../merge/merge-inputs'
async function deleteArtifactIfExists(artifactName: string): Promise<void> {
try {
await artifact.deleteArtifact(artifactName)
} catch (error) {
if (error instanceof ArtifactNotFoundError) {
core.debug(`Skipping deletion of '${artifactName}', it does not exist`)
return
}
// Best effort, we don't want to fail the action if this fails
core.debug(`Unable to delete artifact: ${(error as Error).message}`)
}
}
export async function uploadArtifact( export async function uploadArtifact(
artifactName: string, artifactName: string,
filesToUpload: string[], filesToUpload: string[],
rootDirectory: string, rootDirectory: string,
options: UploadArtifactOptions options: UploadArtifactOptions,
overwrite: boolean = false,
retryAttempts: number = 3
) { ) {
try {
if (overwrite) {
await deleteArtifactIfExists(artifactName)
}
const uploadResponse = await artifact.uploadArtifact( const uploadResponse = await artifact.uploadArtifact(
artifactName, artifactName,
filesToUpload, filesToUpload,
@ -25,4 +51,23 @@ export async function uploadArtifact(
core.info(`Artifact download URL: ${artifactURL}`) core.info(`Artifact download URL: ${artifactURL}`)
core.setOutput('artifact-url', artifactURL) core.setOutput('artifact-url', artifactURL)
} catch (error) {
if (
error instanceof InvalidResponseError &&
error.message.includes(
'Conflict: an artifact with this name already exists on the workflow run'
) &&
overwrite &&
retryAttempts
) {
uploadArtifact(
artifactName,
filesToUpload,
rootDirectory,
options,
overwrite,
retryAttempts - 1
)
}
}
} }

View File

@ -1,27 +1,10 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import artifact, { import {UploadArtifactOptions} from '@actions/artifact'
UploadArtifactOptions,
ArtifactNotFoundError
} from '@actions/artifact'
import {findFilesToUpload} from '../shared/search' import {findFilesToUpload} from '../shared/search'
import {getInputs} from './input-helper' import {getInputs} from './input-helper'
import {NoFileOptions} from './constants' import {NoFileOptions} from './constants'
import {uploadArtifact} from '../shared/upload-artifact' import {uploadArtifact} from '../shared/upload-artifact'
async function deleteArtifactIfExists(artifactName: string): Promise<void> {
try {
await artifact.deleteArtifact(artifactName)
} catch (error) {
if (error instanceof ArtifactNotFoundError) {
core.debug(`Skipping deletion of '${artifactName}', it does not exist`)
return
}
// Best effort, we don't want to fail the action if this fails
core.debug(`Unable to delete artifact: ${(error as Error).message}`)
}
}
export async function run(): Promise<void> { export async function run(): Promise<void> {
const inputs = getInputs() const inputs = getInputs()
const searchResult = await findFilesToUpload( const searchResult = await findFilesToUpload(
@ -57,10 +40,6 @@ export async function run(): Promise<void> {
) )
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`) core.debug(`Root artifact directory is ${searchResult.rootDirectory}`)
if (inputs.overwrite) {
await deleteArtifactIfExists(inputs.artifactName)
}
const options: UploadArtifactOptions = {} const options: UploadArtifactOptions = {}
if (inputs.retentionDays) { if (inputs.retentionDays) {
options.retentionDays = inputs.retentionDays options.retentionDays = inputs.retentionDays
@ -74,7 +53,8 @@ export async function run(): Promise<void> {
inputs.artifactName, inputs.artifactName,
searchResult.filesToUpload, searchResult.filesToUpload,
searchResult.rootDirectory, searchResult.rootDirectory,
options options,
inputs.overwrite
) )
} }
} }