Make a few improvements to linting (#8184)

Use our own script for the yamllint check. This allows us to only
look at modified files and run it locally as part of lint.sh

Made some misc cleanups to the other bash scripts along the way, like
making check_tabs.sh not hang forever if there are no modified files
(grep gets passed an empty list of files and then sits there waiting
for input).
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index c20e5b3..1d1f9e3 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -123,9 +123,10 @@
   yamllint:
     runs-on: ubuntu-18.04
     steps:
-      - uses: actions/checkout@v2
-      - name: yaml-lint
-        uses: ibiqlik/action-yamllint@v1
-        with:
-          strict: true
-          file_or_dir: .github/**/*.yml build_tools/buildkite/**/*.yml
+      - name: Checking out repository
+        uses: actions/checkout@v2
+      - name: Fetching Base Branch
+        # We have to explicitly fetch the base branch as well
+        run: git fetch --no-tags --prune --depth=1 origin "${GITHUB_BASE_REF?}:${GITHUB_BASE_REF?}"
+      - name: yamllint
+        run: ./scripts/run_yamllint.sh
diff --git a/scripts/check_tabs.sh b/scripts/check_tabs.sh
index 3434fa0..0e3c582 100755
--- a/scripts/check_tabs.sh
+++ b/scripts/check_tabs.sh
@@ -18,6 +18,7 @@
   "/third_party/"
   "^third_party/"
   "*Makefile*"
+  # Symlinks make grep upset
   "^integrations/tensorflow/iree-dialects$"
 )
 
@@ -28,6 +29,10 @@
   (git diff --name-only --diff-filter=d "${BASE_REF}" || kill $$) \
     | grep -v -E "${excluded_files_pattern?}")
 
+if (( ${#files[@]} == 0 )); then
+  exit 0
+fi;
+
 diff="$(grep --with-filename --line-number --perl-regexp --binary-files=without-match '\t' "${files[@]}")"
 
 grep_exit="$?"
diff --git a/scripts/lint.sh b/scripts/lint.sh
index bdcb808..4bff737 100755
--- a/scripts/lint.sh
+++ b/scripts/lint.sh
@@ -74,7 +74,7 @@
 echo "***** yapf *****"
 # Don't fail script if condition is false
 disable_update_ret
-if exists yapf > /dev/null; then
+if exists yapf; then
   enable_update_ret
   git diff -U0 main | ./third_party/format_diff/format_diff.py yapf -i
 else
@@ -109,9 +109,16 @@
 ./scripts/check_tabs.sh
 
 echo "***** yamllint *****"
-echo "'yamllint' check not yet implemented. Skipping check"
+disable_update_ret
+if exists yamllint; then
+  enable_update_ret
+  ./scripts/run_yamllint.sh
+else
+  enable_update_ret
+  echo "'yamllint' not found. Skipping check"
+fi
 
-if [[ "${FINAL_RET}" -ne 0 ]]; then
+if (( "${FINAL_RET}" != 0 )); then
   echo "Encountered failures. Check error messages and changes to the working" \
        "directory and git index (which may contain fixes) and try again."
 fi
diff --git a/scripts/run_buildifier.sh b/scripts/run_buildifier.sh
index 298c4ac..6edae4c 100755
--- a/scripts/run_buildifier.sh
+++ b/scripts/run_buildifier.sh
@@ -35,7 +35,7 @@
     | grep -E "${included_files_pattern?}" \
     | grep -v -E "${excluded_files_pattern?}")
 
-if [ ${#files[@]} -eq 0 ]; then
+if (( ${#files[@]} == 0 )); then
   echo "No Bazel files changed"
   exit 0
 fi
diff --git a/scripts/run_yamllint.sh b/scripts/run_yamllint.sh
new file mode 100755
index 0000000..a465af8
--- /dev/null
+++ b/scripts/run_yamllint.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+# Copyright 2021 The IREE Authors
+#
+# Licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+# Runs yamllint on files modified vs the specified reference commit
+# (default "main")
+
+set -uo pipefail
+
+BASE_REF="${1:-main}"
+
+declare -a included_files_patterns=(
+  "\.yaml$"
+  "\.yml$"
+)
+
+declare -a excluded_files_patterns=(
+  "/third_party/"
+  "^third_party/"
+)
+
+# Join on |
+included_files_pattern="$(IFS="|" ; echo "${included_files_patterns[*]?}")"
+excluded_files_pattern="$(IFS="|" ; echo "${excluded_files_patterns[*]?}")"
+
+readarray -t files < <(\
+  (git diff --name-only --diff-filter=d "${BASE_REF}" || kill $$) \
+    | grep -E "${included_files_pattern?}" \
+    | grep -v -E "${excluded_files_pattern?}")
+
+if (( ${#files[@]} == 0 )); then
+  echo "No Yaml files changed"
+  exit 0
+fi
+
+
+yamllint --strict "${files[@]}"