Skip to content
This repository has been archived by the owner on Mar 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from pllim/user-labels
Browse files Browse the repository at this point in the history
Allow custom directives
  • Loading branch information
pllim authored Jan 5, 2021
2 parents 19a174d + 55d986f commit bd536bd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ these directives (case-insensitive):
If it does, the job running this action will fail, thus preventing
downstream jobs or steps from running. Otherwise, jobs will run as usual.

The directives above are the defaults, but they could be customized
using `SKIP_DIRECTIVES` (see example below).

Non-pull request event will not be affected. This is because we want the CI
to run when a PR is merged even though its last commit has a directive to
skip CI for that PR.
Expand All @@ -37,6 +40,17 @@ jobs:
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Example to use custom directives.
check_skip_another:
name: Skip something else
runs-on: ubuntu-latest
steps:
- name: Some other thing depends on this check (not shown)
uses: pllim/action-skip-ci@main
with:
SKIP_DIRECTIVES: '[skip other],[other skip]'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# This is placeholder for your real tests.
tests:
name: Run tests
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: 'Check skip CI'
description: 'Fails job if commit message wants to skip CI.'
author: 'pllim'
inputs:
SKIP_DIRECTIVES:
description: 'Comma separated terms to skip CI'
default: '[skip ci],[ci skip],[skip action],[action skip],[skip actions],[actions skip]'
required: false
GITHUB_TOKEN:
description: 'GitHub access token'
required: true
Expand Down
11 changes: 4 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ const github = __importStar(__webpack_require__(438));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const accepted_flags = [
'[skip ci]', '[ci skip]',
'[skip action]', '[action skip]',
'[skip actions]', '[actions skip]'
];
const accepted_flags_input = core.getInput("SKIP_DIRECTIVES", { required: false });
const accepted_flags = accepted_flags_input.split(",");
const pr = github.context.payload.pull_request;
if (!pr) {
core.info("This action only runs for pull request, exiting with no-op");
Expand All @@ -64,7 +61,7 @@ function run() {
core.info(` ${accepted_flags[i]}`);
}
if (accepted_flags.some(v => msg.includes(v))) {
core.setFailed(`"${commit.data.message}" contains directive to skip CI, failing this check`);
core.setFailed(`"${commit.data.message}" contains directive to skip, failing this check`);
/* Instead of failing, can also try to cancel but the token needs write access,
so we cannot implement this for OSS in reality. */
/*
Expand All @@ -79,7 +76,7 @@ function run() {
*/
}
else {
core.info(`No directive to skip CI found in "${commit.data.message}", moving on...`);
core.info(`No directive to skip found in "${commit.data.message}", moving on...`);
}
}
catch (err) {
Expand Down
10 changes: 4 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import * as github from "@actions/github";

async function run() {
try {
const accepted_flags:Array<string> = [
'[skip ci]', '[ci skip]',
'[skip action]', '[action skip]',
'[skip actions]', '[actions skip]'];
const accepted_flags_input = core.getInput("SKIP_DIRECTIVES", { required: false });
const accepted_flags = accepted_flags_input.split(",");

const pr = github.context.payload.pull_request;
if (!pr) {
Expand All @@ -29,7 +27,7 @@ async function run() {
}

if (accepted_flags.some(v => msg.includes(v))) {
core.setFailed(`"${commit.data.message}" contains directive to skip CI, failing this check`);
core.setFailed(`"${commit.data.message}" contains directive to skip, failing this check`);

/* Instead of failing, can also try to cancel but the token needs write access,
so we cannot implement this for OSS in reality. */
Expand All @@ -44,7 +42,7 @@ async function run() {
});
*/
} else {
core.info(`No directive to skip CI found in "${commit.data.message}", moving on...`);
core.info(`No directive to skip found in "${commit.data.message}", moving on...`);
}
} catch(err) {
core.setFailed(`Action failed with error ${err}`);
Expand Down

0 comments on commit bd536bd

Please sign in to comment.