Blogmark

Useful label-based GitHub Actions workflows

via jbranchaud@gmail.com

https://www.jessesquires.com/blog/2021/08/24/useful-label-based-github-actions-workflows/#updated-21-march-2022
GitHub GitHub Actions

I was looking at how others have implemented a GitHub Action to trigger a failed check on a PR when it is tagged with certain labels, such as No Merge or WIP.

I came across this blog post which included an updated code block on how to achieve this without any 3rd-party actions. This is also the simplest example I found coming in at 18 lines.

My contribution was to alter the if check to look at multiple labels:

jobs:
  do-not-merge:
    if: ${{ contains(github.event.*.labels.*.name, 'no merge') || contains(github.event.*.labels.*.name, 'wip') }}

I also printed out the labels to add a bit more detail in the action log:

    steps:
      - name: Check for label
        run: |
          echo "Pull request label prevents merging"
          echo "Labels: ${{ join(github.event.*.labels.*.name, ', ') }}"
          echo "This workflow fails so that the pull request cannot be merged"
          exit 1

TIL'd: Use Labels To Block PR Merge