Skip to content

Commit

Permalink
Support for skippable jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Mar 4, 2022
1 parent 2c439a4 commit f1efe7e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@ jobs:
needs:
- job_1
- job_2
- skippable_job_1
- skippable_job_2
runs-on: ubuntu-latest
steps:
- uses: matrix-org/done-action@v1
with:
needs: ${{ toJSON(needs) }}
skippable: |
skippable_job_1
skippable_job_2
```
Under `needs`, you should list the names of the jobs that you want to complete
for the required status check to pass.

By default, the dependent jobs may not be skipped. Optionally, you can specify
the names of any jobs which may be skipped whilst still allowing the workflow to
pass, under `steps...with.skippable`, one job per line.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ inputs:
needs:
description: 'The GHA "needs" context'
required: true
skippable:
description: 'A space-separated list of jobs that can be skipped'
required: false
runs:
using: 'node16'
main: 'dist/index.js'
20 changes: 15 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1678,19 +1678,29 @@ var __webpack_exports__ = {};
(() => {
const core = __nccwpck_require__(186);

function main() {
const needs_param = core.getInput('needs');
function parseJsonInput(param_name) {
const param_val = core.getInput(param_name);
try {
const needs = JSON.parse(needs_param);
return JSON.parse(param_val);
} catch (error) {
throw new Error(`Invalid 'needs' input ${needs_param}: ${error.message}`);
throw new Error(`Invalid '${param_name}' input ${param_val}: ${error.message}`);
}
}


function main() {
const needs = parseJsonInput('needs');
const skippable = core.getMultilineInput('skippable');

console.debug(`needs: ${JSON.stringify(needs)}`);
console.debug(`skippable: ${JSON.stringify(skippable)}`);
for (const job_id of Object.keys(needs)) {
const result = needs[job_id].result;
console.log(`Job ${job_id} returned ${result}`);
if (result != 'success' && result != 'skipped') {
if (result == 'skipped' && skippable.includes(job_id)) {
continue;
}
if (result != 'success') {
throw new Error(`Job ${job_id} returned ${result}`);
}
}
Expand Down
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
const core = require('@actions/core');

function main() {
const needs_param = core.getInput('needs');
function parseJsonInput(param_name) {
const param_val = core.getInput(param_name);
try {
const needs = JSON.parse(needs_param);
return JSON.parse(param_val);
} catch (error) {
throw new Error(`Invalid 'needs' input ${needs_param}: ${error.message}`);
throw new Error(`Invalid '${param_name}' input ${param_val}: ${error.message}`);
}
}


function main() {
const needs = parseJsonInput('needs');
const skippable = core.getMultilineInput('skippable');

console.debug(`needs: ${JSON.stringify(needs)}`);
console.debug(`skippable: ${JSON.stringify(skippable)}`);
for (const job_id of Object.keys(needs)) {
const result = needs[job_id].result;
console.log(`Job ${job_id} returned ${result}`);
if (result != 'success' && result != 'skipped') {
if (result == 'skipped' && skippable.includes(job_id)) {
continue;
}
if (result != 'success') {
throw new Error(`Job ${job_id} returned ${result}`);
}
}
Expand Down

0 comments on commit f1efe7e

Please sign in to comment.