Skip to content

Commit 3adb0e1

Browse files
NEW: Add check for PR titles prefixes in CI
1 parent 5016d79 commit 3adb0e1

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

.github/workflows/pr-title.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: CI
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on pull request creation and edit events but only for the "main" branch
8+
pull_request:
9+
types:
10+
- edited
11+
- opened
12+
- synchronize
13+
branches: [ "develop" ]
14+
15+
# Allows you to run this workflow manually from the Actions tab
16+
workflow_dispatch:
17+
18+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
19+
jobs:
20+
# This workflow contains a single job called "build"
21+
check-pr-title:
22+
# The type of runner that the job will run on
23+
runs-on: ubuntu-latest
24+
# Steps represent a sequence of tasks that will be executed as part of the job
25+
steps:
26+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
27+
- uses: actions/checkout@v4
28+
29+
# Runs a bash script from the specified working directory
30+
- name: Check PR Title begins with the required prefix
31+
shell: bash
32+
working-directory: .github/workflows
33+
env:
34+
TITLE: ${{github.event.pull_request.title}}
35+
run: bash verify-pr-title-prefix.sh $TITLE "NEW:" "CHANGE:" "FIX:" "DOCS:" "RELEASE:"
36+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
exit_with_failure()
4+
{
5+
echo "$*" 1>&2 ; exit 1;
6+
}
7+
8+
TITLE_STRING="$1"
9+
shift # Shift all arguments to the left, so $2 becomes $1, $3 becomes $2, etc.
10+
11+
# The remaining arguments are treated as an array of strings
12+
PREFIXES_REQUIRED=("$@")
13+
14+
# Validate the title string prefix based on prefixes required
15+
for PREFIX in "${PREFIXES_REQUIRED[@]}";
16+
do
17+
if [[ "$TITLE_STRING" =~ ^$PREFIX ]]; then
18+
echo ""
19+
exit 0
20+
fi
21+
done
22+
23+
PREFIXES_REQUIRED_STRING="${PREFIXES_REQUIRED[*]}"
24+
25+
exit_with_failure "PR Title needs the required prefixes: $PREFIXES_REQUIRED_STRING"

0 commit comments

Comments
 (0)