c-parsons | 166ff5e | 2019-09-11 12:04:15 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # Copyright 2019 The Bazel Authors. All rights reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | # Renerates most Stardoc golden files for Stardoc golden tests. |
| 17 | # |
| 18 | # When run, every golden file which is changed as a result of this script should |
| 19 | # be manually examined and *heavily* scrutinized, as this usually indicates a large |
| 20 | # in-place change of core rendering functionality of Stardoc. |
| 21 | |
| 22 | set -eu |
| 23 | |
Alexandre Rostovtsev | f8fab82 | 2023-07-24 21:43:33 -0400 | [diff] [blame] | 24 | function run_buildozer () { |
| 25 | # buildozer uses return code 3 to signal a no-op, so we can't use "set -e" |
| 26 | set +e |
| 27 | buildozer "$@" |
| 28 | ret=$? |
| 29 | set -e |
| 30 | if [[ $ret != 0 && $ret != 3 ]]; then |
| 31 | return $ret |
| 32 | fi |
| 33 | } |
| 34 | |
Alexandre Rostovtsev | aba1a01 | 2024-06-18 14:40:59 -0400 | [diff] [blame] | 35 | function update_non_manual_tests () { |
| 36 | echo "** Querying for non-manual tests..." |
| 37 | regenerate $(${BAZEL} query "kind(sh_binary, //test:all) - attr(tags, manual, //test:all)" | grep _regenerate) |
| 38 | } |
| 39 | |
| 40 | function update_manual_tests_with_tag () { |
| 41 | local manual_tag="$1"; shift |
Fabian Meumertzheim | 018dee5 | 2024-06-18 22:34:12 +0200 | [diff] [blame] | 42 | echo "** Querying for tests tagged \"${manual_tag}\", \"manual\" using 'USE_BAZEL_VERSION=${USE_BAZEL_VERSION:-} ${BAZEL}' $@ ..." |
| 43 | BUILD_FLAGS="$@" regenerate $(${BAZEL} query "attr(tags, ${manual_tag}, attr(tags, manual, kind(sh_binary, //test:all)))" | grep _regenerate) |
Alexandre Rostovtsev | aba1a01 | 2024-06-18 14:40:59 -0400 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | function regenerate () { |
| 47 | echo "** Regenerating and copying goldens..." |
Fabian Meumertzheim | 018dee5 | 2024-06-18 22:34:12 +0200 | [diff] [blame] | 48 | local run_cmd="run ${BUILD_FLAGS:-}" |
Alexandre Rostovtsev | aba1a01 | 2024-06-18 14:40:59 -0400 | [diff] [blame] | 49 | for regen_target in $@; do |
Fabian Meumertzheim | 018dee5 | 2024-06-18 22:34:12 +0200 | [diff] [blame] | 50 | if [[ -z ${USE_BAZEL_VERSION:-} ]]; then |
| 51 | echo "** Running '${BAZEL} ${run_cmd} ${regen_target}' ..." |
Alexandre Rostovtsev | aba1a01 | 2024-06-18 14:40:59 -0400 | [diff] [blame] | 52 | else |
Fabian Meumertzheim | 018dee5 | 2024-06-18 22:34:12 +0200 | [diff] [blame] | 53 | echo "** Running 'USE_BAZEL_VERSION=${USE_BAZEL_VERSION} ${BAZEL} ${run_cmd} ${regen_target}' BAZEL_BUILD_FLAGS ..." |
Alexandre Rostovtsev | aba1a01 | 2024-06-18 14:40:59 -0400 | [diff] [blame] | 54 | fi |
Fabian Meumertzheim | 018dee5 | 2024-06-18 22:34:12 +0200 | [diff] [blame] | 55 | ${BAZEL} ${run_cmd} "${regen_target}" |
Alexandre Rostovtsev | aba1a01 | 2024-06-18 14:40:59 -0400 | [diff] [blame] | 56 | done |
| 57 | } |
| 58 | |
Alexandre Rostovtsev | f8fab82 | 2023-07-24 21:43:33 -0400 | [diff] [blame] | 59 | # Allow users to override the bazel command with e.g. bazelisk. |
Alexandre Rostovtsev | aba1a01 | 2024-06-18 14:40:59 -0400 | [diff] [blame] | 60 | : "${BAZEL:=bazelisk}" |
Alexandre Rostovtsev | f8fab82 | 2023-07-24 21:43:33 -0400 | [diff] [blame] | 61 | |
Alexandre Rostovtsev | aba1a01 | 2024-06-18 14:40:59 -0400 | [diff] [blame] | 62 | update_non_manual_tests |
Fabian Meumertzheim | 018dee5 | 2024-06-18 22:34:12 +0200 | [diff] [blame] | 63 | update_manual_tests_with_tag "noenable_bzlmod" --noenable_bzlmod |
Alexandre Rostovtsev | aba1a01 | 2024-06-18 14:40:59 -0400 | [diff] [blame] | 64 | USE_BAZEL_VERSION="7.2.0" update_manual_tests_with_tag "bazel_7_2" |
| 65 | USE_BAZEL_VERSION="8.0.0-pre.20240603.2" update_manual_tests_with_tag "bazel_8" |
Alexandre Rostovtsev | f8fab82 | 2023-07-24 21:43:33 -0400 | [diff] [blame] | 66 | |
c-parsons | 166ff5e | 2019-09-11 12:04:15 -0400 | [diff] [blame] | 67 | echo "** Files copied." |
| 68 | echo "Please note that not all golden files are correctly copied by this script." |
| 69 | echo "You may want to manually run:" |
| 70 | echo "" |
Alexandre Rostovtsev | f8fab82 | 2023-07-24 21:43:33 -0400 | [diff] [blame] | 71 | echo "${BAZEL} test //test:all" |
c-parsons | 166ff5e | 2019-09-11 12:04:15 -0400 | [diff] [blame] | 72 | echo "" |
| 73 | echo "...and manually update tests which are still broken." |