You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by ad...@apache.org on 2022/06/10 20:20:14 UTC

[ozone] branch master updated: HDDS-6845. Add CI check for pull request title (#3494)

This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 4f0bd4ae3a HDDS-6845. Add CI check for pull request title (#3494)
4f0bd4ae3a is described below

commit 4f0bd4ae3a79cc64481071d98a2dbfe44ffd7656
Author: Kaijie Chen <ch...@kaijie.org>
AuthorDate: Sat Jun 11 04:20:08 2022 +0800

    HDDS-6845. Add CI check for pull request title (#3494)
---
 .github/workflows/pull-request.yml      |  36 +++++++++++
 dev-support/ci/pr_title_check.bats      | 107 ++++++++++++++++++++++++++++++++
 dev-support/ci/pr_title_check.sh        |  48 ++++++++++++++
 hadoop-ozone/dev-support/checks/bats.sh |   1 +
 4 files changed, 192 insertions(+)

diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml
new file mode 100644
index 0000000000..f37e680a5f
--- /dev/null
+++ b/.github/workflows/pull-request.yml
@@ -0,0 +1,36 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+name: pull request
+
+on:
+  pull_request:
+    types:
+      - reopened
+      - opened
+      - edited
+      - synchronize
+
+jobs:
+  title:
+    runs-on: ubuntu-20.04
+    steps:
+      - name: Checkout project
+        uses: actions/checkout@v3
+      - name: Check pull request title
+        env:
+          TITLE: ${{ github.event.pull_request.title }}
+        run:
+          dev-support/ci/pr_title_check.sh "${TITLE}"
diff --git a/dev-support/ci/pr_title_check.bats b/dev-support/ci/pr_title_check.bats
new file mode 100644
index 0000000000..633d0179a1
--- /dev/null
+++ b/dev-support/ci/pr_title_check.bats
@@ -0,0 +1,107 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This script confirms that pr_title_check.sh works correctly
+# against some valid and invalid examples.
+#
+# Prerequisites:
+#
+# 1. Install bats-core, see:
+#    https://bats-core.readthedocs.io/en/stable/installation.html
+#
+# 2. Clone libraries into dev-support/ci:
+#    cd dev-support/ci
+#    git clone https://github.com/bats-core/bats-assert
+#    git clone https://github.com/bats-core/bats-support
+#
+# Usage:
+#    bats dev-support/ci/pr_title_check.bats
+
+load bats-support/load.bash
+load bats-assert/load.bash
+
+@test "check legal PR title examples" {
+  # 1 digit Jira
+  run dev-support/ci/pr_title_check.sh 'HDDS-1. Hello World'
+  assert_output 'OK'
+
+  # 2 digits Jira
+  run dev-support/ci/pr_title_check.sh 'HDDS-12. Hello World'
+  assert_output 'OK'
+
+  # 3 digits Jira
+  run dev-support/ci/pr_title_check.sh 'HDDS-123. Hello World'
+  assert_output 'OK'
+
+  # 4 digits Jira
+  run dev-support/ci/pr_title_check.sh 'HDDS-1234. Hello World'
+  assert_output 'OK'
+
+  # 5 digits Jira
+  run dev-support/ci/pr_title_check.sh 'HDDS-12345. Hello World'
+  assert_output 'OK'
+
+  # PR with tag
+  run dev-support/ci/pr_title_check.sh 'HDDS-1234. [Tag] Hello World'
+  assert_output 'OK'
+
+  # trailing dot is allowed
+  run dev-support/ci/pr_title_check.sh 'HDDS-1234. Hello World.'
+  assert_output 'OK'
+
+  # case in summary does not matter
+  run dev-support/ci/pr_title_check.sh 'HDDS-1234. hello world in lower case'
+  assert_output 'OK'
+}
+
+@test "check illegal PR title examples" {
+  # HDDS case matters
+  run dev-support/ci/pr_title_check.sh 'Hdds-1234. Hello World'
+  assert_output 'Fail: must start with HDDS'
+
+  # missing dash in Jira
+  run dev-support/ci/pr_title_check.sh 'HDDS 1234. Hello World'
+  assert_output 'Fail: missing dash in Jira'
+
+  # 6 digits Jira not needed yet 
+  run dev-support/ci/pr_title_check.sh 'HDDS-123456. Hello World'
+  assert_output 'Fail: Jira must be 1 to 5 digits'
+
+  # leading zero in Jira
+  run dev-support/ci/pr_title_check.sh 'HDDS-01234. Hello World'
+  assert_output 'Fail: leading zero in Jira'
+
+  # missing dot after Jira
+  run dev-support/ci/pr_title_check.sh 'HDDS-1234 Hello World'
+  assert_output 'Fail: missing dot after Jira'
+
+  # missing space after Jira
+  run dev-support/ci/pr_title_check.sh 'HDDS-1234.Hello World'
+  assert_output 'Fail: missing space after Jira'
+
+  # trailing space
+  run dev-support/ci/pr_title_check.sh 'HDDS-1234. Hello World '
+  assert_output 'Fail: trailing space'
+
+  # double spaces after Jira
+  run dev-support/ci/pr_title_check.sh 'HDDS-1234.  Hello World'
+  assert_output 'Fail: two consecutive spaces'
+
+  # double spaces in summary
+  run dev-support/ci/pr_title_check.sh 'HDDS-1234. Hello  World'
+  assert_output 'Fail: two consecutive spaces'
+}
diff --git a/dev-support/ci/pr_title_check.sh b/dev-support/ci/pr_title_check.sh
new file mode 100755
index 0000000000..826b58a038
--- /dev/null
+++ b/dev-support/ci/pr_title_check.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+TITLE=$1
+
+assertMatch() {
+    echo "${TITLE}" | grep -E "$1" >/dev/null
+    ret=$?
+    if [ $ret -ne 0 ]; then
+        echo $2
+        exit 1
+    fi
+}
+
+assertNotMatch() {
+    echo "${TITLE}" | grep -E -v "$1" >/dev/null
+    ret=$?
+    if [ $ret -ne 0 ]; then
+        echo $2
+        exit 1
+    fi
+}
+
+assertMatch    '^HDDS'                             'Fail: must start with HDDS'
+assertMatch    '^HDDS-'                            'Fail: missing dash in Jira'
+assertNotMatch '^HDDS-0'                           'Fail: leading zero in Jira'
+assertMatch    '^HDDS-[1-9][0-9]{0,4}[^0-9]'       'Fail: Jira must be 1 to 5 digits'
+assertMatch    '^HDDS-[1-9][0-9]{0,4}\.'           'Fail: missing dot after Jira'
+assertMatch    '^HDDS-[1-9][0-9]{0,4}\. '          'Fail: missing space after Jira'
+assertNotMatch '[[:space:]]$'                      'Fail: trailing space'
+assertNotMatch '[[:space:]]{2}'                    'Fail: two consecutive spaces'
+assertMatch    '^HDDS-[1-9][0-9]{0,4}\. .*[^ ]$'   'Fail: not match "^HDDS-[1-9][0-9]{0,4}\. .*[^ ]$"'
+
+echo 'OK'
diff --git a/hadoop-ozone/dev-support/checks/bats.sh b/hadoop-ozone/dev-support/checks/bats.sh
index dc071324a5..407457612c 100755
--- a/hadoop-ozone/dev-support/checks/bats.sh
+++ b/hadoop-ozone/dev-support/checks/bats.sh
@@ -33,6 +33,7 @@ rm -f "${REPORT_DIR}/output.log"
 find * \( \
     -path '*/src/test/shell/*' -name '*.bats' \
     -or -path dev-support/ci/selective_ci_checks.bats \
+    -or -path dev-support/ci/pr_title_check.bats \
     \) -print0 \
   | xargs -0 -n1 bats --formatter tap \
   | tee -a "${REPORT_DIR}/output.log"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org