@@ -48,50 +48,46 @@ be defined as environment variables in your Kokoro configuration.
4848Example installation script using a pre-built clang-format binary:
4949
5050``` bash
51- CLANG_FORMAT_VERSION=" r343360"
52- CLANG_FORMAT_SHA=" 9d2a3aeaee65f09ae5405dd33812d167fadd48aba712965cdb3238e5d8837255"
53- GIT_CLANG_FORMAT_VERSION=" c510fac5695e904b43d5bf0feee31cc9550f110e"
54- GIT_CLANG_FORMAT_SHA=" 1f6cfad79f90ea202dcf2d52a360186341a589cdbfdee05b0e7694f912aa9820"
55-
56- install_clang_format () {
57- mkdir bin
58- pushd bin >> /dev/null
59-
60- echo " Downloading clang-format..."
61- curl -Ls " https://github.com/material-foundation/clang-format/releases/download/$CLANG_FORMAT_VERSION /clang-format" -o " clang-format"
62- if openssl sha -sha256 " clang-format" | grep -q " $CLANG_FORMAT_SHA " ; then
63- echo " SHAs match. Proceeding."
64- else
65- echo " clang-format does not match sha. Aborting."
66- exit 1
51+ # Fail on any error.
52+ set -e
53+
54+ REPO=" <TODO: Your github repo. E.g. material-foundation/clang-format-ci>"
55+
56+ # The tagged version of https://github.com/material-foundation/clang-format-ci to check out.
57+ # A * wildcard can be used to check out the latest release of a given version.
58+ CLANG_FORMAT_CI_VERSION=" v1.*"
59+
60+ CLANG_FORMAT_CI_SRC_DIR=" .clang-format-ci-src"
61+
62+ # Will run git clang-format on the branch's changes, reporting a failure if the linter generated any
63+ # stylistic changes.
64+ #
65+ # For local runs, you must set the following environment variables:
66+ #
67+ # GITHUB_API_TOKEN -> Create a token here: https://github.com/settings/tokens.
68+ # Must have public_repo scope.
69+ # KOKORO_GITHUB_PULL_REQUEST_NUMBER="###" -> The PR # you want to post the API diff results to.
70+ # KOKORO_GITHUB_PULL_REQUEST_COMMIT="..." -> The PR commit you want to post to.
71+ #
72+ # And install the following tools:
73+ #
74+ # - clang-format
75+ # - git-clang-format
76+ lint_clang_format () {
77+ if [ ! -d " $CLANG_FORMAT_CI_SRC_DIR " ]; then
78+ git clone --recurse-submodules https://github.com/material-foundation/clang-format-ci.git " $CLANG_FORMAT_CI_SRC_DIR "
6779 fi
68- chmod +x " clang-format"
69-
70- echo " Downloading git-clang-format..."
71- curl -Ls " https://raw.githubusercontent.com/llvm-mirror/clang/$GIT_CLANG_FORMAT_VERSION /tools/clang-format/git-clang-format" -o " git-clang-format"
72- if openssl sha -sha256 " git-clang-format" | grep -q " $GIT_CLANG_FORMAT_SHA " ; then
73- echo " SHAs match. Proceeding."
74- else
75- echo " git-clang-format does not match sha. Aborting."
76- exit 1
77- fi
78- chmod +x " git-clang-format"
7980
80- export PATH=" $( pwd) :$PATH "
81+ pushd " $CLANG_FORMAT_CI_SRC_DIR "
82+ git fetch > /dev/null
83+ TAG=$( git tag --sort=v:refname -l " $CLANG_FORMAT_CI_VERSION " | tail -n1)
84+ git checkout " $TAG " > /dev/null
85+ echo " Using clang-format-ci $TAG "
86+ popd
8187
82- popd >> /dev/null
88+ .clang-format-ci-src/from-kokoro.sh " $REPO "
8389}
8490
85- if ! git clang-format -h > /dev/null 2> /dev/null; then
86- install_clang_format
87- fi
88-
89- git clone --branch < TODO: version> https://github.com/material-foundation/clang-format-ci.git
90- ./clang-format-ci/check-pull-request.sh \
91- --api_token " $API_TOKEN " \
92- --repo " $REPO " \
93- --pr " $KOKORO_GITHUB_PULL_REQUEST_NUMBER " \
94- --commit " $KOKORO_GITHUB_PULL_REQUEST_COMMIT " \
95- --target_branch " $KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH "
91+ lint_clang_format
9692```
9793
0 commit comments