File tree Expand file tree Collapse file tree 4 files changed +113
-0
lines changed Expand file tree Collapse file tree 4 files changed +113
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : " Commit Lint"
2
+ on :
3
+ pull_request :
4
+ branches :
5
+ - main
6
+ - development
7
+ - staging
8
+ types :
9
+ - opened
10
+ - reopened
11
+ - labeled
12
+ - unlabeled
13
+ - edited
14
+ - synchronize
15
+ jobs :
16
+ custom_test :
17
+ runs-on : ubuntu-latest
18
+ name : We test it locally with act
19
+ steps :
20
+ - uses : actions/checkout@v3
21
+ with :
22
+ token : ${{ secrets.PAT }}
23
+ fetch-depth : 0
24
+ - name : Conventional Commits Checker
25
+ uses : ./ # Uses an action in the root directory
26
+ id : commits-check
27
+ with :
28
+ target-branch : ${{ github.event.pull_request.base.ref }}
29
+ current-branch : ${{ github.event.pull_request.head.ref }}
30
+ - name : Get the Result
31
+ run : echo "${{ steps.commits-check.outputs.commit-checker }}"
Original file line number Diff line number Diff line change
1
+ # Base image
2
+ FROM alpine:latest
3
+
4
+ RUN apk add --no-cache \
5
+ bash \
6
+ ca-certificates \
7
+ curl \
8
+ git
9
+
10
+ COPY entrypoint.sh /entrypoint.sh
11
+
12
+ RUN chmod +x /entrypoint.sh
13
+
14
+ ENTRYPOINT ["/entrypoint.sh" ]
Original file line number Diff line number Diff line change
1
+ # action.yaml
2
+ name : ' Conventional Commits Checker'
3
+ description : ' Check that all pull request commits are following conventional commits'
4
+ inputs :
5
+ target-branch :
6
+ description : ' target branch'
7
+ required : true
8
+ default : ' main'
9
+ current-branch :
10
+ description : ' current-branch'
11
+ required : true
12
+ default : ' main'
13
+ outputs :
14
+ commit-checker :
15
+ description : ' true or false'
16
+ runs :
17
+ using : docker
18
+ image : Dockerfile
19
+ args :
20
+ - ${{ inputs.target-branch }}
21
+ - ${{ inputs.current-branch }}
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ set -e
3
+
4
+ git config --global --add safe.directory /github/workspace
5
+
6
+ # Define the branch names
7
+ main_branch=main=$1
8
+
9
+ echo $1
10
+ echo $2
11
+
12
+ # Get all commit messages from the feature branch that are not in the main branch
13
+ commits=($( git log --pretty=" %s EON" origin/$2 ^origin/$1 ) )
14
+
15
+ pattern=" (feat|fix|ci|chore|docs|test|style|refactor): +#([0-9]+) -.{1,}$"
16
+
17
+ # Loop through the array and create other structure data
18
+ commits_struct=()
19
+ for commit in " ${commits[@]} " ; do
20
+ if [ $commit != " EON" ]; then
21
+ commit_msg+=" $commit "
22
+ fi
23
+ if [ $commit == " EON" ]; then
24
+ commits_struct+=(" ${commit_msg} " )
25
+ commit_msg=" "
26
+ fi
27
+ done
28
+
29
+ all_commits_ok=" true"
30
+ echo " | commit | status"
31
+ for msg in " ${commits_struct[@]} " ; do
32
+ if [[ $msg =~ $pattern ]]; then
33
+ echo " $msg | ok"
34
+ else
35
+ echo " $msg | invalid"
36
+ all_commits_ok=" false"
37
+ fi
38
+ echo " --"
39
+ done
40
+
41
+ if [ $all_commits_ok == " true" ]; then
42
+ echo " commit-checker=true" >> $GITHUB_OUTPUT
43
+ exit 0
44
+ else
45
+ echo " commit-checker=false" >> $GITHUB_OUTPUT
46
+ exit 1
47
+ fi
You can’t perform that action at this time.
0 commit comments