diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index cd90053..bee8638 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -6,6 +6,9 @@ # We need to make sure the checked-in `index.js` actually matches what we expect it to be. name: Check dist/ +permissions: + contents: read + on: push: branches: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index e95dbe4..dcf7c1e 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -1,5 +1,9 @@ name: "Code scanning - action" +permissions: + contents: read + security-events: write + on: push: branches-ignore: "dependabot/**" diff --git a/.github/workflows/licensed.yml b/.github/workflows/licensed.yml index 6c8fe65..54365f7 100644 --- a/.github/workflows/licensed.yml +++ b/.github/workflows/licensed.yml @@ -1,5 +1,8 @@ name: Licensed +permissions: + contents: read + on: push: branches: @@ -9,7 +12,7 @@ on: - main jobs: - test: + licenses: runs-on: ubuntu-latest name: Check licenses steps: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d23bbb7..bd0f1af 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,9 +7,12 @@ on: paths-ignore: - '**.md' +permissions: + contents: read + jobs: - build: - name: Build + test: + name: Build and Test strategy: matrix: @@ -115,6 +118,29 @@ jobs: path: single/directory merge-multiple: true + - name: Request missing Artifact + id: request-missing-artifact + uses: ./ + with: + name: nonexistent + warn-on-failure: true + + - name: Check missing warning + env: + output: ${{ steps.request-missing-artifact.outputs.failure }} + if: ${{ !contains(env.output, 'Unable to download artifact(s):') }} + run: | + false + shell: bash + + - name: Log missing warning + env: + output: ${{ steps.request-missing-artifact.outputs.failure }} + run_os: ${{ matrix.runs-on }} + run: | + echo "::notice title=This message is expected::[$run_os] $output" + shell: bash + - name: Verify successful download run: | $fileA = "single/directory/file-A.txt" diff --git a/README.md b/README.md index 6ed23d8..77455a1 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,10 @@ 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. # Optional. Default is ${{ github.run_id }} run-id: + + # Map failure result to an output instead of failing the job. + # Optional. Default is `false` + warn-on-failure: ``` ### Outputs @@ -89,6 +93,7 @@ For assistance with breaking changes, see [MIGRATION.md](docs/MIGRATION.md). | Name | Description | Example | | - | - | - | | `download-path` | Absolute path where the artifact(s) were downloaded | `/tmp/my/download/path` | +| `failure` | Failure message (if using `warn-on-failure`) | `Unable to download artifact(s): ...` | ## Examples diff --git a/action.yml b/action.yml index 54a3eb6..7e91294 100644 --- a/action.yml +++ b/action.yml @@ -32,9 +32,15 @@ inputs: If github-token is specified, this is the run that artifacts will be downloaded from.' required: false default: ${{ github.run_id }} + warn-on-failure: + description: 'Map failure result to an output instead of failing the job' + required: false + default: false outputs: download-path: description: 'Path of artifact download' + failure: + description: 'Failure message (if warn-on-failure is set)' runs: using: 'node20' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index 64e3212..f860069 100644 --- a/dist/index.js +++ b/dist/index.js @@ -118710,6 +118710,7 @@ var Inputs; Inputs["RunID"] = "run-id"; Inputs["Pattern"] = "pattern"; Inputs["MergeMultiple"] = "merge-multiple"; + Inputs["WarnOnFailure"] = "warn-on-failure"; })(Inputs || (exports.Inputs = Inputs = {})); var Outputs; (function (Outputs) { @@ -118774,7 +118775,7 @@ const chunk = (arr, n) => arr.reduce((acc, cur, i) => { return acc; }, []); exports.chunk = chunk; -function run() { +function run(flags) { return __awaiter(this, void 0, void 0, function* () { const inputs = { name: core.getInput(constants_1.Inputs.Name, { required: false }), @@ -118783,8 +118784,12 @@ function run() { repository: core.getInput(constants_1.Inputs.Repository, { required: false }), runID: parseInt(core.getInput(constants_1.Inputs.RunID, { 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 + }), + warnOnFailure: core.getBooleanInput(constants_1.Inputs.WarnOnFailure, { required: false }) }; + flags.warnOnFailure = inputs.warnOnFailure; if (!inputs.path) { inputs.path = process.env['GITHUB_WORKSPACE'] || process.cwd(); } @@ -118863,7 +118868,17 @@ function run() { } }); } -run().catch(err => core.setFailed(`Unable to download artifact(s): ${err.message}`)); +{ + const flags = { warnOnFailure: false }; + run(flags).catch(err => { + if (flags.warnOnFailure) { + core.setOutput('failure', `Unable to download artifact(s): ${err.message}`); + } + else { + core.setFailed(`Unable to download artifact(s): ${err.message}`); + } + }); +} /***/ }), diff --git a/src/constants.ts b/src/constants.ts index 17c7d34..57b14e1 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -5,7 +5,8 @@ export enum Inputs { Repository = 'repository', RunID = 'run-id', Pattern = 'pattern', - MergeMultiple = 'merge-multiple' + MergeMultiple = 'merge-multiple', + WarnOnFailure = 'warn-on-failure' } export enum Outputs { diff --git a/src/download-artifact.ts b/src/download-artifact.ts index e149804..b32641c 100644 --- a/src/download-artifact.ts +++ b/src/download-artifact.ts @@ -8,6 +8,10 @@ import {Inputs, Outputs} from './constants' const PARALLEL_DOWNLOADS = 5 +interface Flags { + warnOnFailure: boolean +} + export const chunk = (arr: T[], n: number): T[][] => arr.reduce((acc, cur, i) => { const index = Math.floor(i / n) @@ -15,7 +19,7 @@ export const chunk = (arr: T[], n: number): T[][] => return acc }, [] as T[][]) -async function run(): Promise { +async function run(flags: Flags): Promise { const inputs = { name: core.getInput(Inputs.Name, {required: false}), path: core.getInput(Inputs.Path, {required: false}), @@ -23,8 +27,12 @@ async function run(): Promise { repository: core.getInput(Inputs.Repository, {required: false}), runID: parseInt(core.getInput(Inputs.RunID, {required: false})), pattern: core.getInput(Inputs.Pattern, {required: false}), - mergeMultiple: core.getBooleanInput(Inputs.MergeMultiple, {required: false}) + mergeMultiple: core.getBooleanInput(Inputs.MergeMultiple, { + required: false + }), + warnOnFailure: core.getBooleanInput(Inputs.WarnOnFailure, {required: false}) } + flags.warnOnFailure = inputs.warnOnFailure if (!inputs.path) { inputs.path = process.env['GITHUB_WORKSPACE'] || process.cwd() @@ -145,6 +153,16 @@ async function run(): Promise { } } -run().catch(err => - core.setFailed(`Unable to download artifact(s): ${err.message}`) -) +{ + const flags = {warnOnFailure: false} + run(flags).catch(err => { + if (flags.warnOnFailure) { + core.setOutput( + 'failure', + `Unable to download artifact(s): ${err.message}` + ) + } else { + core.setFailed(`Unable to download artifact(s): ${err.message}`) + } + }) +}