diff --git a/libcxx/utils/ci/buildkite-pipeline-trigger.sh b/libcxx/utils/ci/buildkite-pipeline-trigger.sh new file mode 100755 --- /dev/null +++ b/libcxx/utils/ci/buildkite-pipeline-trigger.sh @@ -0,0 +1,37 @@ +#===----------------------------------------------------------------------===## +# +# Part of the LLVM Project, 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 +# +#===----------------------------------------------------------------------===## + +# +# This file generates a Buildkite pipeline that triggers the libc++ CI +# job(s) if needed. The intended usage of this script is to be piped +# into `buildkite-agent pipeline upload`. +# + +if git diff --name-only HEAD~ | grep -q -E "libcxx/|libcxxabi/"; then + skip="false" +else + skip="The commit does not touch libc++ or libc++abi" +fi + +reviewID="$(git log --format=%B -n 1 | sed -nE 's/^Review-ID:[[:space:]]*(.+)$/\1/p')" +if [[ "${reviewID}" != "" ]]; then + buildMessage="https://llvm.org/${reviewID}" +else + buildMessage="Push to branch ${BUILDKITE_BRANCH}" +fi + +cat < 0 for match in matches): + return False + + # Error while running CMake + if 'CMake Error' in log or 'Configuring incomplete, errors occurred!' in log: + return False + + # Ninja failed to build some target + if 'FAILED:' in log: + return False + + return True + def main(argv): parser = argparse.ArgumentParser( description=""" @@ -31,8 +76,12 @@ The script is assumed to be running inside a Buildkite agent, and as such, it assumes the existence of several environment variables that are specific -to Buildkite. It also assumes that it is running in a context where the HEAD -commit contains the Phabricator ID of the review to update. +to Buildkite. + +It also assumes that it is running in a context where the HEAD commit contains +the Phabricator ID of the review to update. If the commit does not contain the +Phabricator ID, this script is basically a no-op. This allows running the CI +on commits that are not triggered by a Phabricator review. """) args = parser.parse_args(argv) @@ -60,7 +109,7 @@ # Then, extract information from the environment and post-process the logs. log.seek(0) log = log.read() - result = 'fail' if 'FAILED:' in log else 'pass' + result = 'pass' if buildPassed(log) else 'fail' resultObject = { 'name': '{BUILDKITE_LABEL} ({BUILDKITE_BUILD_URL}#{BUILDKITE_JOB_ID})'.format(**os.environ), 'result': result, @@ -70,15 +119,21 @@ commitMessage = subprocess.check_output(['git', 'log', '--format=%B' , '-n', '1']).decode() phabricatorID = re.search(r'^Phabricator-ID:\s+(.+)$', commitMessage, flags=re.MULTILINE) - if not phabricatorID: - raise RuntimeError('Could not find the Phabricator ID in the commit message. ' - 'The commit message was:\n{}'.format(commitMessage)) - else: - phabricatorID = phabricatorID.group(1) - token = os.environ['CONDUIT_TOKEN'] - phab = phabricator.Phabricator(token=token, host=LLVM_REVIEWS_API) - phab.harbormaster.sendmessage(buildTargetPHID=phabricatorID, type=result, unit=[resultObject]) + # If there's a Phabricator ID in the commit, then the build was triggered + # by a Phabricator review -- update the results back. Otherwise, don't + # do anything. + if phabricatorID: + phabricatorID = phabricatorID.group(1) + token = os.environ['CONDUIT_TOKEN'] + phab = phabricator.Phabricator(token=token, host=LLVM_REVIEWS_API) + exponentialBackoffRetry( + lambda: phab.harbormaster.sendmessage(buildTargetPHID=phabricatorID, type=result, unit=[resultObject]), + exception=socket.timeout + ) + else: + print('The HEAD commit does not appear to be tied to a Phabricator review -- ' + 'not uploading the results to any review.') if __name__ == '__main__': main(sys.argv[1:]) diff --git a/libcxx/utils/ci/run-buildbot.sh b/libcxx/utils/ci/run-buildbot.sh --- a/libcxx/utils/ci/run-buildbot.sh +++ b/libcxx/utils/ci/run-buildbot.sh @@ -123,5 +123,5 @@ echo "+++ Running the libc++abi tests" ninja -C "${BUILD_DIR}" check-cxxabi -echo "+++ Running the libc++ benchmarks" -ninja -C "${BUILD_DIR}" check-cxx-benchmarks +# echo "+++ Running the libc++ benchmarks" +# ninja -C "${BUILD_DIR}" check-cxx-benchmarks