As of February 8, 2021, Github Actions natively support skipping pull request and push workflow if any of the commit messages in your push or the HEAD commit of your PR contains
[skip ci]
, [ci skip]
, [no ci]
, [skip actions]
, or [actions skip]
. This achieves the exact same effect as the action without the need to change or structure your workflow in a certain way. You can still use this action to programatically run different jobs or steps. Run steps programatically example
Github action for skipping workflows upon matching or finding phrase in commit message(s) or pull request
Works by searching for phrase in or matching RegExp with commit message(s), pull request title, and/or pull request body. skip
output value can then be used to conditionally skip the following jobs or steps.
Github Actions does not natively support skipping or canceling workflow based on phrases in commit message like other CI tools do. This action was made to replicate this feature and let repositories save on CI minutes for small non-impacting changes to code bases.
Github workflow token is needed to make authenticated requests for commit and pull requests.
name: 'NodeJS CI'
on:
push:
pull_request:
- main
- master
jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: skip-workflow
id: skip-workflow # id used for referencing step
uses: saulmaldonado/skip-workflow@v1
with:
phrase: 'skip-workflow'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Use Node.js ${{ matrix.node-version }}
if: ${{ !steps.skip-workflow.outputs.skip }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm install
- name: Build
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm run build
- name: Test
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm test
View example workflow
name: 'NodeJS CI'
on:
push:
pull_request:
- main
- master
jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: skip-workflow
id: skip-workflow # id used for referencing step
uses: saulmaldonado/skip-workflow@v1
with:
phrase: /^\[skip-workflow\]/i # matches with commits starting with '[skip-workflow]'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Use Node.js ${{ matrix.node-version }}
if: ${{ !steps.skip-workflow.outputs.skip }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm install
- name: Build
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm run build
- name: Test
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm test
View example workflow
name: 'NodeJS CI'
on:
push:
pull_request:
- main
- master
jobs:
skip-workflow:
runs-on: ubuntu-latest
outputs: # job outputs
skip: ${{ steps.skip-workflow.outputs.skip }}
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: skip-workflow
id: skip-workflow # id used for referencing step
uses: saulmaldonado/skip-workflow@v1
with:
phrase: '[skip-workflow]'
github-token: ${{ secrets.GITHUB_TOKEN }}
build:
needs: skip-workflow # needs is required for reference and to prevent both jobs running at the same time
if: ${{ !needs.skip-workflow.outputs.skip }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm install
- name: Build
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm run build
Skip rest of job if phrase is found in all commit messages and the title of the incoming pull request
View example workflow
name: 'NodeJS CI'
on:
push:
pull_request:
- main
- master
jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: skip-workflow
id: skip-workflow # id used for referencing step
uses: saulmaldonado/skip-workflow@v1
with:
phrase: '[skip-workflow]'
search: '["commit_messages", "pull_request"]' # search commits and pr title
pr-message: 'title'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Use Node.js ${{ matrix.node-version }}
if: ${{ !steps.skip-workflow.outputs.skip }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm install
- name: Build
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm run build
- name: Test
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm test
View example workflow
name: 'NodeJS CI'
on:
push:
branches:
- main
- master
jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: skip-workflow
id: skip-workflow # id used for referencing step
uses: saulmaldonado/skip-workflow@v1
with:
phrase: '[skip-workflow]'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Use Node.js ${{ matrix.node-version }}
if: ${{ !steps.skip-workflow.outputs.skip }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm install
- name: Build
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm run build
- name: Test
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm test
View example workflow
name: 'NodeJS CI'
on:
push:
branches:
- main
- master
jobs:
skip-workflow:
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.skip-workflow.outputs.skip }}
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: skip-workflow
id: skip-workflow # id used for referencing step
uses: saulmaldonado/skip-workflow@v1
with:
phrase: '[skip-workflow]'
github-token: ${{ secrets.GITHUB_TOKEN }}
build:
needs: skip-workflow # needs is required for reference and to prevent both jobs running at the same time
if: ${{ !needs.skip-workflow.outputs.skip }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm install
- name: Build
if: ${{ !steps.skip-workflow.outputs.skip }}
run: npm run build
Fail and skip workflow immediately if phrase is found in all commit messages in push to main/master branch
View example workflow
name: 'NodeJS CI'
on:
push:
branches:
- main
- master
jobs:
skip-workflow:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: skip-workflow
id: skip-workflow # id used for referencing step
uses: saulmaldonado/skip-workflow@v1
with:
phrase: '[skip-workflow]'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: build
run: npm run build
- name: test
run: npm run test
Required: String phrase or RegExp to search for.
with:
phrase: '[skip-workflow]' # searches for phrase anywhere in text
# or
phrase: '/^\[skip-workflow\]/i'
Text to search in for match. JSON array
.
default: '["commit_messages"]'
with:
search: '["commit_messages", "pull_request"]' # any combination
Pull request text to search in. To be used along side search
option input '["pull_request"]'
.
default: 'title'
with:
search: '["pull_request"]' # pull_request must be included in search option input array
pr-message: 'title' # default
# or
pr-message: 'body'
# or
pr-message: 'title & body'
Required: Github workflow context token needed to search commits and pull request.
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Skip and fail workflow immediately after action confirms workflow can be skipped. Enabling this will fail the check.
default: 'false'
with:
fail-fast: 'false' # default
# or
fail-fast: 'true'
Result of search.
Can be:
true
: Match passed, workflow can be skippednull
: Match not passed, workflow must continue
steps:
- uses: actions/checkout@v2
- name: skip-workflow
id: skip-workflow # id used for referencing step
uses: saulmaldonado/skip-workflow@v1
with:
phrase: '[skip-workflow]'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: test
if: ${{ !steps.skip-workflow.outputs.skip }} # conditionally run following steps
Since all this action does is search for phrase and regex matches in messages, it can be used for many other scenarios outside of skipping workflows. If you want to programatically run jobs based on phrases found in PR or commit messages you can do so by adding conditionals to steps/jobs.
The following workflow will search for [deploy]
in any of the commit messages
jobs:
build-test-deploy:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: run-deploy
id: run-deploy # id used for referencing step
uses: saulmaldonado/skip-workflow@v1
with:
phrase: '[deploy]'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm install
- name: Build
run: npm run build
- name: Test
run: npm test
- name: Deploy
if: ${{ steps.run-deploy.outputs.skip }} # This step will only run if `[deploy]` is found
run: npm run deploy