Test - PR checking for labels #12
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 Labels | |
# Every PR should have a label and some labels should include an update to the release notes | |
on: | |
pull_request: | |
branches-ignore: | |
- 'main' | |
- 'release/**' | |
types: [ synchronize, labeled, unlabeled ] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref }} | |
cancel-in-progress: true | |
jobs: | |
get_allowed_labels: | |
runs-on: ubuntu-latest | |
outputs: | |
allowed-labels: ${{ steps.get_allowed_labels.outputs.allowed_labels }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get the list of allowed pull request labels | |
id: get_allowed_labels | |
env: | |
PROJECT_ROOT: ${{ github.workspace }} | |
run: | | |
RED='\033[0;31m' | |
FILE_NAME=.release_notes_allowed_labels_list | |
GITHUB_DIR=.github | |
FILE_PATH=$PROJECT_ROOT/$GITHUB_DIR/$FILE_NAME | |
if [[ ! -f "$FILE_PATH" ]]; then | |
echo -e "${RED}$FILE_NAME file doesn't exits in $GITHUB_DIR/" | |
exit 1 | |
fi | |
ALLOWED_LABELS=$(cat $FILE_PATH) | |
echo -e "allowed_labels=$ALLOWED_LABELS" >> $GITHUB_OUTPUT | |
echo -e "Allowed labels are: $ALLOWED_LABELS" | |
labels-check: | |
runs-on: ubuntu-latest | |
needs: get_allowed_labels | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Validate release notes | |
env: | |
REQUIRED_PR_LABELS: "Breaking change,Feature,Fix" | |
OPTIONAL_PR_LABELS: "Dependencies,Chore" | |
ALLOWED_RELEASE_NOTES_LABELS: ${{ needs.get_allowed_labels.outputs.allowed-labels }} | |
PR_BODY: ${{ github.event.pull_request.body }} | |
run: | | |
# Fetch PR labels | |
ALL_PR_LABELS_JSON=$(cat <<EOF | |
${{ toJson(github.event.pull_request.labels.*.name) }} | |
EOF | |
) | |
ALL_PR_LABELS=$(jq -r '.[]' <<< "$ALL_PR_LABELS_JSON") | |
# Read PR labels into an array | |
IFS=',' read -r -a PR_LABELS <<< "$ALL_PR_LABELS" | |
echo "PR labels: $PR_LABELS" | |
# Initialize flags | |
REQUIRED_LABEL_MATCH=false | |
OPTIONAL_LABEL_MATCH=false | |
# Check labels against categories | |
for label in "${PR_LABELS[@]}"; do | |
if [[ ",$REQUIRED_PR_LABELS," == *",$label,"* ]]; then | |
REQUIRED_LABEL_MATCH=true | |
fi | |
if [[ ",$OPTIONAL_PR_LABELS," == *",$label,"* ]]; then | |
OPTIONAL_LABEL_MATCH=true | |
fi | |
done | |
# Handle matches | |
if [[ "$OPTIONAL_LABEL_MATCH" == "true" ]]; then | |
echo "This PR has an optional label. No release notes are required." | |
exit 0 | |
elif [[ "$REQUIRED_LABEL_MATCH" == "true" ]]; then | |
echo "This PR has a required label. Checking release notes..." | |
chmod +x scripts/check_release_notes_labels.sh | |
scripts/check_release_notes_labels.sh | |
else | |
echo "Error: You must add a valid label to this PR." | |
exit 1 | |
fi |