-
Notifications
You must be signed in to change notification settings - Fork 15
59 lines (49 loc) · 1.76 KB
/
check-pr-title.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Validate PR Title
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
validate-pr-title:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Enable corepack
run: |
corepack enable
corepack prepare yarn@4.2.2 --activate
yarn set version 4.2.2
- name: Set up Node.js environment
uses: actions/setup-node@v4.0.4
with:
node-version: '>=18.12.x'
- name: Install dependencies
run: yarn install
- name: Extract PR title
id: extract_pr_title
run: echo "title=$(jq -r '.pull_request.title' $GITHUB_EVENT_PATH)" >> $GITHUB_OUTPUT
- name: Fetch commit messages
id: fetch_commits
run: |
commits=$(jq -r '.pull_request.commits_url' $GITHUB_EVENT_PATH)
curl -s $commits | jq -r '.[].commit.message' > commit_messages.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check for release commit
id: check_commit
# Check if any commit message starts with [RELEASE]
run: |
if grep -qE '^\[RELEASE\]' commit_messages.txt; then
echo "contains_release=true" >> $GITHUB_ENV
else
echo "contains_release=false" >> $GITHUB_ENV
fi
- name: Validate PR title
id: check_pr_title
run: |
if [[ "${{ env.contains_release }}" == "true" && ! "${{ steps.extract_pr_title.outputs.title }}" =~ ^\[RELEASE\] ]]; then
echo "PR title must start with [RELEASE] if any commit starts with [RELEASE]."
exit 1
else
echo "${{ steps.extract_pr_title.outputs.title }}" | yarn commitlint --verbose
fi