Support [skip ci] out of box with github actions
Problem
Pretty much every other ci/cd solution will skip running a workflow/pipeline if `[skip_ci]` is in the commit text. Currently the hack for this is to add an `if` statement to jobs with something like `"! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"`. However, this still runs the workflow, just not any jobs with the condition. Please provide an out of box way for this to happen. One solution would be something like paths-ignore: [code block] @eseay
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Implement [skip ci] Support in GitHub Actions Workflows
GitHub Actions does not natively support skipping workflows based on commit messages like other CI/CD solutions. The existing workaround only prevents jobs from running but still triggers the workflow, leading to unnecessary resource usage.
Awaiting Verification
Be the first to verify this fix
- 1
Create a Workflow Dispatch Event
Modify the GitHub Actions workflow to include a 'workflow_dispatch' event. This allows for manual triggering of workflows and can be combined with the commit message check to skip execution.
yamlon: push: branches: - main workflow_dispatch: - 2
Add Conditional Check for [skip ci]
Implement a condition at the workflow level to check for the presence of '[skip ci]' in the commit messages. If found, the workflow will not execute.
yamlif: '!contains(github.event.head_commit.message, '[skip ci]')' - 3
Update Workflow Jobs to Use the New Condition
Ensure that each job within the workflow uses the defined condition to prevent execution if '[skip ci]' is detected in the commit message.
yamljobs: build: runs-on: ubuntu-latest if: '!contains(github.event.head_commit.message, '[skip ci]')' steps: - name: Checkout code uses: actions/checkout@v2 - 4
Test the Implementation
Create test commits with and without '[skip ci]' in the message to verify that the workflow behaves as expected. Ensure that workflows are skipped when the message is present.
Validation
Confirm the fix by pushing commits with '[skip ci]' and checking the Actions tab in GitHub to ensure the workflow does not run. Also, push commits without the tag to verify that the workflow executes normally.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep