Merge 49b3eab436201d377cf76033abdb597478c0cc5d into 95815c38cf2ff2164869cbab79da8d1f422bc89e

This commit is contained in:
Christopher Roemheld 2025-03-19 21:52:18 +01:00 committed by GitHub
commit 06be35c08b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 74 additions and 28 deletions

View File

@ -131,3 +131,15 @@ jobs:
Write-Error "File contents of downloaded artifacts are incorrect" Write-Error "File contents of downloaded artifacts are incorrect"
} }
shell: pwsh shell: pwsh
- name: Download non-existent Artifact
id: not-existent-artifact
uses: ./
with:
name: Artifact-C-${{ matrix.runs-on }}
allow-not-found: true
- name: Verify empty download-path output
if: ${{ steps.not-existent-artifact.outputs.download-path != '' }}
run: |
Write-Error "Expected download-path output is not empty"

View File

@ -82,6 +82,12 @@ For assistance with breaking changes, see [MIGRATION.md](docs/MIGRATION.md).
# If github-token is specified, this is the run that artifacts will be downloaded from. # If github-token is specified, this is the run that artifacts will be downloaded from.
# Optional. Default is ${{ github.run_id }} # Optional. Default is ${{ github.run_id }}
run-id: run-id:
# When an artifact was not found, this changes the behavior of the download-artifact action.
# If true, this will not cause the action to fail. Instead, the 'download-path' output will be empty.
# If false, this action will raise an error and quit.
# Optional. Default is 'false'.
allow-not-found:
``` ```
### Outputs ### Outputs

View File

@ -17,6 +17,10 @@ inputs:
If false, the downloaded artifacts will be extracted into individual named directories within the specified path.' If false, the downloaded artifacts will be extracted into individual named directories within the specified path.'
required: false required: false
default: 'false' default: 'false'
allow-not-found:
description: 'If an artifact was not found, do not cause the action to fail.'
required: false
default: 'false'
github-token: github-token:
description: 'The GitHub token used to authenticate with the GitHub API. description: 'The GitHub token used to authenticate with the GitHub API.
This is required when downloading artifacts from a different repository or from a different workflow run. This is required when downloading artifacts from a different repository or from a different workflow run.

43
dist/index.js vendored
View File

@ -50930,8 +50930,8 @@ utils.walkdir = function(dirpath, base, callback) {
res.forEach(function(dirEntry) { res.forEach(function(dirEntry) {
results.push(dirEntry); results.push(dirEntry);
}); });
next(); next();
}); });
} else { } else {
next(); next();
@ -118710,6 +118710,7 @@ var Inputs;
Inputs["RunID"] = "run-id"; Inputs["RunID"] = "run-id";
Inputs["Pattern"] = "pattern"; Inputs["Pattern"] = "pattern";
Inputs["MergeMultiple"] = "merge-multiple"; Inputs["MergeMultiple"] = "merge-multiple";
Inputs["AllowNotFound"] = "allow-not-found";
})(Inputs || (exports.Inputs = Inputs = {})); })(Inputs || (exports.Inputs = Inputs = {}));
var Outputs; var Outputs;
(function (Outputs) { (function (Outputs) {
@ -118783,7 +118784,10 @@ function run() {
repository: core.getInput(constants_1.Inputs.Repository, { required: false }), repository: core.getInput(constants_1.Inputs.Repository, { required: false }),
runID: parseInt(core.getInput(constants_1.Inputs.RunID, { required: false })), runID: parseInt(core.getInput(constants_1.Inputs.RunID, { required: false })),
pattern: core.getInput(constants_1.Inputs.Pattern, { required: false }), pattern: core.getInput(constants_1.Inputs.Pattern, { required: false }),
mergeMultiple: core.getBooleanInput(constants_1.Inputs.MergeMultiple, { required: false }) mergeMultiple: core.getBooleanInput(constants_1.Inputs.MergeMultiple, {
required: false
}),
allowNotFound: core.getBooleanInput(constants_1.Inputs.AllowNotFound, { required: false })
}; };
if (!inputs.path) { if (!inputs.path) {
inputs.path = process.env['GITHUB_WORKSPACE'] || process.cwd(); inputs.path = process.env['GITHUB_WORKSPACE'] || process.cwd();
@ -118792,7 +118796,7 @@ function run() {
inputs.path = inputs.path.replace('~', os.homedir()); inputs.path = inputs.path.replace('~', os.homedir());
} }
const isSingleArtifactDownload = !!inputs.name; const isSingleArtifactDownload = !!inputs.name;
const resolvedPath = path.resolve(inputs.path); let resolvedPath = path.resolve(inputs.path);
core.debug(`Resolved path is ${resolvedPath}`); core.debug(`Resolved path is ${resolvedPath}`);
const options = {}; const options = {};
if (inputs.token) { if (inputs.token) {
@ -118810,12 +118814,23 @@ function run() {
let artifacts = []; let artifacts = [];
if (isSingleArtifactDownload) { if (isSingleArtifactDownload) {
core.info(`Downloading single artifact`); core.info(`Downloading single artifact`);
const { artifact: targetArtifact } = yield artifact_1.default.getArtifact(inputs.name, options); const targetArtifact = yield artifact_1.default
.getArtifact(inputs.name, options)
.catch(() => null);
if (!targetArtifact) { if (!targetArtifact) {
throw new Error(`Artifact '${inputs.name}' not found`); const message = `Artifact '${inputs.name}' not found`;
if (!inputs.allowNotFound) {
throw new Error(message);
}
else {
core.warning(message);
resolvedPath = '';
}
}
else {
core.debug(`Found named artifact '${inputs.name}' (ID: ${targetArtifact.artifact.id}, Size: ${targetArtifact.artifact.size})`);
artifacts = [targetArtifact.artifact];
} }
core.debug(`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})`);
artifacts = [targetArtifact];
} }
else { else {
const listArtifactResponse = yield artifact_1.default.listArtifacts(Object.assign({ latest: true }, options)); const listArtifactResponse = yield artifact_1.default.listArtifacts(Object.assign({ latest: true }, options));
@ -128257,11 +128272,11 @@ class LRUCache {
b.__abortController instanceof AC); b.__abortController instanceof AC);
} }
async fetch(k, fetchOptions = {}) { async fetch(k, fetchOptions = {}) {
const { const {
// get options // get options
allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet,
// set options // set options
ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL, ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL,
// fetch exclusive options // fetch exclusive options
noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal, } = fetchOptions; noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal, } = fetchOptions;
if (!this.#hasFetchMethod) { if (!this.#hasFetchMethod) {
@ -128886,10 +128901,10 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/******/ } finally { /******/ } finally {
/******/ if(threw) delete __webpack_module_cache__[moduleId]; /******/ if(threw) delete __webpack_module_cache__[moduleId];
/******/ } /******/ }
/******/ /******/
/******/ // Flag the module as loaded /******/ // Flag the module as loaded
/******/ module.loaded = true; /******/ module.loaded = true;
/******/ /******/
/******/ // Return the exports of the module /******/ // Return the exports of the module
/******/ return module.exports; /******/ return module.exports;
/******/ } /******/ }
@ -128903,7 +128918,7 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/******/ return module; /******/ return module;
/******/ }; /******/ };
/******/ })(); /******/ })();
/******/ /******/
/******/ /* webpack/runtime/compat */ /******/ /* webpack/runtime/compat */
/******/ /******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";

View File

@ -5,7 +5,8 @@ export enum Inputs {
Repository = 'repository', Repository = 'repository',
RunID = 'run-id', RunID = 'run-id',
Pattern = 'pattern', Pattern = 'pattern',
MergeMultiple = 'merge-multiple' MergeMultiple = 'merge-multiple',
AllowNotFound = 'allow-not-found'
} }
export enum Outputs { export enum Outputs {

View File

@ -23,7 +23,10 @@ export async function run(): Promise<void> {
repository: core.getInput(Inputs.Repository, {required: false}), repository: core.getInput(Inputs.Repository, {required: false}),
runID: parseInt(core.getInput(Inputs.RunID, {required: false})), runID: parseInt(core.getInput(Inputs.RunID, {required: false})),
pattern: core.getInput(Inputs.Pattern, {required: false}), pattern: core.getInput(Inputs.Pattern, {required: false}),
mergeMultiple: core.getBooleanInput(Inputs.MergeMultiple, {required: false}) mergeMultiple: core.getBooleanInput(Inputs.MergeMultiple, {
required: false
}),
allowNotFound: core.getBooleanInput(Inputs.AllowNotFound, {required: false})
} }
if (!inputs.path) { if (!inputs.path) {
@ -35,7 +38,7 @@ export async function run(): Promise<void> {
} }
const isSingleArtifactDownload = !!inputs.name const isSingleArtifactDownload = !!inputs.name
const resolvedPath = path.resolve(inputs.path) let resolvedPath = path.resolve(inputs.path)
core.debug(`Resolved path is ${resolvedPath}`) core.debug(`Resolved path is ${resolvedPath}`)
const options: FindOptions = {} const options: FindOptions = {}
@ -60,20 +63,25 @@ export async function run(): Promise<void> {
if (isSingleArtifactDownload) { if (isSingleArtifactDownload) {
core.info(`Downloading single artifact`) core.info(`Downloading single artifact`)
const {artifact: targetArtifact} = await artifactClient.getArtifact( const targetArtifact = await artifactClient
inputs.name, .getArtifact(inputs.name, options)
options .catch(() => null)
)
if (!targetArtifact) { if (!targetArtifact) {
throw new Error(`Artifact '${inputs.name}' not found`) const message = `Artifact '${inputs.name}' not found`
if (!inputs.allowNotFound) {
throw new Error(message)
} else {
core.warning(message)
resolvedPath = ''
}
} else {
core.debug(
`Found named artifact '${inputs.name}' (ID: ${targetArtifact.artifact.id}, Size: ${targetArtifact.artifact.size})`
)
artifacts = [targetArtifact.artifact]
} }
core.debug(
`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})`
)
artifacts = [targetArtifact]
} else { } else {
const listArtifactResponse = await artifactClient.listArtifacts({ const listArtifactResponse = await artifactClient.listArtifacts({
latest: true, latest: true,