• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2#
3# Copyright 2024 The Fuchsia Authors
4#
5# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
6# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
7# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
8# This file may not be copied, modified, or distributed except according to
9# those terms.
10
11set -eo pipefail
12echo "Running pre-push git hook: $0"
13# Forego redirecting stdout to /dev/null on check_fmt.sh because the output from
14# `cargo fmt` is useful (and the good stuff is not delivered by stderr).
15#
16# Background all jobs and wait for them so they can run in parallel.
17./ci/check_fmt.sh                              & FMT_PID=$!
18./ci/check_all_toolchains_tested.sh >/dev/null & TOOLCHAINS_PID=$!
19./ci/check_job_dependencies.sh      >/dev/null & JOB_DEPS_PID=$!
20./ci/check_readme.sh                >/dev/null & README_PID=$!
21./ci/check_versions.sh              >/dev/null & VERSIONS_PID=$!
22
23# `wait <pid>` exits with the same status code as the job it's waiting for.
24# Since we `set -e` above, this will have the effect of causing the entire
25# script to exit with a non-zero status code if any of these jobs does the same.
26# Note that, while `wait` (with no PID argument) waits for all backgrounded
27# jobs, it exits with code 0 even if one of the backgrounded jobs does not, so
28# we can't use it here.
29wait $FMT_PID
30wait $TOOLCHAINS_PID
31wait $JOB_DEPS_PID
32wait $README_PID
33wait $VERSIONS_PID
34
35# Ensure that this script calls all scripts in `ci/*`. This isn't a foolproof
36# check since it just checks for the string in this script (e.g., it could be in
37# a comment, which would trigger a false positive), but it should catch obvious
38# errors. Also note that this entire hook is a nice-to-have - failures that
39# aren't caught here will still be caught in CI.
40#
41# This was added because, in #728, we added `ci/check_all_toolchains_tested.sh`
42# without calling it from this script.
43GLOBIGNORE="./*/release_crate_version.sh" # We don't want to run this one
44for f in ./ci/*; do
45    grep "$f" githooks/pre-push >/dev/null || { echo "$f not called from githooks/pre-push" >&2 ; exit 1; }
46done
47unset GLOBIGNORE
48