Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I filter a GitHub action step based on the commit message?

I've recently added a static analysis step to my GitHub actions. However, it is somewhat expensive so I'm trying to reduce the number of times that this step is run. I've already added an appropriate filter so that it only runs on one OS and so that it only runs on my "feature" branches. However, I would like to also filter out any checkins that include "WIP" in their commit message. (The theory being that there is no point in performing the full analysis until it is no longer a "Work In Progress".)

I've searched through the docs, expecting I would find an object I could use as part of the github context object, but to no avail.

Any ideas on how I can accomplish this goal?

If you want to see exactly what I'm doing, the action Yaml is as follows. I'm hoping to find some change I can make to the if statement on the Static Analysis item that would accomplish my goal.

name: On Push

on: [push]

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
    steps:
    - uses: actions/checkout@v1

    - name: Build
      run: |
        ./configure
        make -j 4

    - name: Run tests
      run: |
        make -j 4 check

    - name: Static Analysis
      if: runner.os == 'macOS' && startsWith(github.ref, 'refs/heads/feature/')
      run: |
        make analyze
like image 561
Steven W. Klassen Avatar asked Dec 21 '19 19:12

Steven W. Klassen


People also ask

Do commit messages support markdown?

Use Markdown to format your text. Some tools like GitHub will render Markdown when showing commit messages. Use asterisks bullets when you need to explain a long list of changes. The commit message should be clear on its own.

How detailed should commit messages be?

The description is better to be up to 72 characters. Preslav Rachev in his article explains the reason for the 50/72 rule. The ideal size of a git commit summary is around 50 characters in length. Analyzing the average length of commit messages in the Linux kernel suggests this number.

Can you CD in GitHub Actions?

With GitHub Actions, you can trigger CI/CD workflows and pipelines of webhooks from these apps (even something simple, like a chat app message, if you've integrated your chat app into your GitHub repository, of course).


2 Answers

You can make use of the event property on the github context to access the push payload.

Add the following to the step that does the analysis:

if: !startsWith(github.event.head_commit.message, 'WIP')
like image 55
smac89 Avatar answered Sep 19 '22 02:09

smac89


Related to your issue, you now (Feb. 2021) have:

GitHub Actions: Skip pull request and push workflows

with [skip ci]

GitHub Actions now supports skipping push and pull_request workflows by looking for some common keywords in your commit message.

If any commit message in your push or the HEAD commit of your PR contains the strings [skip ci], [ci skip], [no ci], [skip actions], or [actions skip] workflows triggered on the push or pull_request events will be skipped.

This is not as flexible as a custom commit message (like your "WIP"), but it still can help.

like image 43
VonC Avatar answered Sep 18 '22 02:09

VonC