blob: 25368cc4627bca4238bda7c1fdddcb12dc2a1b40 [file] [log] [blame]
Fabio Utzigefe67ae2017-12-05 16:03:02 -02001#!/bin/bash
Fabio Utzig5b989102017-09-04 16:27:51 -03002
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Fabio Utzig6da40d02017-09-12 11:32:32 -030015parents=(`git log -n 1 --format=%p HEAD`)
Fabio Utzig5b989102017-09-04 16:27:51 -030016
Almir Okato3eb06812023-01-27 16:15:30 -030017if [[ "${#parents[@]}" -eq 1 ]]; then
18 # CI doesn't use a merge commit
19 commits=$(git show -s --format=%h ${parents})
20elif [[ "${#parents[@]}" -eq 2 ]]; then
21 # CI uses a merge commit, eg GH / Travis
22 from="${parents[0]}"
23 into="${parents[1]}"
24 commits=$(git show -s --format=%h ${from}..${into})
25else
26 echo "Unexpected behavior, cannot verify more than 2 parent commits!"
Fabio Utzig6da40d02017-09-12 11:32:32 -030027 exit 1
28fi
29
Fabio Utzig31180172017-09-06 21:38:14 -030030has_commits=false
Fabio Utzig5b989102017-09-04 16:27:51 -030031for sha in $commits; do
Fabio Utzig0b561382017-09-07 17:04:26 -030032 author="Signed-off-by: $(git show -s --format="%an <%ae>" ${sha})"
33 committer="Signed-off-by: $(git show -s --format="%cn <%ce>" ${sha})"
34
Fabio Utzig31180172017-09-06 21:38:14 -030035 lines="$(git show -s --format=%B ${sha})"
Fabio Utzig0b561382017-09-07 17:04:26 -030036
37 found_author=false
Fabio Utzigce503342021-01-14 09:52:11 -030038 # Don't enforce committer email on forks; this primarily avoids issues
39 # running workflows on the zephyr fork, because rebases done in the GH UX
40 # use the primary email of the committer, which might not match the one
41 # used in git CLI.
42 if [[ $GITHUB_REPOSITORY == mcu-tools/* ]]; then
43 found_committer=false
44 else
45 found_committer=true
46 fi
47
Fabio Utzig31180172017-09-06 21:38:14 -030048 IFS=$'\n'
49 for line in ${lines}; do
50 stripped=$(echo $line | sed -e 's/^\s*//' | sed -e 's/\s*$//')
Fabio Utzigf8592552021-09-29 19:06:08 -030051 if [[ "${stripped}" == "${author}" ]]; then
Fabio Utzig0b561382017-09-07 17:04:26 -030052 found_author=true
Fabio Utzig31180172017-09-06 21:38:14 -030053 fi
Fabio Utzigf8592552021-09-29 19:06:08 -030054 if [[ "${stripped}" == "${committer}" ]]; then
Fabio Utzig0b561382017-09-07 17:04:26 -030055 found_committer=true
56 fi
57
58 [[ ${found_author} == true && ${found_committer} == true ]] && break
Fabio Utzig31180172017-09-06 21:38:14 -030059 done
Fabio Utzig5b989102017-09-04 16:27:51 -030060
Fabio Utzigd8f84bc2018-10-11 05:52:37 -070061 if [[ ${found_author} == false ]]; then
Fabio Utzig73d8b032018-10-11 06:14:26 -070062 echo -e "Missing \"${author}\" in commit ${sha}"
Fabio Utzigd8f84bc2018-10-11 05:52:37 -070063 fi
64 if [[ ${found_committer} == false ]]; then
Fabio Utzig38609e02018-10-13 15:16:25 -070065 echo -e "Missing \"${committer}\" in commit ${sha}"
Fabio Utzigd8f84bc2018-10-11 05:52:37 -070066 fi
Fabio Utzig0b561382017-09-07 17:04:26 -030067 if [[ ${found_author} == false || ${found_committer} == false ]]; then
Fabio Utzig5b989102017-09-04 16:27:51 -030068 exit 1
69 fi
Fabio Utzig31180172017-09-06 21:38:14 -030070
71 has_commits=true
Fabio Utzig5b989102017-09-04 16:27:51 -030072done
Fabio Utzig31180172017-09-06 21:38:14 -030073
74if [[ ${has_commits} = false ]]; then
75 echo "No commits found in this PR!"
76 exit 1
77fi