Skip to content

Commit

Permalink
fix: ensure release archive contains all required files (bazel-contri…
Browse files Browse the repository at this point in the history
…b#130)

- Add some missing files to the release archive.
- Create a separate test for bzlmod e2e testing.
- Add archive test to ensure that the archive contains everything needed
to run properly.

Related to bazelbuild/bazel-central-registry#519
Related to bazel-contrib#120.
  • Loading branch information
cgrindel committed Sep 27, 2023
1 parent e78db22 commit ce25a18
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .bcr/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ bcr_test_module:
name: "Run test module"
platform: ${{ platform }}
test_targets:
- "//examples:simple_test"
- "//bazel_integration_test/bzlmod/..."
14 changes: 10 additions & 4 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,23 @@ filegroup(
visibility = ["//:__subpackages__"],
)

# Provides the *.bazlerc files for the example workspace integration tests.
filegroup(
name = "all_files",
srcs = glob(["*"]),
visibility = ["//:__subpackages__"],
)

# This target collects all of the parent workspace files needed by the child workspaces.
filegroup(
name = "local_repository_files",
# Include every package that is required by the child workspaces.
srcs = [
"BUILD.bazel",
"MODULE.bazel",
"WORKSPACE",
":all_files",
":shared_bazelrc_files",
"//bazel_integration_test:all_files",
"//bazel_integration_test/bzlmod:all_files",
"//bazel_integration_test/private:all_files",
"//examples:all_files",
"//tools:all_files",
],
visibility = ["//:__subpackages__"],
Expand All @@ -77,6 +82,7 @@ test_suite(
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS,
tests = [
"//examples:integration_tests",
"//release:archive_test",
"//tests/params_tests:integration_tests",
"//tests/py_tests:integration_tests",
],
Expand Down
32 changes: 32 additions & 0 deletions bazel_integration_test/bzlmod/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")
load("//:bazel_versions.bzl", "CURRENT_BAZEL_VERSION")
load(
"//bazel_integration_test:defs.bzl",
"bazel_integration_test",
)

bzlformat_pkg(name = "bzlformat")

filegroup(
name = "all_files",
srcs = glob(["*"]),
visibility = ["//:__subpackages__"],
)

sh_binary(
name = "e2e_test_runner",
testonly = True,
srcs = ["e2e_test_runner.sh"],
deps = [
"@bazel_tools//tools/bash/runfiles",
"@cgrindel_bazel_starlib//shlib/lib:assertions",
],
)

# This test exists to be run as part of the BCR presubmit.
bazel_integration_test(
name = "e2e_test",
bazel_binaries = bazel_binaries,
bazel_version = CURRENT_BAZEL_VERSION,
# Override the default tags. Let this run with bazel test //...
tags = [],
test_runner = ":e2e_test_runner",
)
50 changes: 50 additions & 0 deletions bazel_integration_test/bzlmod/e2e_test_runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---


# MARK - Locate Deps

assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh
assertions_sh="$(rlocation "${assertions_sh_location}")" || \
(echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1)
source "${assertions_sh}"


# MARK - Process Args

bazel="${BIT_BAZEL_BINARY:-}"
workspace_dir="${BIT_WORKSPACE_DIR:-}"

# Process args
while (("$#")); do
case "${1}" in
*)
fail "Unrecognized argument. ${@}"
;;
esac
done

[[ -n "${bazel:-}" ]] || exit_with_msg "Must specify the location of the Bazel binary."
[[ -n "${workspace_dir:-}" ]] || exit_with_msg "Must specify the path of the workspace directory."


# MARK - Create a WORKSPACE

cd "${workspace_dir}"

# Create a WORKSPACE file
touch WORKSPACE

# Run Bazel info
info_out="$( "${bazel}" info release )"
assert_match "release " "${info_out}" "Expected a release stanza."
8 changes: 0 additions & 8 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,3 @@ test_suite(
),
visibility = ["//:__subpackages__"],
)

# We do not want to pull everything into the release archive. We just need the
# simple workspace.
filegroup(
name = "all_files",
srcs = glob(["simple/**"]),
visibility = ["//:__subpackages__"],
)
24 changes: 24 additions & 0 deletions release/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")
load(
Expand All @@ -9,6 +10,11 @@ load(
"release_archive",
"update_readme",
)
load("//:bazel_versions.bzl", "CURRENT_BAZEL_VERSION")
load(
"//bazel_integration_test:defs.bzl",
"bazel_integration_test",
)

bzlformat_pkg(name = "bzlformat")

Expand Down Expand Up @@ -55,3 +61,21 @@ build_test(
":archive_sha256",
],
)

sh_binary(
name = "archive_test_runner",
testonly = True,
srcs = ["archive_test_runner.sh"],
data = ["//release:archive"],
deps = [
"@bazel_tools//tools/bash/runfiles",
"@cgrindel_bazel_starlib//shlib/lib:assertions",
],
)

bazel_integration_test(
name = "archive_test",
bazel_binaries = bazel_binaries,
bazel_version = CURRENT_BAZEL_VERSION,
test_runner = ":archive_test_runner",
)
59 changes: 59 additions & 0 deletions release/archive_test_runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -o nounset -o pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
# shellcheck disable=SC1090
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -o errexit
# --- end runfiles.bash initialization v2 ---

# MARK - Locate Deps

assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh
assertions_sh="$(rlocation "${assertions_sh_location}")" || \
(echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1)
source "${assertions_sh}"

rules_bazel_integration_test_tar_gz_location=rules_bazel_integration_test/release/rules_bazel_integration_test.tar.gz
rules_bazel_integration_test_tar_gz="$(rlocation "${rules_bazel_integration_test_tar_gz_location}")" || \
(echo >&2 "Failed to locate ${rules_bazel_integration_test_tar_gz_location}" && exit 1)

# MARK - Process Args

bazel="${BIT_BAZEL_BINARY:-}"
workspace_dir="${BIT_WORKSPACE_DIR:-}"

# Process args
while (("$#")); do
case "${1}" in
*)
fail "Unrecognized argument. ${@}"
;;
esac
done

[[ -n "${bazel:-}" ]] || exit_with_msg "Must specify the location of the Bazel binary."
[[ -n "${workspace_dir:-}" ]] || exit_with_msg "Must specify the path of the workspace directory."

# MARK - Create a HOME directory

# Not sure why, but the download and extract for the Bazel binaries was
# experiencing a permission denied when trying to use the local repository
# cache.
home_dir="${PWD}/home"
mkdir -p "${home_dir}"
export HOME="${home_dir}"

# MARK - Create a WORKSPACE

# Extract the contents of the archive into the workspace directory
tar -xf "${rules_bazel_integration_test_tar_gz}" -C "${workspace_dir}"

# Test the extracted contents
cd "${workspace_dir}"
"${bazel}" test //bazel_integration_test/bzlmod/...

0 comments on commit ce25a18

Please sign in to comment.