Skip to content

Commit

Permalink
fix: only run bzltidy tests for a single Bazel version (#372)
Browse files Browse the repository at this point in the history
The `MODULE.bazel.lock` file can change between Bazel versions. Hence,
the `:tidy_modified` test can only pass on a single Bazel version. The
PR updates the test to work with 7.0.0.rc4.

Closes #371.
  • Loading branch information
cgrindel authored Nov 18, 2023
1 parent 16477c7 commit ab1270e
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 60 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,10 @@ jobs:
- test: '@@//tests/bzlrelease_tests/tools_tests:generate_workspace_snippet_test'
runner: ubuntu-22.04
enable_bzlmod: true
- test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_.bazelversion'
- test: '@@//tests/bzltidy_tests:tidy_all_test'
runner: ubuntu-22.04
enable_bzlmod: true
- test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_.bazelversion'
runner: macos-13
enable_bzlmod: true
- test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_6_4_0'
runner: ubuntu-22.04
enable_bzlmod: true
- test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_6_4_0'
- test: '@@//tests/bzltidy_tests:tidy_all_test'
runner: macos-13
enable_bzlmod: true
- test: '@@//tests/shlib_tests/lib_tests/git_tests:git_integration_test'
Expand Down
18 changes: 9 additions & 9 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ load(
"bzlformat_pkg",
)
load("//bzltidy:defs.bzl", "tidy", "tidy_all")
load("//ci:defs.bzl", "ci_workflow")
load("//shlib/rules:execute_binary.bzl", "execute_binary")
load("//tests:integration_test_common.bzl", "INTEGRATION_TEST_TAGS")
load("//updatesrc:defs.bzl", "updatesrc_update_all")
Expand Down Expand Up @@ -238,14 +237,15 @@ test_suite(
visibility = ["//:__subpackages__"],
)

ci_workflow(
name = "ci_workflow",
test_params = [
"{}:all_test_params".format(pkg)
for pkg in _INTEGRATION_TEST_PKGS
],
workflow_yml = ".github/workflows/ci.yml",
)
# GH368: Enable when this is generating the proper output
# ci_workflow(
# name = "ci_workflow",
# test_params = [
# "{}:all_test_params".format(pkg)
# for pkg in _INTEGRATION_TEST_PKGS
# ],
# workflow_yml = ".github/workflows/ci.yml",
# )

bzl_library(
name = "deps",
Expand Down
22 changes: 9 additions & 13 deletions tests/bzltidy_tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
load(
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl",
"bazel_integration_tests",
"bazel_integration_test",
"integration_test_utils",
)
load("//bzlformat:defs.bzl", "bzlformat_pkg")
Expand All @@ -25,11 +25,15 @@ sh_binary(
],
)

bazel_integration_tests(
# NOTE: The MODULE.bazel.lock file can change between Bazel versions. In other
# words, the checked-in file can only be correct for a single version. Hence,
# we will only run the integration test for the current Bazel version.

bazel_integration_test(
name = "tidy_all_test",
timeout = "eternal",
bazel_binaries = bazel_binaries,
bazel_versions = bazel_binaries.versions.all,
bazel_version = bazel_binaries.versions.current,
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS + [
# Avoid file permssion error when using disk and repository cache after
# 7.0.0rc2 upgrade.
Expand All @@ -50,22 +54,14 @@ bazel_integration_tests(
test_suite(
name = "smoke_integration_tests",
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS,
tests = [
integration_test_utils.bazel_integration_test_name(
":tidy_all_test",
bazel_binaries.versions.current,
),
],
tests = [":tidy_all_test"],
visibility = ["//:__subpackages__"],
)

test_suite(
name = "all_integration_tests",
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS,
tests = integration_test_utils.bazel_integration_test_names(
":tidy_all_test",
bazel_binaries.versions.all,
),
tests = [":tidy_all_test"],
visibility = ["//:__subpackages__"],
)

Expand Down
14 changes: 14 additions & 0 deletions tests/bzltidy_tests/tidy_all_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ revert_changes() {
git clean -f
}

dump_modified_files() {
local title="${1}"
shift
if [[ $# -eq 0 ]]; then
return 0
fi
echo >&2 "${title}"
while (("$#")); do
echo >&2 " ${1}"
shift 1
done
}

# MARK - Initialize Important Variables

bazel="${BIT_BAZEL_BINARY:-}"
Expand Down Expand Up @@ -77,6 +90,7 @@ tidy_out_files=()
while IFS=$'\n' read -r line; do tidy_out_files+=("$line"); done < <(
find_tidy_out_files "${scratch_dir}"
)
dump_modified_files "Modified files for ${assert_msg}" "${tidy_out_files[@]:-}"
assert_equal 0 ${#tidy_out_files[@]} "${assert_msg}"
assert_match "${output_prefix_regex}"\ No\ workspaces\ to\ tidy\. "${output}" "${assert_msg}"

Expand Down
20 changes: 10 additions & 10 deletions tests/bzltidy_tests/workspace/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ab1270e

Please sign in to comment.