Add a workflow that stops pulle request whit out a lable #6
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check for label on pull request | |
on: | |
pull_request: | |
types: [opened, labeled, unlabeled] | |
branches: | |
- main | |
jobs: | |
check-lables: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get PR labels | |
run: | | |
PR_LABELS="${{ join(github.event.pull_request.labels.*.name, ',') }}" | |
echo "PR_LABELS=$PR_LABELS" >> $GITHUB_ENV | |
echo "Labels fetched: $PR_LABELS" | |
- name: Calculate number of labels | |
run: | | |
LABEL_COUNT=$(echo "$PR_LABELS" | awk -F',' '{print NF}') | |
echo "LABEL_COUNT=$LABEL_COUNT" >> $GITHUB_ENV | |
- name: Contains lable | |
if: ${{ env.LABEL_COUNT == '0' }} | |
run: | | |
echo "The pull request needs a lable." | |
exit 1 #This fails the action | |
- name: Check if pull request labels combination is okay | |
run: | | |
#if it has exatly one label there is no combination | |
if [ "$LABEL_COUNT" -eq 1 ] exit 0; fi | |
#E alows for use of or operators | |
#breaking | |
if echo "$PR_LABELS" | grep -q "\bbreaking\b"; then | |
NOT_ALLOWED_LABELS="refactor|test|workflow" | |
if echo "$PR_LABELS" | grep -qE "\b($NOT_ALLOWED_LABELS)\b"; then | |
exit 1 | |
fi | |
#bug | |
elif echo "$PR_LABELS" | grep -q "\bbug\b"; then | |
NOT_ALLOWED_LABELS="refactor" | |
if echo "$PR_LABELS" | grep -qE "\b($NOT_ALLOWED_LABELS)\b"; then | |
exit 1 | |
fi | |
#feature | |
elif echo "$PR_LABELS" | grep -q "\bfeature\b"; then | |
NOT_ALLOWED_LABELS="refactor|test" | |
if echo "$PR_LABELS" | grep -qE "\b($NOT_ALLOWED_LABELS)\b"; then | |
exit 1 | |
fi | |
fi | |