@@ -4,60 +4,23 @@ inputs:
44 title :
55 description : Pull request title
66 required : true
7- pattern :
8- description : Regex pattern the PR title must match
9- required : false
10- default : ' ^CCM-[0-9]+: .+$'
11- error_message :
12- description : Custom error message
13- required : false
14- default : Pull request title does not match required format
157runs :
168 using : composite
179 steps :
1810 - name : Validate PR title
1911 shell : bash
2012 env :
2113 TITLE : ${{ inputs.title }}
22- PATTERN : ${{ inputs.pattern }}
23- MESSAGE : ${{ inputs.error_message }}
2414 run : |
2515 title="$TITLE"
26- pattern="$PATTERN"
27- message="$MESSAGE"
28-
29- escape_workflow_command_value() {
30- local value="$1"
31- value="${value//'%'/'%25'}"
32- value="${value//$'\r'/'%0D'}"
33- value="${value//$'\n'/'%0A'}"
34- printf '%s' "$value"
35- }
36-
37- escaped_message="$(escape_workflow_command_value "$message")"
38- escaped_pattern="$(escape_workflow_command_value "$pattern")"
16+ pattern='^CCM-[0-9]+: .+$'
17+ message='PR title must match: CCM-1234: Some Text'
3918
4019 echo "PR title: $title"
41- echo "Required pattern: $pattern"
4220
43- if [ -z "$pattern" ]; then
44- echo "::error::Input 'pattern' must be a non-empty regular expression"
45- exit 1
46- fi
4721 if printf '%s\n' "$title" | grep -Eq -- "$pattern"; then
4822 echo "PR title is valid"
4923 else
50- status=$?
51- case "$status" in
52- 1)
53- echo "::error::$escaped_message"
54- ;;
55- 2)
56- echo "::error::Input 'pattern' is not a valid regular expression: $escaped_pattern"
57- ;;
58- *)
59- echo "::error::Unexpected error while validating PR title"
60- ;;
61- esac
24+ echo "::error::$message"
6225 exit 1
6326 fi
0 commit comments