-
Notifications
You must be signed in to change notification settings - Fork 404
Add check/all #1146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mhucka
wants to merge
13
commits into
main
Choose a base branch
from
mh-add-check-all
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add check/all #1146
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a8c121a
Add check/all
mhucka 8ea7970
Merge branch 'main' into mh-add-check-all
mhucka 3a368b6
Remove description of non-existent `--no-coverage` option
mhucka cc75a88
Remove unnecessary exit statements
mhucka 373b4f8
Ignore `*,cover` files
mhucka bfe8785
Add check/all to scripts checked by check/shellcheck
mhucka 3cd8297
Apply suggestion from @pavoljuhas
mhucka 442b21d
Apply suggestion from @pavoljuhas
mhucka 45dfe78
Apply suggestion from @pavoljuhas
mhucka b202803
Apply suggestion from @pavoljuhas
mhucka 650881b
Apply suggestion from @pavoljuhas
mhucka 5433e1f
Address flaws pointed out in code review
mhucka ce42e1a
Merge branch 'main' into mh-add-check-all
mhucka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed 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 | ||
| # | ||
| # https://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. | ||
|
|
||
| # Summary: run multiple checks on the OpenFermion code base. | ||
| # This is modeled in part on Cirq's check/all script. | ||
|
|
||
| declare -r usage="\ | ||
| Usage: ${0##*/} [--help] [--only-changed-files] [--apply-format-changes] [BASE_REV] | ||
|
|
||
| If the first argument given on the command line is the option --help or -h, | ||
| this program prints usage information and then exits. | ||
|
|
||
| With no arguments, this runs multiple checks on the code base. These tests | ||
| are based on the programs in the checks/ subdirectory. | ||
|
|
||
| If the option --no-coverage is specified, check/pytest will be run instead of | ||
| check/pytest-and-incremental-coverage. | ||
|
|
||
| If --apply-format-changes is specified, the flag --apply will be passed to | ||
| check/format-incremental to apply the format changes suggested by the | ||
| formatter. | ||
|
|
||
| You can specify a base git revision to compare against (i.e., to use when | ||
| determining whether or not a file is considered to have changed). If given, | ||
| the argument BASE_REV is passed on to tests that can use it, such as | ||
| check/pytest-and-incremental-coverage." | ||
|
|
||
| set -eo pipefail -o errtrace | ||
| shopt -s inherit_errexit | ||
|
|
||
| # Get the working directory to the repo root. | ||
| thisdir=$(dirname "${BASH_SOURCE[0]:?}") || exit $? | ||
| repo_dir=$(git -C "${thisdir}" rev-parse --show-toplevel) || exit $? | ||
| cd "${repo_dir}" || exit $? | ||
mhucka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| function error() { | ||
| echo >&2 "ERROR: ${*}" | ||
| } | ||
|
|
||
| # ~~~~ Parse the CLI arguments and gather some data ~~~~ | ||
|
|
||
| declare rev | ||
| declare apply_arg | ||
| declare only_changed | ||
mhucka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for arg in "$@"; do | ||
| case "${arg}" in | ||
| -h | --help) | ||
| echo "${usage}" | ||
| exit 0 | ||
| ;; | ||
| --apply-format-changes) | ||
| apply_arg="--apply" | ||
| shift | ||
| ;; | ||
| --only-changed-files) | ||
| only_changed="true" | ||
| shift | ||
| ;; | ||
| -*) | ||
| if [[ -n "${rev}" ]]; then | ||
| error "Invalid arguments." | ||
| echo "${usage}" | ||
| exit 1 | ||
| fi | ||
mhucka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ;; | ||
| *) | ||
| if [ "$(git cat-file -t "${arg}" 2> /dev/null)" != "commit" ]; then | ||
| error "No revision '${arg}'" | ||
| exit 1 | ||
| fi | ||
| rev="${arg}" | ||
mhucka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| # ~~~~ Run the tests ~~~~ | ||
|
|
||
| declare -a errors | ||
| declare program | ||
mhucka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| function run() { | ||
| local -r program="$1" | ||
| echo "Running $program ..." | ||
| $program || errors+=( "${program} failed" ) | ||
| echo | ||
mhucka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if [[ -n "${only_changed}" ]]; then | ||
| run "check/format-incremental ${rev} ${apply_arg}" | ||
| run "check/pylint-changed-files ${rev}" | ||
mhucka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| else | ||
| run "check/format-incremental ${rev} ${apply_arg} --all" | ||
| run "check/pylint" | ||
| fi | ||
| run "check/mypy" | ||
| run "check/pytest-and-incremental-coverage ${rev}" | ||
| run "check/shellcheck" | ||
|
|
||
| # ~~~~ Summarize the results and exit with a status code ~~~~ | ||
|
|
||
| declare exit_code=0 | ||
| echo | ||
| echo "Done." | ||
| if [[ "${#errors[@]}" == 0 ]]; then | ||
| echo "All checks passed." | ||
| else | ||
| error "Some checks failed." | ||
| printf " %s\n" "${errors[@]}" | ||
| exit_code=1 | ||
| fi | ||
|
|
||
| exit "${exit_code}" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.