diff --git a/.bazelrc b/.bazelrc index 15df5cb2..e15d307f 100644 --- a/.bazelrc +++ b/.bazelrc @@ -3,8 +3,8 @@ # This lets us glob() up all the files inside the examples to make them inputs to tests # (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it) # To update these lines, run `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`. -build --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/bzlmod_e2e,examples/bzlmod_e2e/header,examples/bzlmod_e2e/mockascript,examples/bzlmod_e2e/mockascript/internal,examples/bzlmod_e2e/srcs/Bar,examples/bzlmod_e2e/srcs/Foo,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/bzltidy_tests/workspace,tests/bzltidy_tests/workspace/child_workspaces/bar,tests/bzltidy_tests/workspace/child_workspaces/foo,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters -query --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/bzlmod_e2e,examples/bzlmod_e2e/header,examples/bzlmod_e2e/mockascript,examples/bzlmod_e2e/mockascript/internal,examples/bzlmod_e2e/srcs/Bar,examples/bzlmod_e2e/srcs/Foo,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/bzltidy_tests/workspace,tests/bzltidy_tests/workspace/child_workspaces/bar,tests/bzltidy_tests/workspace/child_workspaces/foo,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters +build --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/bzlmod_e2e,examples/bzlmod_e2e/header,examples/bzlmod_e2e/mockascript,examples/bzlmod_e2e/mockascript/internal,examples/bzlmod_e2e/srcs/Bar,examples/bzlmod_e2e/srcs/Foo,examples/markdown/simple,examples/markdown/simple/bar,examples/tools/workspace,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/bzltidy_tests/workspace,tests/bzltidy_tests/workspace/child_workspaces/bar,tests/bzltidy_tests/workspace/child_workspaces/foo,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters +query --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/bzlmod_e2e,examples/bzlmod_e2e/header,examples/bzlmod_e2e/mockascript,examples/bzlmod_e2e/mockascript/internal,examples/bzlmod_e2e/srcs/Bar,examples/bzlmod_e2e/srcs/Foo,examples/markdown/simple,examples/markdown/simple/bar,examples/tools/workspace,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/bzltidy_tests/workspace,tests/bzltidy_tests/workspace/child_workspaces/bar,tests/bzltidy_tests/workspace/child_workspaces/foo,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters # Import Shared settings import %workspace%/shared.bazelrc diff --git a/.bazelversion b/.bazelversion index ae9a76b9..6da4de57 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -8.0.0 +8.4.1 diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml index 816347ba..964ae9e0 100644 --- a/.bcr/presubmit.yml +++ b/.bcr/presubmit.yml @@ -2,7 +2,7 @@ bcr_test_module: module_path: "examples/bzlmod_e2e" matrix: platform: ["macos", "ubuntu2004"] - bazel: ["8.0.0"] + bazel: ["8.1.1"] tasks: run_tests: name: "Run test module" diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..298125ea --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +# Configure shfmt (https://github.com/patrickvane/shfmt) + +[*.sh] +indent_style = space +indent_size = 2 +case_indent = true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eeefba7f..e0bf6de6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ concurrency: cancel-in-progress: true jobs: all_ci_tests: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 needs: - tidy_and_test_matrix - integration_test_matrix @@ -38,22 +38,16 @@ jobs: - test: '@@//examples/bzlformat:simple_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - - test: '@@//examples/bzlformat:simple_test_bazel_last_green' - runner: ubuntu-22.04 - enable_bzlmod: true - - test: '@@//examples/bzlformat:simple_test_bazel_last_green' - runner: macos-13 - enable_bzlmod: true - test: '@@//examples/markdown:simple_test_bazel_.bazelversion' runner: ubuntu-22.04 enable_bzlmod: true - test: '@@//examples/markdown:simple_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - - test: '@@//examples/markdown:simple_test_bazel_last_green' + - test: '@@//examples/tools:tools_test_bazel_.bazelversion' runner: ubuntu-22.04 enable_bzlmod: true - - test: '@@//examples/markdown:simple_test_bazel_last_green' + - test: '@@//examples/tools:tools_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - test: '@@//examples/updatesrc:simple_test_bazel_.bazelversion' @@ -62,36 +56,18 @@ jobs: - test: '@@//examples/updatesrc:simple_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - - test: '@@//examples/updatesrc:simple_test_bazel_last_green' - runner: ubuntu-22.04 - enable_bzlmod: true - - test: '@@//examples/updatesrc:simple_test_bazel_last_green' - runner: macos-13 - enable_bzlmod: true - test: '@@//examples:bzlmod_e2e_test_bazel_.bazelversion' runner: ubuntu-22.04 enable_bzlmod: true - test: '@@//examples:bzlmod_e2e_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - - test: '@@//examples:bzlmod_e2e_test_bazel_last_green' - runner: ubuntu-22.04 - enable_bzlmod: true - - test: '@@//examples:bzlmod_e2e_test_bazel_last_green' - runner: macos-13 - enable_bzlmod: true - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_.bazelversion' runner: ubuntu-22.04 enable_bzlmod: true - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_last_green' - runner: ubuntu-22.04 - enable_bzlmod: true - - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_last_green' - runner: macos-13 - enable_bzlmod: true - test: '@@//tests/bzlrelease_tests/rules_tests/generate_release_notes_tests:generate_release_notes_test' runner: ubuntu-22.04 enable_bzlmod: true @@ -125,26 +101,23 @@ jobs: - test: '@@//tests/shlib_tests/lib_tests/github_tests:get_gh_auth_status_test' runner: ubuntu-22.04 enable_bzlmod: true - - test: '@@//tests/shlib_tests/lib_tests/github_tests:get_gh_changelog_test' + - test: '@@//tests/shlib_tests/lib_tests/github_tests:get_gh_changelog_organized_test' runner: ubuntu-22.04 enable_bzlmod: true - - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_.bazelversion' + - test: '@@//tests/shlib_tests/lib_tests/github_tests:get_gh_changelog_test' runner: ubuntu-22.04 enable_bzlmod: true - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_.bazelversion' - runner: macos-13 - enable_bzlmod: true - - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_last_green' runner: ubuntu-22.04 enable_bzlmod: true - - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_last_green' + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true runs-on: ${{ matrix.runner }} env: CC: clang steps: - - uses: actions/checkout@cbb722410c2e876e24abbe8de2cc27693e501dcb + - uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 - uses: cgrindel/gha_set_up_bazel@v1 with: bazel_disk_cache_dir: "" @@ -170,7 +143,7 @@ jobs: - ubuntu-22.04 runs-on: ${{ matrix.runner }} steps: - - uses: actions/checkout@cbb722410c2e876e24abbe8de2cc27693e501dcb + - uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 - uses: cgrindel/gha_set_up_bazel@v1 with: bazel_disk_cache_dir: "" diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 123157af..34eff6f9 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -33,7 +33,7 @@ jobs: CC: clang steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4 - uses: cgrindel/gha_set_up_bazel@v1 with: repo_name: bazel-starlib diff --git a/BUILD.bazel b/BUILD.bazel index 6b0968f5..fdfba8fa 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -44,6 +44,12 @@ bzlformat_pkg(name = "bzlformat") bzlformat_missing_pkgs(name = "bzlformat_missing_pkgs") +# MARK: - Format using rules_lint + +alias( + name = "format", + actual = "//tools/format", +) # MARK: - Update Source Files updatesrc_update_all(name = "update_all") @@ -61,6 +67,7 @@ tidy( ":go_mod_tidy", ":gazelle_update_repos", ":update_build_files", + ":format", ], ) @@ -169,6 +176,9 @@ _RUNTIME_PKGS = [ "//shlib/rules", "//shlib/rules/private", "//shlib/tools", + "//tools/gh", + "//tools/git", + "//tools/tar", "//updatesrc", "//updatesrc/private", ] @@ -207,6 +217,7 @@ _INTEGRATION_TEST_PKGS = [ "//examples/bzlformat", "//examples/markdown", "//examples/updatesrc", + "//examples/tools", "//tests/bzlformat_tests/tools_tests/missing_pkgs_tests", "//tests/bzlrelease_tests/rules_tests/generate_release_notes_tests", "//tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests", diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..7d9c7ddb --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,156 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this +repository. + +## Overview + +Bazel Starlib is a collection of projects containing rulesets and libraries for Bazel projects. +The repository is organized as a monorepo with multiple related Bazel projects: + +- **bazeldoc**: Generate Starlark documentation using Bazel Stardoc +- **bzlformat**: Format Bazel Starlark files using Buildifier +- **bzllib**: Collection of Starlark libraries +- **bzlrelease**: Automate release generation using GitHub Actions +- **bzltidy**: Collect Bazel actions to keep source files up-to-date +- **markdown**: Maintain markdown files +- **shlib**: Shell libraries for implementing binaries, libraries, and tests +- **updatesrc**: Copy files from Bazel output directories to workspace + +## Common Commands + +### Development Workflow + +```bash +# Quick source file updates (most common during development) +bazel run //:update_files + +# Full tidy operation (runs formatting, updates source files) +bazel run //:tidy + +# Format all code using rules_lint +bazel run //:format + +# Update all generated source files +bazel run //:update_all + +# Tidy all child workspaces +bazel run //:tidy_all + +# Tidy only modified workspaces +bazel run //:tidy_modified +``` + +### Golang Dependencies + +```bash +# Add a new Go dependency +bazel run @io_bazel_rules_go//go -- github.com/sweet/go_pkg + +# Update go.mod and Bazel files +bazel run //:go_mod_tidy +bazel run //:gazelle_update_repos +bazel run //:update_build_files +``` + +### Formatting and Linting + +```bash +# Format all source files +bazel run //:format + +# Find missing bzlformat packages +bazel run //:bzlformat_missing_pkgs + +# Fix missing bzlformat packages +bazel run //:bzlformat_missing_pkgs_fix +``` + +### Testing + +```bash +# Run integration tests (smoke tests) +bazel test //:smoke_integration_tests + +# Run all integration tests +bazel test //:all_integration_tests + +# Run with CI configuration +bazel test --config=ci //... +``` + +### Build Configuration + +```bash +# Build with remote cache +bazel build --config=cache //... + +# Build without any caches +bazel build --config=no_cache //... +``` + +## Architecture + +### Module Structure + +Each project follows a consistent structure: + +- `defs.bzl`: Public API exports +- `private/`: Internal implementation files +- `tools/`: Executable scripts and binaries +- `README.md`: Project-specific documentation + +### Key Build Patterns + +**Bzlmod Support**: The repository uses Bzlmod with `MODULE.bazel` as the primary dependency +management system, with legacy `WORKSPACE` support maintained. + +**Integration Testing**: Extensive integration test infrastructure using +`rules_bazel_integration_test` with child workspaces in `/examples/` and `/tests/`. + +**Code Generation**: Many projects generate documentation, build files, and other artifacts +that need to be kept in sync using the `updatesrc` system. + +**Shell Library Pattern**: The `shlib` project provides reusable shell functions following a +library loading pattern with `cgrindel_bazel_shlib_lib_*_loaded()` functions. + +### Toolchain Integration + +- **Git Toolchain**: Custom git toolchain via `//tools/git` +- **Gazelle**: Automated BUILD file generation for Go code +- **Buildifier**: Starlark file formatting and linting +- **Stardoc**: Documentation generation for Starlark rules + +### Configuration Files + +- `shared.bazelrc`: Common Bazel configurations (bzlmod, caching, error reporting) +- `ci.bazelrc`: CI-specific settings (no color, detailed test output) +- `.bazelversion`: Specifies required Bazel version +- `go.mod`/`go.sum`: Go module dependencies for Go-based tools + +## Development Notes + +### File Organization + +- `/doc/`: Generated API documentation for all projects +- `/examples/`: Example workspaces demonstrating usage +- `/tests/`: Integration and unit tests +- `/tools/`: Shared tooling (git, gh, tar, format) +- `/ci/`: CI workflow generation utilities + +### Release Process + +Releases are automated through GitHub Actions using the `bzlrelease` system, which: + +- Generates release archives +- Updates README with workspace snippets +- Creates GitHub releases with proper versioning + +### Shell Script Standards + +All shell scripts follow these conventions: + +- Shebang: `#!/usr/bin/env bash` +- Error handling: `set -o errexit -o nounset -o pipefail` +- 2-space indentation +- Use `shfmt -i 2 -ci -bn` for formatting diff --git a/MODULE.bazel b/MODULE.bazel index cd12ae46..02dd641b 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -4,33 +4,49 @@ module( bazel_compatibility = [">=6.1.0"], ) +local_git_ext = use_extension("//tools/git:extensions.bzl", "local_git_ext") +use_repo(local_git_ext, "bazel_starlib_git_toolchains") + +register_toolchains( + "@bazel_starlib_git_toolchains//:local_git_toolchain", +) + # MARK: - Runtime Dependencies bazel_dep( name = "rules_go", - version = "0.50.1", + version = "0.55.1", repo_name = "io_bazel_rules_go", ) bazel_dep( name = "gazelle", - version = "0.40.0", + version = "0.44.0", repo_name = "bazel_gazelle", ) bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep( name = "stardoc", - version = "0.7.2", + version = "0.8.0", repo_name = "io_bazel_stardoc", ) bazel_dep( name = "buildifier_prebuilt", version = "7.3.1", ) -bazel_dep(name = "platforms", version = "0.0.10") -bazel_dep(name = "rules_shell", version = "0.3.0") +bazel_dep(name = "platforms", version = "0.0.11") +bazel_dep(name = "rules_shell", version = "0.5.0") +bazel_dep(name = "rules_multitool", version = "1.0.0") +bazel_dep(name = "aspect_bazel_lib", version = "2.19.4") + +multitool = use_extension( + "@rules_multitool//multitool:extension.bzl", + "multitool", +) +multitool.hub(lockfile = "//tools/gh:multitool.lock.json") +use_repo(multitool, "multitool") go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk") -go_sdk.download(version = "1.23.3") +go_sdk.download(version = "1.23.5") go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") go_deps.from_file(go_mod = "//:go.mod") @@ -51,9 +67,10 @@ bazel_dep( ) bazel_dep( name = "rules_bazel_integration_test", - version = "0.31.0", + version = "0.32.0", dev_dependency = True, ) +bazel_dep(name = "aspect_rules_lint", version = "1.5.1", dev_dependency = True) bazel_binaries = use_extension( "@rules_bazel_integration_test//:extensions.bzl", @@ -61,11 +78,14 @@ bazel_binaries = use_extension( dev_dependency = True, ) bazel_binaries.download(version_file = "//:.bazelversion") -bazel_binaries.download(version = "last_green") + +# GH525: Enable once archive extraction regression is fixed. +# bazel_binaries.download(version = "last_green") use_repo( bazel_binaries, "bazel_binaries", "bazel_binaries_bazelisk", "build_bazel_bazel_.bazelversion", - "build_bazel_bazel_last_green", + # GH525: Enable once archive extraction regression is fixed. + # "build_bazel_bazel_last_green", ) diff --git a/README.md b/README.md index 3874c982..4362ea6b 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ how-to links above and review the [the generated documentation](/doc/). ```python -bazel_dep(name = "cgrindel_bazel_starlib", version = "0.22.0") +bazel_dep(name = "cgrindel_bazel_starlib", version = "0.27.0") ``` @@ -47,9 +47,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "cgrindel_bazel_starlib", - sha256 = "4511eb49dfec9a8e796de79a7af051e062ef07795d4f8939a42553742d7520fe", + sha256 = "53e77f9b0cea589b4ca6dfb169ce5839aa61d6d56f0773d9bbd63b5fa8c1fff7", urls = [ - "https://github.com/cgrindel/bazel-starlib/releases/download/v0.22.0/bazel-starlib.v0.22.0.tar.gz", + "https://github.com/cgrindel/bazel-starlib/releases/download/v0.27.0/bazel-starlib.v0.27.0.tar.gz", ], ) diff --git a/bzlformat/tools/buildifier.sh b/bzlformat/tools/buildifier.sh index 2cc460da..80970a6c 100755 --- a/bzlformat/tools/buildifier.sh +++ b/bzlformat/tools/buildifier.sh @@ -2,31 +2,38 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/fail.sh source "${fail_sh}" arrays_sh_location=cgrindel_bazel_starlib/shlib/lib/arrays.sh -arrays_sh="$(rlocation "${arrays_sh_location}")" || \ +arrays_sh="$(rlocation "${arrays_sh_location}")" || (echo >&2 "Failed to locate ${arrays_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/arrays.sh source "${arrays_sh}" buildifier_location=buildifier_prebuilt/buildifier/buildifier -buildifier="$(rlocation "${buildifier_location}")" || \ +buildifier="$(rlocation "${buildifier_location}")" || (echo >&2 "Failed to locate ${buildifier_location}" && exit 1) # MARK - Process Args @@ -35,7 +42,7 @@ buildifier="$(rlocation "${buildifier_location}")" || \ # off - Do not lint # warn - Report lint issues. # fix = Attempt to fix lint issues. -lint_modes=( off warn fix ) +lint_modes=(off warn fix) lint_mode="off" warnings="all" @@ -50,7 +57,7 @@ Usage: ${utility} [OPTION]... Options: - --lint_mode The buildifier lint mode: $( join_by ", " "${lint_modes[@]}" ) (default: ${lint_mode}) + --lint_mode The buildifier lint mode: $(join_by ", " "${lint_modes[@]}") (default: ${lint_mode}) --warnings A comma-separated warnings used in the lint mode or "all" (default: ${warnings}) A path to a Starlark file A path where to write the output from buildifier @@ -60,24 +67,24 @@ EOF args=() while (("$#")); do case "${1}" in - "--help") - show_usage - ;; - "--lint_mode") - lint_mode="${2}" - shift 2 - ;; - "--warnings") - warnings="${2}" - shift 2 - ;; - --*) - usage_error "Unexpected option. ${1}" - ;; - *) - args+=("${1}") - shift 1 - ;; + "--help") + show_usage + ;; + "--lint_mode") + lint_mode="${2}" + shift 2 + ;; + "--warnings") + warnings="${2}" + shift 2 + ;; + --*) + usage_error "Unexpected option. ${1}" + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -85,37 +92,36 @@ done bzl_path="${args[0]}" [[ ${#args[@]} -gt 1 ]] && out_path="${args[1]}" -contains_item "${lint_mode}" "${lint_modes[@]}" || \ - usage_error "Invalid lint_mode (${lint_mode}). Expected to be one of the following: $( join_by ", " "${lint_modes[@]}" )." - +contains_item "${lint_mode}" "${lint_modes[@]}" || + usage_error "Invalid lint_mode (${lint_mode}). Expected to be one of the following: $(join_by ", " "${lint_modes[@]}")." # MARK - Execute Buildifier exec_buildifier() { local bzl_path="${1}" shift 1 - local buildifier_cmd=( "${buildifier}" "--path=${bzl_path}" ) - [[ ${#} -gt 0 ]] && buildifier_cmd+=( "${@}" ) + local buildifier_cmd=("${buildifier}" "--path=${bzl_path}") + [[ ${#} -gt 0 ]] && buildifier_cmd+=("${@}") "${buildifier_cmd[@]}" } -cat_cmd=( cat "${bzl_path}" ) +cat_cmd=(cat "${bzl_path}") -buildifier_cmd=( exec_buildifier "${bzl_path}" "--warnings=${warnings}" ) +buildifier_cmd=(exec_buildifier "${bzl_path}" "--warnings=${warnings}") case "${lint_mode}" in - "fix") - buildifier_cmd+=( "--lint=fix" ) - ;; - "warn") - buildifier_cmd+=( "--lint=warn" ) - ;; - "off") - buildifier_cmd+=( "--lint=off" ) - ;; +"fix") + buildifier_cmd+=("--lint=fix") + ;; +"warn") + buildifier_cmd+=("--lint=warn") + ;; +"off") + buildifier_cmd+=("--lint=off") + ;; esac if [[ -n "${out_path:-}" ]]; then - "${cat_cmd[@]}" | "${buildifier_cmd[@]}" > "${out_path}" + "${cat_cmd[@]}" | "${buildifier_cmd[@]}" >"${out_path}" else - "${cat_cmd[@]}" | "${buildifier_cmd[@]}" > /dev/null + "${cat_cmd[@]}" | "${buildifier_cmd[@]}" >/dev/null fi diff --git a/bzlformat/tools/missing_pkgs/common.sh b/bzlformat/tools/missing_pkgs/common.sh index 313d5372..184017b3 100644 --- a/bzlformat/tools/missing_pkgs/common.sh +++ b/bzlformat/tools/missing_pkgs/common.sh @@ -16,14 +16,13 @@ normalize_pkg() { # Strip a trailing slash # Make sure to add prefix (//) case "${pkg}" in - "//"*) - ;; - "/"*) - local pkg="/${pkg}" - ;; - *) - local pkg="//${pkg}" - ;; + "//"*) ;; + "/"*) + local pkg="/${pkg}" + ;; + *) + local pkg="//${pkg}" + ;; esac echo "${pkg}" } diff --git a/bzlformat/tools/missing_pkgs/find.sh b/bzlformat/tools/missing_pkgs/find.sh index d48deed6..1f3ba3aa 100755 --- a/bzlformat/tools/missing_pkgs/find.sh +++ b/bzlformat/tools/missing_pkgs/find.sh @@ -2,16 +2,23 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- -# Use the Bazel binary specified by the integration test. Otherise, fall back +# Use the Bazel binary specified by the integration test. Otherise, fall back # to bazel. bazel="${BIT_BAZEL_BINARY:-bazel}" @@ -20,14 +27,14 @@ arrays_lib="$(rlocation cgrindel_bazel_starlib/shlib/lib/arrays.sh)" source "${arrays_lib}" common_sh_location=cgrindel_bazel_starlib/bzlformat/tools/missing_pkgs/common.sh -common_sh="$(rlocation "${common_sh_location}")" || \ +common_sh="$(rlocation "${common_sh_location}")" || (echo >&2 "Failed to locate ${common_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/common.sh source "${common_sh}" query_for_pkgs() { local query="${1}" - # We need to add a prefix here (//). Otherwise, the root package would be an + # We need to add a prefix here (//). Otherwise, the root package would be an # empty string. Empty strings are easily lost in Bash. "${bazel}" query "${query}" --output package | sed -e 's|^|//|' } @@ -37,18 +44,18 @@ exclude_pkgs=() args=() while (("$#")); do case "${1}" in - "--exclude") - exclude_pkgs+=( "$(normalize_pkg "${2}")" ) - shift 2 - ;; - "--fail_on_missing_pkgs") - fail_on_missing_pkgs=true - shift 1 - ;; - *) - args+=("${1}") - shift 1 - ;; + "--exclude") + exclude_pkgs+=("$(normalize_pkg "${2}")") + shift 2 + ;; + "--fail_on_missing_pkgs") + fail_on_missing_pkgs=true + shift 1 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -66,9 +73,9 @@ while IFS=$'\n' read -r line; do pkgs_with_format+=("$line"); done < <( pkgs_missing_format=() if [[ "${#all_pkgs[@]}" -gt 0 ]]; then - for pkg in "${all_pkgs[@]}" ; do + for pkg in "${all_pkgs[@]}"; do if ! contains_item "${pkg}" "${pkgs_with_format[@]:-}" && ! contains_item "${pkg}" "${exclude_pkgs[@]:-}"; then - pkgs_missing_format+=( "${pkg}" ) + pkgs_missing_format+=("${pkg}") fi done fi @@ -82,4 +89,3 @@ if [[ ${#pkgs_missing_format[@]} -gt 0 ]]; then exit 1 fi fi - diff --git a/bzlformat/tools/missing_pkgs/fix.sh b/bzlformat/tools/missing_pkgs/fix.sh index 67f5f6ad..87c6fbbc 100755 --- a/bzlformat/tools/missing_pkgs/fix.sh +++ b/bzlformat/tools/missing_pkgs/fix.sh @@ -4,13 +4,20 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- arrays_lib="$(rlocation cgrindel_bazel_starlib/shlib/lib/arrays.sh)" @@ -18,7 +25,7 @@ arrays_lib="$(rlocation cgrindel_bazel_starlib/shlib/lib/arrays.sh)" source "${arrays_lib}" common_sh_location=cgrindel_bazel_starlib/bzlformat/tools/missing_pkgs/common.sh -common_sh="$(rlocation "${common_sh_location}")" || \ +common_sh="$(rlocation "${common_sh_location}")" || (echo >&2 "Failed to locate ${common_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/common.sh source "${common_sh}" @@ -27,29 +34,28 @@ source "${common_sh}" find_missing_pkgs_bin="$(rlocation cgrindel_bazel_starlib/bzlformat/tools/missing_pkgs/find.sh)" buildozer_location=buildifier_prebuilt/buildozer/buildozer -buildozer="$(rlocation "${buildozer_location}")" || \ +buildozer="$(rlocation "${buildozer_location}")" || (echo >&2 "Failed to locate ${buildozer_location}" && exit 1) exclude_pkgs=() args=() while (("$#")); do case "${1}" in - "--exclude") - exclude_pkgs+=( "$(normalize_pkg "${2}")" ) - shift 2 - ;; - *) - args+=("${1}") - shift 1 - ;; + "--exclude") + exclude_pkgs+=("$(normalize_pkg "${2}")") + shift 2 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done - cd "${BUILD_WORKSPACE_DIRECTORY}" find_args=() -for pkg in "${exclude_pkgs[@]:-}" ; do +for pkg in "${exclude_pkgs[@]:-}"; do find_args+=(--exclude "${pkg}") done missing_pkgs=() @@ -61,19 +67,19 @@ while IFS=$'\n' read -r line; do missing_pkgs+=("$line"); done < <( [[ ${#missing_pkgs[@]} -eq 0 ]] && echo "No missing package updates were found." && exit echo "Updating the following packages:" -for pkg in "${missing_pkgs[@]}" ; do +for pkg in "${missing_pkgs[@]}"; do echo "${pkg}" done buildozer_cmds=() -buildozer_cmds+=( 'fix movePackageToTop' ) -buildozer_cmds+=( 'new_load @cgrindel_bazel_starlib//bzlformat:defs.bzl bzlformat_pkg' ) -buildozer_cmds+=( 'new bzlformat_pkg bzlformat' ) -buildozer_cmds+=( 'fix unusedLoads' ) +buildozer_cmds+=('fix movePackageToTop') +buildozer_cmds+=('new_load @cgrindel_bazel_starlib//bzlformat:defs.bzl bzlformat_pkg') +buildozer_cmds+=('new bzlformat_pkg bzlformat') +buildozer_cmds+=('fix unusedLoads') # Execute the buildozer commands missing_pkgs_args=() -for pkg in "${missing_pkgs[@]}" ; do - missing_pkgs_args+=( "${pkg}:__pkg__" ) +for pkg in "${missing_pkgs[@]}"; do + missing_pkgs_args+=("${pkg}:__pkg__") done "${buildozer}" "${buildozer_cmds[@]}" "${missing_pkgs_args[@]}" diff --git a/bzlrelease/private/BUILD.bazel b/bzlrelease/private/BUILD.bazel index 64fca66e..c4f00e91 100644 --- a/bzlrelease/private/BUILD.bazel +++ b/bzlrelease/private/BUILD.bazel @@ -54,11 +54,12 @@ filegroup( ) bzl_library( - name = "hash_sha256", - srcs = ["hash_sha256.bzl"], + name = "release_archive", + srcs = ["release_archive.bzl"], + deps = ["//tools/tar:tar_toolchains"], ) bzl_library( - name = "release_archive", - srcs = ["release_archive.bzl"], + name = "hash_sha256", + srcs = ["hash_sha256.bzl"], ) diff --git a/bzlrelease/private/release_archive.bzl b/bzlrelease/private/release_archive.bzl index 04bc4859..2ac6933d 100644 --- a/bzlrelease/private/release_archive.bzl +++ b/bzlrelease/private/release_archive.bzl @@ -1,5 +1,7 @@ """Definition for `release_archive` rule.""" +load("//tools/tar:tar_toolchains.bzl", "tar_toolchains") + def _release_archive_impl(ctx): out_basename = ctx.attr.out if out_basename == "": @@ -18,21 +20,23 @@ def _release_archive_impl(ctx): content = file_list_args, ) - # Create the archive + bsdtar = ctx.toolchains[tar_toolchains.type] + args = ctx.actions.args() - args.add(out) - args.add(file_list_out) - ctx.actions.run_shell( + args.add("-f", out) + args.add_all(["-h", "-c", "-z"]) + args.add("-T", file_list_out) + ctx.actions.run( outputs = [out], - inputs = [file_list_out] + ctx.files.srcs, + inputs = depset( + direct = [file_list_out] + ctx.files.srcs, + transitive = [bsdtar.default.files], + ), arguments = [args], - command = """\ -archive="$1" -file_list="$2" -shift 1 -tar 2>/dev/null -hczvf "$archive" -T "${file_list}" -""", + executable = bsdtar.tarinfo.binary, + toolchain = tar_toolchains.type, ) + return DefaultInfo( files = depset([out]), runfiles = ctx.runfiles(files = [out]), @@ -53,6 +57,7 @@ release_archive = rule( mandatory = True, ), }, + toolchains = [tar_toolchains.type], doc = """\ Create a source release archive. diff --git a/bzlrelease/tools/BUILD.bazel b/bzlrelease/tools/BUILD.bazel index ea348ea4..5e21b008 100644 --- a/bzlrelease/tools/BUILD.bazel +++ b/bzlrelease/tools/BUILD.bazel @@ -33,6 +33,9 @@ sh_binary( sh_binary( name = "generate_git_archive", srcs = ["generate_git_archive.sh"], + data = [ + "//tools/git", + ], visibility = ["//visibility:public"], deps = [ "//shlib/lib:env", @@ -72,6 +75,9 @@ sh_binary( sh_binary( name = "create_release_tag", srcs = ["create_release_tag.sh"], + data = [ + "//tools/git", + ], visibility = ["//visibility:public"], deps = [ "//shlib/lib:env", diff --git a/bzlrelease/tools/create_release.sh b/bzlrelease/tools/create_release.sh index 194adb03..8cb739ea 100755 --- a/bzlrelease/tools/create_release.sh +++ b/bzlrelease/tools/create_release.sh @@ -2,47 +2,50 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/fail.sh source "${fail_sh}" env_sh_location=cgrindel_bazel_starlib/shlib/lib/env.sh -env_sh="$(rlocation "${env_sh_location}")" || \ +env_sh="$(rlocation "${env_sh_location}")" || (echo >&2 "Failed to locate ${env_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/env.sh source "${env_sh}" git_sh_location=cgrindel_bazel_starlib/shlib/lib/git.sh -git_sh="$(rlocation "${git_sh_location}")" || \ +git_sh="$(rlocation "${git_sh_location}")" || (echo >&2 "Failed to locate ${git_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/git.sh source "${git_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/github.sh source "${github_sh}" - # MARK - Check for Required Software -is_installed gh || fail "Could not find Github CLI (gh)." - - # MARK - Usage get_usage() { @@ -66,7 +69,6 @@ Options: EOF } - # MARK - Process Arguments reset_tag=false @@ -74,28 +76,28 @@ reset_tag=false args=() while (("$#")); do case "${1}" in - "--help") - show_usage - ;; - --workflow) - workflow_name="${2}" - shift 2 - ;; - --ref) - ref="${2}" - shift 2 - ;; - --reset_tag) - reset_tag=true - shift 1 - ;; - --*) - fail "Unrecognized flag. ${1}" - ;; - *) - args+=("${1}") - shift 1 - ;; + "--help") + show_usage + ;; + --workflow) + workflow_name="${2}" + shift 2 + ;; + --ref) + ref="${2}" + shift 2 + ;; + --reset_tag) + reset_tag=true + shift 1 + ;; + --*) + fail "Unrecognized flag. ${1}" + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -105,7 +107,6 @@ done tag="${args[0]}" is_valid_release_tag "${tag}" || fail "Invalid version tag. Expected it to start with 'v'." - # MARK - Run the workflow cd "${BUILD_WORKSPACE_DIRECTORY}" diff --git a/bzlrelease/tools/create_release_tag.sh b/bzlrelease/tools/create_release_tag.sh index c98ee1c6..4023128c 100755 --- a/bzlrelease/tools/create_release_tag.sh +++ b/bzlrelease/tools/create_release_tag.sh @@ -2,49 +2,48 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/fail.sh source "${fail_sh}" env_sh_location=cgrindel_bazel_starlib/shlib/lib/env.sh -env_sh="$(rlocation "${env_sh_location}")" || \ +env_sh="$(rlocation "${env_sh_location}")" || (echo >&2 "Failed to locate ${env_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/env.sh source "${env_sh}" git_sh_location=cgrindel_bazel_starlib/shlib/lib/git.sh -git_sh="$(rlocation "${git_sh_location}")" || \ +git_sh="$(rlocation "${git_sh_location}")" || (echo >&2 "Failed to locate ${git_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/git.sh source "${git_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/github.sh source "${github_sh}" - -# MARK - Check for Required Software - -required_software="Both git and Github CLI (gh) are required to run this utility." -is_installed gh || fail "Could not find Github CLI (gh)." "${required_software}" -is_installed git || fail "Could not find git." "${required_software}" - - # MARK - Process Args get_usage() { @@ -64,25 +63,25 @@ main_branch=main args=() while (("$#")); do case "${1}" in - "--help") - show_usage - ;; - --remote) - remote="${2}" - shift 2 - ;; - --branch) - main_branch="${2}" - shift 2 - ;; - --reset_tag) - reset_tag=true - shift 1 - ;; - *) - args+=("${1}") - shift 1 - ;; + "--help") + show_usage + ;; + --remote) + remote="${2}" + shift 2 + ;; + --branch) + main_branch="${2}" + shift 2 + ;; + --reset_tag) + reset_tag=true + shift 1 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -91,7 +90,6 @@ tag="${args[0]}" is_valid_release_tag "${tag}" || fail "Invalid version tag. Expected it to start with 'v'." - # MARK - Create the release cd "${BUILD_WORKSPACE_DIRECTORY}" @@ -111,7 +109,7 @@ git_tag_exists_on_remote "${tag}" "${remote}" && fail "This tag already exists o if git_tag_exists "${tag}"; then echo "The tag (${tag}) exists locally, but does not exist on origin." else - commit="$( get_git_commit_hash "${remote}/${main_branch}" )" + commit="$(get_git_commit_hash "${remote}/${main_branch}")" cat <<-EOF Creating release tag. Tag: ${tag} diff --git a/bzlrelease/tools/generate_gh_changelog.sh b/bzlrelease/tools/generate_gh_changelog.sh index 8958015a..6bbeac69 100755 --- a/bzlrelease/tools/generate_gh_changelog.sh +++ b/bzlrelease/tools/generate_gh_changelog.sh @@ -2,66 +2,66 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/fail.sh source "${fail_sh}" env_sh_location=cgrindel_bazel_starlib/shlib/lib/env.sh -env_sh="$(rlocation "${env_sh_location}")" || \ +env_sh="$(rlocation "${env_sh_location}")" || (echo >&2 "Failed to locate ${env_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/env.sh source "${env_sh}" git_sh_location=cgrindel_bazel_starlib/shlib/lib/git.sh -git_sh="$(rlocation "${git_sh_location}")" || \ +git_sh="$(rlocation "${git_sh_location}")" || (echo >&2 "Failed to locate ${git_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/git.sh source "${git_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/github.sh source "${github_sh}" - -# MARK - Check for Required Software - -is_installed gh || fail "Could not find Github CLI (gh)." -is_installed git || fail "Could not find git." - - # MARK - Process Arguments main_branch=main args=() while (("$#")); do case "${1}" in - "--previous_tag_name") - previous_tag_name="${2}" - shift 2 - ;; - "--output") - output_path="${2}" - shift 2 - ;; - *) - args+=("${1}") - shift 1 - ;; + "--previous_tag_name") + previous_tag_name="${2}" + shift 2 + ;; + "--output") + output_path="${2}" + shift 2 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -72,8 +72,8 @@ tag_name="${args[0]}" cd "${BUILD_WORKSPACE_DIRECTORY}" -repo_url="$( get_git_remote_url )" -is_github_repo_url "${repo_url}" || \ +repo_url="$(get_git_remote_url)" +is_github_repo_url "${repo_url}" || fail "The git repository's remote URL does not appear to be a Github URL. ${repo_url}" # Fetch the latest from origin @@ -84,17 +84,17 @@ fetch_latest_from_git_remote changelog_args=() changelog_args+=(--tag_name "${tag_name}") if ! git_tag_exists "${tag_name}"; then - last_commit_on_main="$( get_git_commit_hash "${remote}/${main_branch}" )" + last_commit_on_main="$(get_git_commit_hash "${remote}/${main_branch}")" changelog_args+=(--target_commitish "${last_commit_on_main}") fi [[ -z "${previous_tag_name:-}" ]] || changelog_args+=(--previous_tag_name "${previous_tag_name}") # Generate the changelog -changelog_md="$( get_gh_changelog "${changelog_args[@]}" )" +changelog_md="$(get_gh_changelog_organized "${changelog_args[@]}")" # Output the changelog if [[ -z "${output_path:-}" ]]; then echo "${changelog_md}" else - echo "${changelog_md}" > "${output_path}" + echo "${changelog_md}" >"${output_path}" fi diff --git a/bzlrelease/tools/generate_git_archive.sh b/bzlrelease/tools/generate_git_archive.sh index 3c1aa04c..7bc9a86f 100755 --- a/bzlrelease/tools/generate_git_archive.sh +++ b/bzlrelease/tools/generate_git_archive.sh @@ -9,42 +9,51 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/fail.sh source "${fail_sh}" env_sh_location=cgrindel_bazel_starlib/shlib/lib/env.sh -env_sh="$(rlocation "${env_sh_location}")" || \ +env_sh="$(rlocation "${env_sh_location}")" || (echo >&2 "Failed to locate ${env_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/env.sh source "${env_sh}" git_sh_location=cgrindel_bazel_starlib/shlib/lib/git.sh -git_sh="$(rlocation "${git_sh_location}")" || \ +git_sh="$(rlocation "${git_sh_location}")" || (echo >&2 "Failed to locate ${git_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/git.sh source "${git_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/github.sh source "${github_sh}" -is_installed git || fail "This utility requires git to be installed and in the path." +git_exe_location=cgrindel_bazel_starlib/tools/git/git.exe +git="$(rlocation "${git_exe_location}")" || + (echo >&2 "Failed to locate ${git_exe_location}" && exit 1) # MARK - Process Args @@ -55,38 +64,38 @@ compress=true args=() while (("$#")); do case "${1}" in - "--remote") - remote="${2}" - shift 2 - ;; - "--main") - main_branch="${2}" - shift 2 - ;; - "--repo") - repo="${2}" - shift 2 - ;; - "--tag_name") - tag_name="${2}" - shift 2 - ;; - "--prefix") - prefix="${2}" - shift 2 - ;; - "--nocompress") - compress=false - shift 1 - ;; - "--output") - output_path="${2}" - shift 2 - ;; - *) - args+=("${1}") - shift 1 - ;; + "--remote") + remote="${2}" + shift 2 + ;; + "--main") + main_branch="${2}" + shift 2 + ;; + "--repo") + repo="${2}" + shift 2 + ;; + "--tag_name") + tag_name="${2}" + shift 2 + ;; + "--prefix") + prefix="${2}" + shift 2 + ;; + "--nocompress") + compress=false + shift 1 + ;; + "--output") + output_path="${2}" + shift 2 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -103,29 +112,27 @@ fetch_latest_from_git_remote if [[ -z "${prefix:-}" ]]; then # Make sure that we have a repo name if [[ -z "${repo:-}" ]]; then - repo_url="$( get_git_remote_url )" - is_github_repo_url "${repo_url}" || \ + repo_url="$(get_git_remote_url)" + is_github_repo_url "${repo_url}" || fail "Could not figure out repo name. Please specify the repo name using the --repo flag." - repo="$( get_gh_repo_name "${repo_url}" )" + repo="$(get_gh_repo_name "${repo_url}")" fi prefix_suffix="${tag_name}" [[ "${prefix_suffix}" =~ ^v ]] && prefix_suffix="${prefix_suffix:1}" prefix="${repo}-${prefix_suffix}" fi - # Figure out which commit or tag to use if git_tag_exists "${tag_name}"; then commit_or_tag="${tag_name}" else # The tag does not exist. Assume that we are about to tag the code in the main branch. - commit_or_tag="$( get_git_commit_hash "${remote_name}/${main_branch}" )" + commit_or_tag="$(get_git_commit_hash "${remote_name}/${main_branch}")" fi - # Wrap the archive call create_archive() { - git archive --format=tar "--prefix=${prefix}/" "${commit_or_tag}" + "${git}" archive --format=tar "--prefix=${prefix}/" "${commit_or_tag}" } # Compress @@ -144,5 +151,5 @@ fi if [[ -z "${output_path:-}" ]]; then do_archive else - do_archive > "${output_path}" + do_archive >"${output_path}" fi diff --git a/bzlrelease/tools/generate_module_snippet.sh b/bzlrelease/tools/generate_module_snippet.sh index b85f3913..bc7ac099 100755 --- a/bzlrelease/tools/generate_module_snippet.sh +++ b/bzlrelease/tools/generate_module_snippet.sh @@ -1,23 +1,30 @@ #!/usr/bin/env bash -# Generates a Bazel module snippet suitable for inclusion in a MODULE.bazel +# Generates a Bazel module snippet suitable for inclusion in a MODULE.bazel # file. # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/fail.sh source "${fail_sh}" @@ -28,26 +35,26 @@ dev_dependency="false" args=() while (("$#")); do case "${1}" in - "--module_name") - module_name="${2}" - shift 2 - ;; - "--version") - version="${2}" - shift 2 - ;; - "--output") - output_path="${2}" - shift 2 - ;; - "--dev_dependency") - dev_dependency="true" - shift 1 - ;; - *) - args+=("${1}") - shift 1 - ;; + "--module_name") + module_name="${2}" + shift 2 + ;; + "--version") + version="${2}" + shift 2 + ;; + "--output") + output_path="${2}" + shift 2 + ;; + "--dev_dependency") + dev_dependency="true" + shift 1 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -65,23 +72,25 @@ fi # MARK - Generate the Snippet if [[ "${dev_dependency}" == "true" ]]; then - snippet="$(cat <<-EOF + snippet="$( + cat <<-EOF bazel_dep( name = "${module_name}", version = "${version}", dev_dependency = True, ) EOF -)" + )" else - snippet="$(cat <<-EOF + snippet="$( + cat <<-EOF bazel_dep(name = "${module_name}", version = "${version}") EOF -)" + )" fi - -snippet="$(cat <<-EOF +snippet="$( + cat <<-EOF \`\`\`python ${snippet} \`\`\` @@ -94,5 +103,5 @@ EOF if [[ -z "${output_path:-}" ]]; then echo "${snippet}" else - echo "${snippet}" > "${output_path}" + echo "${snippet}" >"${output_path}" fi diff --git a/bzlrelease/tools/generate_release_notes.sh b/bzlrelease/tools/generate_release_notes.sh index 70cb1e17..e6dd248b 100755 --- a/bzlrelease/tools/generate_release_notes.sh +++ b/bzlrelease/tools/generate_release_notes.sh @@ -2,25 +2,32 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/fail.sh source "${fail_sh}" generate_gh_changelog_sh_location=cgrindel_bazel_starlib/bzlrelease/tools/generate_gh_changelog.sh -generate_gh_changelog_sh="$(rlocation "${generate_gh_changelog_sh_location}")" || \ +generate_gh_changelog_sh="$(rlocation "${generate_gh_changelog_sh_location}")" || (echo >&2 "Failed to locate ${generate_gh_changelog_sh_location}" && exit 1) # MARK - Process Arguments @@ -30,35 +37,35 @@ starting_dir="${PWD}" args=() while (("$#")); do case "${1}" in - "--output") - output_path="${2}" - shift 2 - ;; - "--generate_workspace_snippet") - # If the input path is not absolute, then resolve it to be relative to - # the starting directory. We do this before we starting changing - # directories. - generate_workspace_snippet="${2}" - [[ "${generate_workspace_snippet}" =~ ^/ ]] || \ - generate_workspace_snippet="${starting_dir}/${generate_workspace_snippet}" - shift 2 - ;; - "--generate_module_snippet") - # If the input path is not absolute, then resolve it to be relative to - # the starting directory. We do this before we starting changing - # directories. - generate_module_snippet="${2}" - [[ "${generate_module_snippet}" =~ ^/ ]] || \ - generate_module_snippet="${starting_dir}/${generate_module_snippet}" - shift 2 - ;; - --*) - fail "Unrecognized flag ${1}." - ;; - *) - args+=("${1}") - shift 1 - ;; + "--output") + output_path="${2}" + shift 2 + ;; + "--generate_workspace_snippet") + # If the input path is not absolute, then resolve it to be relative to + # the starting directory. We do this before we starting changing + # directories. + generate_workspace_snippet="${2}" + [[ "${generate_workspace_snippet}" =~ ^/ ]] || + generate_workspace_snippet="${starting_dir}/${generate_workspace_snippet}" + shift 2 + ;; + "--generate_module_snippet") + # If the input path is not absolute, then resolve it to be relative to + # the starting directory. We do this before we starting changing + # directories. + generate_module_snippet="${2}" + [[ "${generate_module_snippet}" =~ ^/ ]] || + generate_module_snippet="${starting_dir}/${generate_module_snippet}" + shift 2 + ;; + --*) + fail "Unrecognized flag ${1}." + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -79,17 +86,18 @@ cd "${BUILD_WORKSPACE_DIRECTORY}" "that Github produces appears to be compatible with Linux implementations of gzip. Hence," \ "generating release notes on this OS may result in an incompatible SHA256 value." -changelog_md="$( "${generate_gh_changelog_sh}" "${tag_name}" )" +changelog_md="$("${generate_gh_changelog_sh}" "${tag_name}")" if [[ -n "${generate_workspace_snippet:-}" ]]; then - workspace_snippet="$( "${generate_workspace_snippet}" --tag "${tag_name}" )" + workspace_snippet="$("${generate_workspace_snippet}" --tag "${tag_name}")" fi if [[ -n "${generate_module_snippet:-}" ]]; then - module_snippet="$( "${generate_module_snippet}" --version "${tag_name}" )" + module_snippet="$("${generate_module_snippet}" --version "${tag_name}")" fi -release_notes_md="$(cat <<-EOF +release_notes_md="$( + cat <<-EOF ## What Has Changed ${changelog_md} @@ -97,30 +105,32 @@ EOF )" if [[ -n "${module_snippet:-}" ]]; then - release_notes_md="$(cat <<-EOF + release_notes_md="$( + cat <<-EOF ${release_notes_md} ## Bazel Module Snippet ${module_snippet} EOF -)" + )" fi if [[ -n "${workspace_snippet:-}" ]]; then - release_notes_md="$(cat <<-EOF + release_notes_md="$( + cat <<-EOF ${release_notes_md} ## Workspace Snippet ${workspace_snippet} EOF -)" + )" fi # Output the changelog if [[ -z "${output_path:-}" ]]; then echo "${release_notes_md}" else - echo "${release_notes_md}" > "${output_path}" + echo "${release_notes_md}" >"${output_path}" fi diff --git a/bzlrelease/tools/generate_sha256.sh b/bzlrelease/tools/generate_sha256.sh index ecdfb5a3..62dde5dc 100755 --- a/bzlrelease/tools/generate_sha256.sh +++ b/bzlrelease/tools/generate_sha256.sh @@ -2,51 +2,57 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/fail.sh source "${fail_sh}" env_sh_location=cgrindel_bazel_starlib/shlib/lib/env.sh -env_sh="$(rlocation "${env_sh_location}")" || \ +env_sh="$(rlocation "${env_sh_location}")" || (echo >&2 "Failed to locate ${env_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/env.sh source "${env_sh}" - # MARK - Process Arguments args=() while (("$#")); do case "${1}" in - "--source") - source_path="${2}" - shift 2 - ;; - "--output") - output_path="${2}" - shift 2 - ;; - "--utility") - utility="${2}" - shift 2 - ;; - *) - args+=("${1}") - shift 1 - ;; + "--source") + source_path="${2}" + shift 2 + ;; + "--output") + output_path="${2}" + shift 2 + ;; + "--utility") + utility="${2}" + shift 2 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -63,22 +69,22 @@ fi # Define the hash function case "${utility}" in - shasum) - function sumsha256() { - shasum -a 256 | sed -E -n 's/^([^[:space:]]+).*/\1/gp' - } - ;; - openssl) - function sumsha256() { - # On Ubuntu, we can see a prefix of '(stdin)= ' - # 2023-02-01: This has recently changed to be 'SHA2-256(stdin)='. - openssl dgst -sha256 | sed -E 's|^.*\(stdin\)= (.*)|\1|g' - } - ;; - *) - fail "Unrecognized utility. ${utility:-}" - ;; +shasum) + function sumsha256() { + shasum -a 256 | sed -E -n 's/^([^[:space:]]+).*/\1/gp' + } + ;; +openssl) + function sumsha256() { + # On Ubuntu, we can see a prefix of '(stdin)= ' + # 2023-02-01: This has recently changed to be 'SHA2-256(stdin)='. + openssl dgst -sha256 | sed -E 's|^.*\(stdin\)= (.*)|\1|g' + } + ;; +*) + fail "Unrecognized utility. ${utility:-}" + ;; esac # Generate the hash -sumsha256 < "${source_path:-/dev/stdin}" > "${output_path:-/dev/stdout}" +sumsha256 <"${source_path:-/dev/stdin}" >"${output_path:-/dev/stdout}" diff --git a/bzlrelease/tools/generate_workspace_snippet.sh b/bzlrelease/tools/generate_workspace_snippet.sh index d0a47ef5..c6b8df72 100755 --- a/bzlrelease/tools/generate_workspace_snippet.sh +++ b/bzlrelease/tools/generate_workspace_snippet.sh @@ -12,41 +12,48 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/fail.sh source "${fail_sh}" git_sh_location=cgrindel_bazel_starlib/shlib/lib/git.sh -git_sh="$(rlocation "${git_sh_location}")" || \ +git_sh="$(rlocation "${git_sh_location}")" || (echo >&2 "Failed to locate ${git_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/git.sh source "${git_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/github.sh source "${github_sh}" generate_git_archive_sh_location=cgrindel_bazel_starlib/bzlrelease/tools/generate_git_archive.sh -generate_git_archive_sh="$(rlocation "${generate_git_archive_sh_location}")" || \ +generate_git_archive_sh="$(rlocation "${generate_git_archive_sh_location}")" || (echo >&2 "Failed to locate ${generate_git_archive_sh_location}" && exit 1) generate_sha256_sh_location=cgrindel_bazel_starlib/bzlrelease/tools/generate_sha256.sh -generate_sha256_sh="$(rlocation "${generate_sha256_sh_location}")" || \ +generate_sha256_sh="$(rlocation "${generate_sha256_sh_location}")" || (echo >&2 "Failed to locate ${generate_sha256_sh_location}" && exit 1) # MARK - Keep Track of the starting directory @@ -62,64 +69,64 @@ url_templates=() args=() while (("$#")); do case "${1}" in - "--sha256") - sha256="${2}" - shift 2 - ;; - "--sha256_file") - sha256_file="${2}" - shift 2 - ;; - "--tag") - tag="${2}" - shift 2 - ;; - "--url") - url_templates+=( "${2}" ) - shift 2 - ;; - "--github_release_archive_url") - add_github_release_archive_url=true - add_github_src_archive_url=false - add_strip_prefix=false - shift 1 - ;; - "--no_github_source_archive_url") - add_github_src_archive_url=false - shift 1 - ;; - "--no_strip_prefix") - add_github_src_archive_url=false - shift 1 - ;; - "--owner") - owner="${2}" - shift 2 - ;; - "--repo") - repo="${2}" - shift 2 - ;; - "--workspace_name") - workspace_name="${2}" - shift 2 - ;; - "--output") - output_path="${2}" - shift 2 - ;; - "--template") - # If the input path is not absolute, then resolve it to be relative to - # the starting directory. We do this before we starting changing - # directories. - template="${2}" - [[ "${template}" =~ ^/ ]] || template="${starting_dir}/${2}" - shift 2 - ;; - *) - args+=( "${1}" ) - shift 1 - ;; + "--sha256") + sha256="${2}" + shift 2 + ;; + "--sha256_file") + sha256_file="${2}" + shift 2 + ;; + "--tag") + tag="${2}" + shift 2 + ;; + "--url") + url_templates+=("${2}") + shift 2 + ;; + "--github_release_archive_url") + add_github_release_archive_url=true + add_github_src_archive_url=false + add_strip_prefix=false + shift 1 + ;; + "--no_github_source_archive_url") + add_github_src_archive_url=false + shift 1 + ;; + "--no_strip_prefix") + add_github_src_archive_url=false + shift 1 + ;; + "--owner") + owner="${2}" + shift 2 + ;; + "--repo") + repo="${2}" + shift 2 + ;; + "--workspace_name") + workspace_name="${2}" + shift 2 + ;; + "--output") + output_path="${2}" + shift 2 + ;; + "--template") + # If the input path is not absolute, then resolve it to be relative to + # the starting directory. We do this before we starting changing + # directories. + template="${2}" + [[ "${template}" =~ ^/ ]] || template="${starting_dir}/${2}" + shift 2 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -128,20 +135,20 @@ done [[ -z "${tag:-}" ]] && fail "Expected a tag value." # shellcheck disable=SC2016 -[[ "${add_github_src_archive_url}" == true ]] && \ - url_templates+=( 'http://github.com/${owner}/${repo}/archive/${tag}.tar.gz' ) +[[ "${add_github_src_archive_url}" == true ]] && + url_templates+=('http://github.com/${owner}/${repo}/archive/${tag}.tar.gz') # shellcheck disable=SC2016 -[[ "${add_github_release_archive_url}" == true ]] && \ - url_templates+=( 'https://github.com/${owner}/${repo}/releases/download/${tag}/${repo}.${tag}.tar.gz' ) +[[ "${add_github_release_archive_url}" == true ]] && + url_templates+=('https://github.com/${owner}/${repo}/releases/download/${tag}/${repo}.${tag}.tar.gz') [[ ${#url_templates[@]} -gt 0 ]] || fail "Expected one or more url templates." # MARK - Ensure that we have a SHA256 value if [[ -n "${sha256_file:-}" ]]; then - sha256="$(< "${sha256_file}")" + sha256="$(<"${sha256_file}")" fi if [[ -z "${sha256:-}" ]]; then - sha256="$( "${generate_git_archive_sh}" --tag_name "${tag}" | "${generate_sha256_sh}" )" + sha256="$("${generate_git_archive_sh}" --tag_name "${tag}" | "${generate_sha256_sh}")" fi # MARK - Generate the snippet @@ -149,11 +156,11 @@ fi cd "${BUILD_WORKSPACE_DIRECTORY}" if [[ -z "${owner:-}" ]] || [[ -z "${repo:-}" ]]; then - repo_url="$( get_git_remote_url )" - is_github_repo_url "${repo_url}" || \ + repo_url="$(get_git_remote_url)" + is_github_repo_url "${repo_url}" || fail "This git repository's remote does not appear to be hosted by Github. repo_url: ${repo_url}" - owner="$( get_gh_repo_owner "${repo_url}" )" - repo="$( get_gh_repo_name "${repo_url}" )" + owner="$(get_gh_repo_owner "${repo_url}")" + repo="$(get_gh_repo_name "${repo_url}")" fi strip_prefix_suffix="${tag}" @@ -168,16 +175,16 @@ fi # Evaluate the URL template urls="$( - for url_template in "${url_templates[@]}" ; do + for url_template in "${url_templates[@]}"; do url="$(eval echo "${url_template}")" echo " \"${url}\"," done )" - if [[ "${add_strip_prefix}" == true ]]; then # Generate the workspace snippet - http_archive_statement="$(cat <<-EOF + http_archive_statement="$( + cat <<-EOF http_archive( name = "${workspace_name}", sha256 = "${sha256}", @@ -189,7 +196,8 @@ ${urls} EOF )" else - http_archive_statement="$(cat <<-EOF + http_archive_statement="$( + cat <<-EOF http_archive( name = "${workspace_name}", sha256 = "${sha256}", @@ -201,7 +209,6 @@ EOF )" fi - if [[ -z "${template:-}" ]]; then snippet="${http_archive_statement}" else @@ -211,19 +218,20 @@ else # remove the temp file when we are done. tmp_snippet_path="$(mktemp)" trap 'rm -rf "${tmp_snippet_path}"' EXIT - echo "${http_archive_statement}" > "${tmp_snippet_path}" + echo "${http_archive_statement}" >"${tmp_snippet_path}" # Replace the '${http_archive_statement}' with the generated http_archive # statement. sed -E \ - -e '/\$\{http_archive_statement\}/r '"${tmp_snippet_path}" \ - -e '/\$\{http_archive_statement\}/d' \ + -e '/\$\{http_archive_statement\}/r '"${tmp_snippet_path}" \ + -e '/\$\{http_archive_statement\}/d' \ "${template}" )" fi # Wrap the resulting snippet in a markdown codeblock. -snippet="$(cat <<-EOF +snippet="$( + cat <<-EOF \`\`\`python ${snippet} \`\`\` @@ -234,5 +242,5 @@ EOF if [[ -z "${output_path:-}" ]]; then echo "${snippet}" else - echo "${snippet}" > "${output_path}" + echo "${snippet}" >"${output_path}" fi diff --git a/bzlrelease/tools/update_readme.sh b/bzlrelease/tools/update_readme.sh index fc51e7c1..b5cecb8c 100755 --- a/bzlrelease/tools/update_readme.sh +++ b/bzlrelease/tools/update_readme.sh @@ -2,28 +2,34 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/fail.sh source "${fail_sh}" update_markdown_doc_sh_location=cgrindel_bazel_starlib/markdown/tools/update_markdown_doc.sh -update_markdown_doc_sh="$(rlocation "${update_markdown_doc_sh_location}")" || \ +update_markdown_doc_sh="$(rlocation "${update_markdown_doc_sh_location}")" || (echo >&2 "Failed to locate ${update_markdown_doc_sh_location}" && exit 1) - # MARK - Process Arguments starting_dir="${PWD}" @@ -31,36 +37,36 @@ starting_dir="${PWD}" args=() while (("$#")); do case "${1}" in - "--generate_workspace_snippet") - # If the input path is not absolute, then resolve it to be relative to - # the starting directory. We do this before we starting changing - # directories. - generate_workspace_snippet="${2}" - [[ "${generate_workspace_snippet}" =~ ^/ ]] || \ - generate_workspace_snippet="${starting_dir}/${generate_workspace_snippet}" - shift 2 - ;; - "--generate_module_snippet") - # If the input path is not absolute, then resolve it to be relative to - # the starting directory. We do this before we starting changing - # directories. - generate_module_snippet="${2}" - [[ "${generate_module_snippet}" =~ ^/ ]] || \ - generate_module_snippet="${starting_dir}/${generate_module_snippet}" - shift 2 - ;; - "--readme") - # This is a relative path from the root of the workspace. - readme_path="${2}" - shift 2 - ;; - --*) - fail "Unrecognized flag ${1}." - ;; - *) - args+=("${1}") - shift 1 - ;; + "--generate_workspace_snippet") + # If the input path is not absolute, then resolve it to be relative to + # the starting directory. We do this before we starting changing + # directories. + generate_workspace_snippet="${2}" + [[ "${generate_workspace_snippet}" =~ ^/ ]] || + generate_workspace_snippet="${starting_dir}/${generate_workspace_snippet}" + shift 2 + ;; + "--generate_module_snippet") + # If the input path is not absolute, then resolve it to be relative to + # the starting directory. We do this before we starting changing + # directories. + generate_module_snippet="${2}" + [[ "${generate_module_snippet}" =~ ^/ ]] || + generate_module_snippet="${starting_dir}/${generate_module_snippet}" + shift 2 + ;; + "--readme") + # This is a relative path from the root of the workspace. + readme_path="${2}" + shift 2 + ;; + --*) + fail "Unrecognized flag ${1}." + ;; + *) + args+=("${1}") + shift 1 + ;; esac done diff --git a/bzltidy/private/check_tidy.sh b/bzltidy/private/check_tidy.sh index ec2f5277..c8f9a1c5 100755 --- a/bzltidy/private/check_tidy.sh +++ b/bzltidy/private/check_tidy.sh @@ -5,7 +5,7 @@ set -o errexit -o nounset -o pipefail # Purposefully not using Bazel's Bash runfiles support. Running it here, # appears to mess up the execution of targets that also use it. -# Use the Bazel binary specified by the integration test. Otherise, fall back +# Use the Bazel binary specified by the integration test. Otherise, fall back # to bazel. bazel="${BIT_BAZEL_BINARY:-bazel}" @@ -65,18 +65,18 @@ EOF git_status() { local out="${1}" - git status --porcelain > "${out}" + git status --porcelain >"${out}" } git_diff() { local out="${1}" - git diff > "${out}" + git diff >"${out}" } diff_files() { local first="${1}" local second="${2}" - diff "${first}" "${second}" + diff "${first}" "${second}" } # MARK - Process Args @@ -84,20 +84,20 @@ diff_files() { tidy_target= while (("$#")); do case "${1}" in - "--help") - show_usage - ;; - --*) - usage_error "Unrecognized option. ${1}" - ;; - *) - if [[ -z "${tidy_target:-}" ]]; then - tidy_target="${1}" - else - usage_error "Unrecognized argument. ${1}" - fi - shift 1 - ;; + "--help") + show_usage + ;; + --*) + usage_error "Unrecognized option. ${1}" + ;; + *) + if [[ -z "${tidy_target:-}" ]]; then + tidy_target="${1}" + else + usage_error "Unrecognized argument. ${1}" + fi + shift 1 + ;; esac done @@ -138,12 +138,12 @@ after_diff="${after_dir}/diff" git_diff "${after_diff}" # Compare the before and after -status_diff="$( diff_files "${before_status}" "${after_status}" || true )" +status_diff="$(diff_files "${before_status}" "${after_status}" || true)" if [[ -n "${status_diff:-}" ]]; then fail "The git status outputs changed." "${status_diff}" fi -diff_diff="$( diff_files "${before_diff}" "${after_diff}" || true )" +diff_diff="$(diff_files "${before_diff}" "${after_diff}" || true)" if [[ -n "${diff_diff:-}" ]]; then fail "The git diff outputs changed." "${diff_diff}" fi diff --git a/bzltidy/private/tidy.sh b/bzltidy/private/tidy.sh index ea1340d2..70b1eeec 100755 --- a/bzltidy/private/tidy.sh +++ b/bzltidy/private/tidy.sh @@ -5,7 +5,7 @@ set -o errexit -o nounset -o pipefail # Purposefully not using Bazel's Bash runfiles support. Running it here, # appears to mess up the execution of targets that also use it. -# Use the Bazel binary specified by the integration test. Otherise, fall back +# Use the Bazel binary specified by the integration test. Otherise, fall back # to bazel. bazel="${BIT_BAZEL_BINARY:-bazel}" @@ -79,16 +79,16 @@ run_bazel_targets() { targets=() while (("$#")); do case "${1}" in - "--help") - show_usage - ;; - --*) - usage_error "Unrecognized option. ${1}" - ;; - *) - targets+=("${1}") - shift 1 - ;; + "--help") + show_usage + ;; + --*) + usage_error "Unrecognized option. ${1}" + ;; + *) + targets+=("${1}") + shift 1 + ;; esac done diff --git a/bzltidy/private/tidy_all.sh b/bzltidy/private/tidy_all.sh index bf753c0e..a5c3e247 100755 --- a/bzltidy/private/tidy_all.sh +++ b/bzltidy/private/tidy_all.sh @@ -5,7 +5,7 @@ set -o errexit -o nounset -o pipefail # Purposefully not using Bazel's Bash runfiles support. Running it here, # appears to mess up the execution of targets that also use it. -# Use the Bazel binary specified by the integration test. Otherise, fall back +# Use the Bazel binary specified by the integration test. Otherise, fall back # to bazel. bazel="${BIT_BAZEL_BINARY:-bazel}" @@ -64,12 +64,12 @@ sort_items() { # Flags: # --start_dir: The directory where to start the search. # --error_if_not_found: If specified, the function will return 1 if the file is not found. -# +# # Args: # target_file: The basename for the file to be found. # # Outputs: -# stdout: The fully-qualified path to the +# stdout: The fully-qualified path to the # stderr: None. upsearch() { # Lovingly inspired by https://unix.stackexchange.com/a/13474. @@ -79,19 +79,19 @@ upsearch() { local args=() while (("$#")); do case "${1}" in - "--start_dir") - local start_dir - start_dir="$(normalize_path "${2}")" - shift 2 - ;; - "--error_if_not_found") - local error_if_not_found=1 - shift 1 - ;; - *) - args+=( "${1}" ) - shift 1 - ;; + "--start_dir") + local start_dir + start_dir="$(normalize_path "${2}")" + shift 2 + ;; + "--error_if_not_found") + local error_if_not_found=1 + shift 1 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -99,11 +99,10 @@ upsearch() { slashes=${start_dir//[^\/]/} directory="${start_dir}" - for (( n=${#slashes}; n>0; --n )) - do + for ((n = ${#slashes}; n > 0; --n)); do local test_path="${directory}/${target_file}" - test -e "${test_path}" && \ - normalize_path "${test_path}" && return + test -e "${test_path}" && + normalize_path "${test_path}" && return directory="${directory}/.." done @@ -131,7 +130,7 @@ normalize_path() { local basename basename="$(basename "${path}")" fi - dirname="$(cd "${dirname}" > /dev/null && pwd)" + dirname="$(cd "${dirname}" >/dev/null && pwd)" if [[ -z "${basename:-}" ]]; then echo "${dirname}" else @@ -182,13 +181,13 @@ find_workspaces_with_modifications() { # Find the workspace file for each modified file. local workspaces=() - for file in "${modified_files[@]}" ; do + for file in "${modified_files[@]}"; do local dir - dir="$( dirname "${file}" )" - workspaces+=( "$(upsearch --error_if_not_found --start_dir "${dir}" "WORKSPACE")" ) + dir="$(dirname "${file}")" + workspaces+=("$(upsearch --error_if_not_found --start_dir "${dir}" "WORKSPACE")") done - # Return a unique list + # Return a unique list sort_items "${workspaces[@]}" } @@ -204,23 +203,23 @@ tidy_target="//:tidy" while (("$#")); do case "${1}" in - "--help") - show_usage - ;; - "--mode") - find_workspace_mode="$2" - shift 2 - ;; - "--tidy_target") - tidy_target="$2" - shift 2 - ;; - --*) - usage_error "Unrecognized option. ${1}" - ;; - *) - usage_error "Unrecognized argument. ${1}" - ;; + "--help") + show_usage + ;; + "--mode") + find_workspace_mode="$2" + shift 2 + ;; + "--tidy_target") + tidy_target="$2" + shift 2 + ;; + --*) + usage_error "Unrecognized option. ${1}" + ;; + *) + usage_error "Unrecognized argument. ${1}" + ;; esac done @@ -232,14 +231,15 @@ cd "${BUILD_WORKSPACE_DIRECTORY}" # Find all of the workspaces find_workspace_cmd=() case "${find_workspace_mode}" in - "all") - find_workspace_cmd=( find_all_workspaces "${BUILD_WORKSPACE_DIRECTORY}" ) - ;; - "modified") - find_workspace_cmd=( find_workspaces_with_modifications "${BUILD_WORKSPACE_DIRECTORY}" ) - ;; - *) - fail "Unrecognized find_workspace_mode: ${find_workspace_mode}." +"all") + find_workspace_cmd=(find_all_workspaces "${BUILD_WORKSPACE_DIRECTORY}") + ;; +"modified") + find_workspace_cmd=(find_workspaces_with_modifications "${BUILD_WORKSPACE_DIRECTORY}") + ;; +*) + fail "Unrecognized find_workspace_mode: ${find_workspace_mode}." + ;; esac workspaces=() while IFS=$'\n' read -r line; do workspaces+=("$line"); done < <( @@ -252,7 +252,7 @@ if [[ ${#workspaces[@]} -eq 0 ]]; then fi # Execute tidy target in the workspaces, if it exists. -for workspace in "${workspaces[@]}" ; do +for workspace in "${workspaces[@]}"; do workspace_dir="$(dirname "${workspace}")" cd "${workspace_dir}" if target_exists "${tidy_target}"; then diff --git a/deps.bzl b/deps.bzl index 7b14f52c..fbc287e0 100644 --- a/deps.bzl +++ b/deps.bzl @@ -7,10 +7,10 @@ def _bazeldoc_dependencies(): maybe( http_archive, name = "io_bazel_stardoc", - sha256 = "0e1ed4a98f26e718776bd64d053d02bb34d98572ccd03d6ba355112a1205706b", + sha256 = "ca933f39f2a6e0ad392fa91fd662545afcbd36c05c62365538385d35a0323096", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.7.2/stardoc-0.7.2.tar.gz", - "https://github.com/bazelbuild/stardoc/releases/download/0.7.2/stardoc-0.7.2.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.8.0/stardoc-0.8.0.tar.gz", + "https://github.com/bazelbuild/stardoc/releases/download/0.8.0/stardoc-0.8.0.tar.gz", ], ) @@ -18,10 +18,10 @@ def _prebuilt_buildtools_dependencies(): maybe( http_archive, name = "buildifier_prebuilt", - sha256 = "e31fe636a5004eb50b7b47ec31c3cea0afd597d14bb1991832aa213038837ecf", - strip_prefix = "buildifier-prebuilt-8.0.0", + sha256 = "bf9101bd5d657046674167986a18d44c5612e417194dc55aff8ca174344de031", + strip_prefix = "buildifier-prebuilt-8.0.3", urls = [ - "http://github.com/keith/buildifier-prebuilt/archive/8.0.0.tar.gz", + "http://github.com/keith/buildifier-prebuilt/archive/8.0.3.tar.gz", ], ) @@ -32,10 +32,10 @@ def bazel_starlib_dependencies(): maybe( http_archive, name = "bazel_skylib", - sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f", + sha256 = "6e78f0e57de26801f6f564fa7c4a48dc8b36873e416257a92bbb0937eeac8446", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz", ], ) diff --git a/examples/bzlformat/simple/MODULE.bazel b/examples/bzlformat/simple/MODULE.bazel index b9f68057..39d8dbcf 100644 --- a/examples/bzlformat/simple/MODULE.bazel +++ b/examples/bzlformat/simple/MODULE.bazel @@ -4,4 +4,4 @@ local_path_override( path = "../../..", ) -bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "bazel_skylib", version = "1.8.2") diff --git a/examples/bzlformat/simple/mockascript/deps.bzl b/examples/bzlformat/simple/mockascript/deps.bzl index 31ec0c76..5d4d0bef 100644 --- a/examples/bzlformat/simple/mockascript/deps.bzl +++ b/examples/bzlformat/simple/mockascript/deps.bzl @@ -7,9 +7,9 @@ def mockascript_rules_dependencies(): maybe( http_archive, name = "bazel_skylib", - sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f", + sha256 = "6e78f0e57de26801f6f564fa7c4a48dc8b36873e416257a92bbb0937eeac8446", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz", ], ) diff --git a/examples/bzlformat/simple_test.sh b/examples/bzlformat/simple_test.sh index 81705b9e..67946737 100755 --- a/examples/bzlformat/simple_test.sh +++ b/examples/bzlformat/simple_test.sh @@ -2,41 +2,48 @@ # This script performs an integration test for bzlformat. # Changes are made to a build file and a bzl file, then the update -# all command is run to format the changes and copy them back to +# all command is run to format the changes and copy them back to # the workspace. Finally, the tests are run to be sure that everything # is formatted. # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/assertions.sh source "${assertions_sh}" paths_sh_location=cgrindel_bazel_starlib/shlib/lib/paths.sh -paths_sh="$(rlocation "${paths_sh_location}")" || \ +paths_sh="$(rlocation "${paths_sh_location}")" || (echo >&2 "Failed to locate ${paths_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/paths.sh source "${paths_sh}" messages_sh_location=cgrindel_bazel_starlib/shlib/lib/messages.sh -messages_sh="$(rlocation "${messages_sh_location}")" || \ +messages_sh="$(rlocation "${messages_sh_location}")" || (echo >&2 "Failed to locate ${messages_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/messages.sh source "${messages_sh}" create_scratch_dir_sh_location=rules_bazel_integration_test/tools/create_scratch_dir.sh -create_scratch_dir_sh="$(rlocation "${create_scratch_dir_sh_location}")" || \ +create_scratch_dir_sh="$(rlocation "${create_scratch_dir_sh_location}")" || (echo >&2 "Failed to locate ${create_scratch_dir_sh_location}" && exit 1) # MARK - Process Arguments @@ -47,9 +54,9 @@ workspace_dir="${BIT_WORKSPACE_DIR:-}" # Process args while (("$#")); do case "${1}" in - *) - shift 1 - ;; + *) + shift 1 + ;; esac done @@ -76,11 +83,11 @@ internal_build_path="${scratch_dir}/mockascript/internal/BUILD.bazel" mockascript_library_path="${scratch_dir}/mockascript/internal/mockascript_library.bzl" # Add poorly formatted code to build file. -echo "load(':foo.bzl', 'foo')" >> "${internal_build_path}" +echo "load(':foo.bzl', 'foo')" >>"${internal_build_path}" # Add poorly formatted code to bzl file. echo "load(':foo.bzl', 'foo'); foo(tags=['b', 'a'],srcs=['d', 'c'])" \ - >> "${mockascript_library_path}" + >>"${mockascript_library_path}" # Confirm that the tests fail with poorly formatted files. "${bazel}" test //... && fail "Expected tests to fail with poorly formatted files." diff --git a/examples/bzlmod_e2e/MODULE.bazel b/examples/bzlmod_e2e/MODULE.bazel index 2d5ac70a..74855c64 100644 --- a/examples/bzlmod_e2e/MODULE.bazel +++ b/examples/bzlmod_e2e/MODULE.bazel @@ -4,11 +4,11 @@ module( compatibility_level = 1, ) -bazel_dep(name = "rules_shell", version = "0.3.0") +bazel_dep(name = "rules_shell", version = "0.4.1") bazel_dep(name = "cgrindel_bazel_starlib", version = "0.0.0") local_path_override( module_name = "cgrindel_bazel_starlib", path = "../..", ) -bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "bazel_skylib", version = "1.8.2") diff --git a/examples/bzlmod_e2e/header/header.sh b/examples/bzlmod_e2e/header/header.sh index 4af0aae3..d9916e5f 100755 --- a/examples/bzlmod_e2e/header/header.sh +++ b/examples/bzlmod_e2e/header/header.sh @@ -7,7 +7,7 @@ out="$2" header="$3" first_line=$(head -n 1 "${src}") -if [[ "${first_line}" != "${header}" ]]; then - echo "${header}" > "${out}" +if [[ "${first_line}" != "${header}" ]]; then + echo "${header}" >"${out}" fi -cat "${src}" >> "${out}" +cat "${src}" >>"${out}" diff --git a/examples/bzlmod_e2e/mockascript/deps.bzl b/examples/bzlmod_e2e/mockascript/deps.bzl index 31ec0c76..5d4d0bef 100644 --- a/examples/bzlmod_e2e/mockascript/deps.bzl +++ b/examples/bzlmod_e2e/mockascript/deps.bzl @@ -7,9 +7,9 @@ def mockascript_rules_dependencies(): maybe( http_archive, name = "bazel_skylib", - sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f", + sha256 = "6e78f0e57de26801f6f564fa7c4a48dc8b36873e416257a92bbb0937eeac8446", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz", ], ) diff --git a/examples/bzlmod_e2e/srcs/Foo/BUILD.bazel b/examples/bzlmod_e2e/srcs/Foo/BUILD.bazel index 878db295..56a7904b 100644 --- a/examples/bzlmod_e2e/srcs/Foo/BUILD.bazel +++ b/examples/bzlmod_e2e/srcs/Foo/BUILD.bazel @@ -1,5 +1,5 @@ -load("//header:header.bzl", "header") load("@cgrindel_bazel_starlib//updatesrc:defs.bzl", "updatesrc_update") +load("//header:header.bzl", "header") header( name = "add_headers", diff --git a/examples/markdown/simple/MODULE.bazel b/examples/markdown/simple/MODULE.bazel index b9f68057..39d8dbcf 100644 --- a/examples/markdown/simple/MODULE.bazel +++ b/examples/markdown/simple/MODULE.bazel @@ -4,4 +4,4 @@ local_path_override( path = "../../..", ) -bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "bazel_skylib", version = "1.8.2") diff --git a/examples/tools/BUILD.bazel b/examples/tools/BUILD.bazel new file mode 100644 index 00000000..95c0526a --- /dev/null +++ b/examples/tools/BUILD.bazel @@ -0,0 +1,85 @@ +load("@bazel_binaries//:defs.bzl", "bazel_binaries") +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") +load( + "@rules_bazel_integration_test//bazel_integration_test:defs.bzl", + "bazel_integration_tests", + "default_test_runner", + "integration_test_utils", +) +load("//ci:defs.bzl", "ci_integration_test_params") + +bzlformat_pkg(name = "bzlformat") + +# Do not have Gazelle process the child workspace +# gazelle:exclude workspace/** + +# MARK: - Integration Tests + +default_test_runner( + name = "tools_test_runner", + bazel_cmds = [ + "info", + "test //...", + ], +) + +bazel_integration_tests( + name = "tools_test", + bazel_binaries = bazel_binaries, + bazel_versions = bazel_binaries.versions.all, + tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS + [ + # Avoid file permssion error when using disk and repository cache after + # 7.0.0rc2 upgrade. + # https://github.com/bazelbuild/bazel/issues/19908 + "no-sandbox", + ], + test_runner = ":tools_test_runner", + workspace_files = integration_test_utils.glob_workspace_files("workspace") + [ + "//:workspace_integration_test_files", + ], + workspace_path = "workspace", +) + +# MARK: - Test Suites + +test_suite( + name = "smoke_integration_tests", + tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, + tests = [ + integration_test_utils.bazel_integration_test_name( + "tools_test", + bazel_binaries.versions.current, + ), + ], + visibility = ["//:__subpackages__"], +) + +test_suite( + name = "all_integration_tests", + tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, + tests = integration_test_utils.bazel_integration_test_names( + "tools_test", + bazel_binaries.versions.all, + ), + visibility = ["//:__subpackages__"], +) + +ci_integration_test_params( + name = "tools_test_params", + bzlmod_modes = ["enabled"], + oss = [ + "macos", + "linux", + ], + test_names = integration_test_utils.bazel_integration_test_names( + "tools_test", + bazel_binaries.versions.all, + ), + visibility = ["//:__subpackages__"], +) + +alias( + name = "all_test_params", + actual = ":tools_test_params", + visibility = ["//:__subpackages__"], +) diff --git a/examples/tools/workspace/BUILD.bazel b/examples/tools/workspace/BUILD.bazel new file mode 100644 index 00000000..71b21bfa --- /dev/null +++ b/examples/tools/workspace/BUILD.bazel @@ -0,0 +1,14 @@ +load("@rules_shell//shell:sh_test.bzl", "sh_test") + +sh_test( + name = "tools_test", + srcs = ["tools_test.sh"], + data = [ + "@cgrindel_bazel_starlib//tools/git", + "@cgrindel_bazel_starlib//tools/tar", + ], + deps = [ + "@bazel_tools//tools/bash/runfiles", + "@cgrindel_bazel_starlib//shlib/lib:assertions", + ], +) diff --git a/examples/tools/workspace/MODULE.bazel b/examples/tools/workspace/MODULE.bazel new file mode 100644 index 00000000..fbd0b63b --- /dev/null +++ b/examples/tools/workspace/MODULE.bazel @@ -0,0 +1,13 @@ +module( + name = "toolchains_example", + version = "0.0.0", +) + +bazel_dep(name = "rules_shell", version = "0.4.1") +bazel_dep(name = "cgrindel_bazel_starlib") +local_path_override( + module_name = "cgrindel_bazel_starlib", + path = "../../..", +) + +bazel_dep(name = "bazel_skylib", version = "1.8.2") diff --git a/examples/tools/workspace/WORKSPACE b/examples/tools/workspace/WORKSPACE new file mode 100644 index 00000000..ccd9dcef --- /dev/null +++ b/examples/tools/workspace/WORKSPACE @@ -0,0 +1 @@ +# Intentionally blank diff --git a/examples/tools/workspace/WORKSPACE.bzlmod b/examples/tools/workspace/WORKSPACE.bzlmod new file mode 100644 index 00000000..ced68543 --- /dev/null +++ b/examples/tools/workspace/WORKSPACE.bzlmod @@ -0,0 +1,3 @@ +# Intentionally blank +# This exists to force Bazel in bzlmod mode to be strict. + diff --git a/examples/tools/workspace/tools_test.sh b/examples/tools/workspace/tools_test.sh new file mode 100755 index 00000000..52d67b97 --- /dev/null +++ b/examples/tools/workspace/tools_test.sh @@ -0,0 +1,46 @@ +#!/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}" + +git_exe_location=cgrindel_bazel_starlib/tools/git/git.exe +git="$(rlocation "${git_exe_location}")" || + (echo >&2 "Failed to locate ${git_exe_location}" && exit 1) + +tar_exe_location=cgrindel_bazel_starlib/tools/tar/tar.exe +tar="$(rlocation "${tar_exe_location}")" || + (echo >&2 "Failed to locate ${tar_exe_location}" && exit 1) + +# MARK - Test + +# We do not run git, because on MacOS it is tied to xcodebuild which may fail +# if that is not the version of git being used on the system (i.e., using +# Homebrew). +if [[ ! -e "${git}" ]]; then + fail "Did not find git." +fi + +output="$("${tar}" --help)" +assert_match tar "${output}" "tar help output" diff --git a/examples/updatesrc/simple/MODULE.bazel b/examples/updatesrc/simple/MODULE.bazel index aa3428c3..bc7ee74f 100644 --- a/examples/updatesrc/simple/MODULE.bazel +++ b/examples/updatesrc/simple/MODULE.bazel @@ -3,11 +3,11 @@ module( version = "0.0.0", ) -bazel_dep(name = "rules_shell", version = "0.3.0") +bazel_dep(name = "rules_shell", version = "0.4.1") bazel_dep(name = "cgrindel_bazel_starlib") local_path_override( module_name = "cgrindel_bazel_starlib", path = "../../..", ) -bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "bazel_skylib", version = "1.8.2") diff --git a/examples/updatesrc/simple/header/header.sh b/examples/updatesrc/simple/header/header.sh index 4af0aae3..d9916e5f 100755 --- a/examples/updatesrc/simple/header/header.sh +++ b/examples/updatesrc/simple/header/header.sh @@ -7,7 +7,7 @@ out="$2" header="$3" first_line=$(head -n 1 "${src}") -if [[ "${first_line}" != "${header}" ]]; then - echo "${header}" > "${out}" +if [[ "${first_line}" != "${header}" ]]; then + echo "${header}" >"${out}" fi -cat "${src}" >> "${out}" +cat "${src}" >>"${out}" diff --git a/examples/updatesrc/simple/srcs/Foo/BUILD.bazel b/examples/updatesrc/simple/srcs/Foo/BUILD.bazel index 878db295..56a7904b 100644 --- a/examples/updatesrc/simple/srcs/Foo/BUILD.bazel +++ b/examples/updatesrc/simple/srcs/Foo/BUILD.bazel @@ -1,5 +1,5 @@ -load("//header:header.bzl", "header") load("@cgrindel_bazel_starlib//updatesrc:defs.bzl", "updatesrc_update") +load("//header:header.bzl", "header") header( name = "add_headers", diff --git a/markdown/private/yarn.lock b/markdown/private/yarn.lock index 56491afe..81846070 100644 --- a/markdown/private/yarn.lock +++ b/markdown/private/yarn.lock @@ -36,12 +36,10 @@ resolved "https://registry.yarnpkg.com/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz#db4ecfd499a9765ab24002c3b696d02e6d32a12c" integrity sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA== -agent-base@^7.0.2, agent-base@^7.1.0, agent-base@^7.1.1: - version "7.1.1" - resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-7.1.1.tgz#bdbded7dfb096b751a2a087eeeb9664725b2e317" - integrity sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA== - dependencies: - debug "^4.3.4" +agent-base@^7.1.0, agent-base@^7.1.2: + version "7.1.3" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-7.1.3.tgz#29435eb821bc4194633a5b89e5bc4703bafc25a1" + integrity sha512-jRR5wdylq8CkOe6hei19GGZnxM6rBGwFl3Bg0YItGDimvjGtAvdZk4Pu6Cl4u4Igsws4a1fd1Vq3ezrhn4KmFw== argparse@^1.0.7: version "1.0.10" @@ -73,9 +71,9 @@ boolbase@^1.0.0: integrity sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww== chalk@^5.3.0: - version "5.3.0" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.3.0.tgz#67c20a7ebef70e7f3970a01f90fa210cb6860385" - integrity sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w== + version "5.4.1" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.4.1.tgz#1b48bf0963ec158dce2aacf69c093ae2dd2092d8" + integrity sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w== cheerio-select@^2.1.0: version "2.1.0" @@ -106,10 +104,10 @@ cheerio@^1.0.0-rc.10: undici "^6.19.5" whatwg-mimetype "^4.0.0" -commander@^12.1.0: - version "12.1.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3" - integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA== +commander@^13.1.0: + version "13.1.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-13.1.0.tgz#776167db68c78f38dcce1f9b8d7b8b9a488abf46" + integrity sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw== css-select@^5.1.0: version "5.1.0" @@ -133,9 +131,9 @@ data-uri-to-buffer@^6.0.2: integrity sha512-7hvf7/GW8e86rW0ptuwS3OcBGDjIi6SZva7hCyWC0yYry2cOPmLIjXAUHI6DK2HsnwJd9ifmt57i8eV2n4YNpw== debug@4, debug@^4.3.4: - version "4.3.7" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.7.tgz#87945b4151a011d76d95a198d7111c865c360a52" - integrity sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ== + version "4.4.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.0.tgz#2b3f2aea2ffeb776477460267377dc8710faba8a" + integrity sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA== dependencies: ms "^2.1.3" @@ -170,9 +168,9 @@ domhandler@^5.0.2, domhandler@^5.0.3: domelementtype "^2.3.0" domutils@^3.0.1, domutils@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/domutils/-/domutils-3.1.0.tgz#c47f551278d3dc4b0b1ab8cbb42d751a6f0d824e" - integrity sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA== + version "3.2.2" + resolved "https://registry.yarnpkg.com/domutils/-/domutils-3.2.2.tgz#edbfe2b668b0c1d97c24baf0f1062b132221bc78" + integrity sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw== dependencies: dom-serializer "^2.0.0" domelementtype "^2.3.0" @@ -217,29 +215,14 @@ esutils@^2.0.2: resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== -fs-extra@^11.2.0: - version "11.2.0" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.2.0.tgz#e70e17dfad64232287d01929399e0ea7c86b0e5b" - integrity sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw== - dependencies: - graceful-fs "^4.2.0" - jsonfile "^6.0.1" - universalify "^2.0.0" - get-uri@^6.0.1: - version "6.0.3" - resolved "https://registry.yarnpkg.com/get-uri/-/get-uri-6.0.3.tgz#0d26697bc13cf91092e519aa63aa60ee5b6f385a" - integrity sha512-BzUrJBS9EcUb4cFol8r4W3v1cPsSyajLSthNkz5BxbpDcHN5tIrM10E2eNvfnvBn3DaT3DUgx0OpsBKkaOpanw== + version "6.0.4" + resolved "https://registry.yarnpkg.com/get-uri/-/get-uri-6.0.4.tgz#6daaee9e12f9759e19e55ba313956883ef50e0a7" + integrity sha512-E1b1lFFLvLgak2whF2xDBcOy6NLVGZBqqjJjsIhvopKfWWEi64pLVTWWehV8KlLerZkfNTA95sTe2OdJKm1OzQ== dependencies: basic-ftp "^5.0.2" data-uri-to-buffer "^6.0.2" debug "^4.3.4" - fs-extra "^11.2.0" - -graceful-fs@^4.1.6, graceful-fs@^4.2.0: - version "4.2.11" - resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" - integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== html-link-extractor@^1.0.5: version "1.0.5" @@ -266,12 +249,12 @@ http-proxy-agent@^7.0.0, http-proxy-agent@^7.0.1: agent-base "^7.1.0" debug "^4.3.4" -https-proxy-agent@^7.0.3, https-proxy-agent@^7.0.5: - version "7.0.5" - resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz#9e8b5013873299e11fab6fd548405da2d6c602b2" - integrity sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw== +https-proxy-agent@^7.0.6: + version "7.0.6" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz#da8dfeac7da130b05c2ba4b59c9b6cd66611a6b9" + integrity sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw== dependencies: - agent-base "^7.0.2" + agent-base "^7.1.2" debug "4" iconv-lite@0.6.3, iconv-lite@^0.6.3: @@ -314,15 +297,6 @@ jsbn@1.1.0: resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-1.1.0.tgz#b01307cb29b618a1ed26ec79e911f803c4da0040" integrity sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A== -jsonfile@^6.0.1: - version "6.1.0" - resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" - integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ== - dependencies: - universalify "^2.0.0" - optionalDependencies: - graceful-fs "^4.1.6" - link-check@^5.4.0: version "5.4.0" resolved "https://registry.yarnpkg.com/link-check/-/link-check-5.4.0.tgz#73be9b8c40a107da0dbb83a2d2c97657ae3c6672" @@ -340,13 +314,13 @@ lru-cache@^7.14.1: integrity sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA== markdown-link-check@^3.10.0: - version "3.13.6" - resolved "https://registry.yarnpkg.com/markdown-link-check/-/markdown-link-check-3.13.6.tgz#670a139a0ab47e60fdd49f8db07a842e812a0c4e" - integrity sha512-JiqexKOR+oaBovJ16x/VEN886CzPI48bSGUcKJvnkHVS8xSb9fRJtsdcLwG8+5QQ/V0UZKFmW8JEZFcZbd0BBA== + version "3.13.7" + resolved "https://registry.yarnpkg.com/markdown-link-check/-/markdown-link-check-3.13.7.tgz#789d7f2e6bf9a48df3d2a501735aa04b8acf1bd7" + integrity sha512-Btn3HU8s2Uyh1ZfzmyZEkp64zp2+RAjwfQt1u4swq2Xa6w37OW0T2inQZrkSNVxDSa2jSN2YYhw/JkAp5jF1PQ== dependencies: async "^3.2.6" chalk "^5.3.0" - commander "^12.1.0" + commander "^13.1.0" link-check "^5.4.0" markdown-link-extractor "^4.0.2" needle "^3.3.1" @@ -400,19 +374,19 @@ nth-check@^2.0.1: dependencies: boolbase "^1.0.0" -pac-proxy-agent@^7.0.1: - version "7.0.2" - resolved "https://registry.yarnpkg.com/pac-proxy-agent/-/pac-proxy-agent-7.0.2.tgz#0fb02496bd9fb8ae7eb11cfd98386daaac442f58" - integrity sha512-BFi3vZnO9X5Qt6NRz7ZOaPja3ic0PhlsmCRYLOpN11+mWBCR6XJDqW5RF3j8jm4WGGQZtBA+bTfxYzeKW73eHg== +pac-proxy-agent@^7.1.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/pac-proxy-agent/-/pac-proxy-agent-7.2.0.tgz#9cfaf33ff25da36f6147a20844230ec92c06e5df" + integrity sha512-TEB8ESquiLMc0lV8vcd5Ql/JAKAoyzHFXaStwjkzpOpC5Yv+pIzLfHvjTSdf3vpa2bMiUQrg9i6276yn8666aA== dependencies: "@tootallnate/quickjs-emscripten" "^0.23.0" - agent-base "^7.0.2" + agent-base "^7.1.2" debug "^4.3.4" get-uri "^6.0.1" http-proxy-agent "^7.0.0" - https-proxy-agent "^7.0.5" + https-proxy-agent "^7.0.6" pac-resolver "^7.0.1" - socks-proxy-agent "^8.0.4" + socks-proxy-agent "^8.0.5" pac-resolver@^7.0.1: version "7.0.1" @@ -450,18 +424,18 @@ progress@^2.0.3: integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== proxy-agent@^6.4.0: - version "6.4.0" - resolved "https://registry.yarnpkg.com/proxy-agent/-/proxy-agent-6.4.0.tgz#b4e2dd51dee2b377748aef8d45604c2d7608652d" - integrity sha512-u0piLU+nCOHMgGjRbimiXmA9kM/L9EHh3zL81xCdp7m+Y2pHIsnmbdDoEDoAz5geaonNR6q6+yOPQs6n4T6sBQ== + version "6.5.0" + resolved "https://registry.yarnpkg.com/proxy-agent/-/proxy-agent-6.5.0.tgz#9e49acba8e4ee234aacb539f89ed9c23d02f232d" + integrity sha512-TmatMXdr2KlRiA2CyDu8GqR8EjahTG3aY3nXjdzFyoZbmB8hrBsTyMezhULIXKnC0jpfjlmiZ3+EaCzoInSu/A== dependencies: - agent-base "^7.0.2" + agent-base "^7.1.2" debug "^4.3.4" http-proxy-agent "^7.0.1" - https-proxy-agent "^7.0.3" + https-proxy-agent "^7.0.6" lru-cache "^7.14.1" - pac-proxy-agent "^7.0.1" + pac-proxy-agent "^7.1.0" proxy-from-env "^1.1.0" - socks-proxy-agent "^8.0.2" + socks-proxy-agent "^8.0.5" proxy-from-env@^1.1.0: version "1.1.0" @@ -483,19 +457,19 @@ smart-buffer@^4.2.0: resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-4.2.0.tgz#6e1d71fa4f18c05f7d0ff216dd16a481d0e8d9ae" integrity sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg== -socks-proxy-agent@^8.0.2, socks-proxy-agent@^8.0.4: - version "8.0.4" - resolved "https://registry.yarnpkg.com/socks-proxy-agent/-/socks-proxy-agent-8.0.4.tgz#9071dca17af95f483300316f4b063578fa0db08c" - integrity sha512-GNAq/eg8Udq2x0eNiFkr9gRg5bA7PXEWagQdeRX4cPSG+X/8V38v637gim9bjFptMk1QWsCTr0ttrJEiXbNnRw== +socks-proxy-agent@^8.0.5: + version "8.0.5" + resolved "https://registry.yarnpkg.com/socks-proxy-agent/-/socks-proxy-agent-8.0.5.tgz#b9cdb4e7e998509d7659d689ce7697ac21645bee" + integrity sha512-HehCEsotFqbPW9sJ8WVYB6UbmIMv7kUUORIF2Nncq4VQvBfNBLibW9YZR5dlYCSUhwcD628pRllm7n+E+YTzJw== dependencies: - agent-base "^7.1.1" + agent-base "^7.1.2" debug "^4.3.4" socks "^2.8.3" socks@^2.8.3: - version "2.8.3" - resolved "https://registry.yarnpkg.com/socks/-/socks-2.8.3.tgz#1ebd0f09c52ba95a09750afe3f3f9f724a800cb5" - integrity sha512-l5x7VUUWbjVFbafGLxPWkYsHIhEvmF85tbIeFZWc8ZPtoMyybuEhL7Jye/ooC4/d48FgOjSJXgsF/AJPYCW8Zw== + version "2.8.4" + resolved "https://registry.yarnpkg.com/socks/-/socks-2.8.4.tgz#07109755cdd4da03269bda4725baa061ab56d5cc" + integrity sha512-D3YaD0aRxR3mEcqnidIs7ReYJFVzWdd6fXJYUM8ixcQcJRGTka/b3saV0KflYhyVJXKhb947GndU35SxYNResQ== dependencies: ip-address "^9.0.5" smart-buffer "^4.2.0" @@ -521,14 +495,9 @@ tslib@^2.0.1: integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w== undici@^6.19.5: - version "6.20.1" - resolved "https://registry.yarnpkg.com/undici/-/undici-6.20.1.tgz#fbb87b1e2b69d963ff2d5410a40ffb4c9e81b621" - integrity sha512-AjQF1QsmqfJys+LXfGTNum+qw4S88CojRInG/6t31W/1fk6G59s92bnAvGz5Cmur+kQv2SURXEvvudLmbrE8QA== - -universalify@^2.0.0: - version "2.0.1" - resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.1.tgz#168efc2180964e6386d061e094df61afe239b18d" - integrity sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw== + version "6.21.1" + resolved "https://registry.yarnpkg.com/undici/-/undici-6.21.1.tgz#336025a14162e6837e44ad7b819b35b6c6af0e05" + integrity sha512-q/1rj5D0/zayJB2FraXdaWxbhWiNKDvu8naDT2dl1yTlvJp4BLtOcp2a5BvgGNQpYYJzau7tf1WgKv3b+7mqpQ== validator@^13.11.0: version "13.12.0" diff --git a/markdown/tools/update_markdown_doc.sh b/markdown/tools/update_markdown_doc.sh index 92dfad58..fe1b483c 100755 --- a/markdown/tools/update_markdown_doc.sh +++ b/markdown/tools/update_markdown_doc.sh @@ -2,61 +2,67 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/fail.sh source "${fail_sh}" - # MARK - Process Args args=() while (("$#")); do case "${1}" in - "--marker_begin") - marker_begin="${2}" - shift 2 - ;; - "--marker_end") - marker_end="${2}" - shift 2 - ;; - "--marker") - marker="${2}" - shift 2 - [[ "${marker}" =~ :$ ]] || marker="${marker}:" - marker_begin="${marker} BEGIN" - marker_end="${marker} END" - ;; - "--update") - update_path="${2}" - shift 2 - ;; - --*) - fail "Unrecognized flag. ${1}" - ;; - *) - args+=("${1}") - shift 1 - ;; + "--marker_begin") + marker_begin="${2}" + shift 2 + ;; + "--marker_end") + marker_end="${2}" + shift 2 + ;; + "--marker") + marker="${2}" + shift 2 + [[ "${marker}" =~ :$ ]] || marker="${marker}:" + marker_begin="${marker} BEGIN" + marker_end="${marker} END" + ;; + "--update") + update_path="${2}" + shift 2 + ;; + --*) + fail "Unrecognized flag. ${1}" + ;; + *) + args+=("${1}") + shift 1 + ;; esac done [[ -z "${update_path:-}" ]] && fail "No update file was specified." -{ [[ -z "${marker_begin:-}" ]] || [[ -z "${marker_end:-}" ]]; } && \ +{ [[ -z "${marker_begin:-}" ]] || [[ -z "${marker_end:-}" ]]; } && fail "No markers were specified." [[ ${#args[@]} != 2 ]] && fail "Expected exactly two files: input and output." @@ -69,7 +75,7 @@ out_path="${args[1]}" cp -f "${in_path}" "${out_path}" # Update the output file replacing with the contents of update_path. -# +# # sed script explanation # # //{ # Find the begin marker diff --git a/markdown/tools/update_markdown_toc.sh b/markdown/tools/update_markdown_toc.sh index 05a3c51c..dec0269b 100755 --- a/markdown/tools/update_markdown_toc.sh +++ b/markdown/tools/update_markdown_toc.sh @@ -2,69 +2,72 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/fail.sh source "${fail_sh}" update_markdown_doc_sh_location=cgrindel_bazel_starlib/markdown/tools/update_markdown_doc.sh -update_markdown_doc_sh="$(rlocation "${update_markdown_doc_sh_location}")" || \ +update_markdown_doc_sh="$(rlocation "${update_markdown_doc_sh_location}")" || (echo >&2 "Failed to locate ${update_markdown_doc_sh_location}" && exit 1) generate_toc_location=cgrindel_bazel_starlib/markdown/tools/markdown_toc/cmd/generate_toc/generate_toc_/generate_toc -generate_toc="$(rlocation "${generate_toc_location}")" || \ +generate_toc="$(rlocation "${generate_toc_location}")" || (echo >&2 "Failed to locate ${generate_toc_location}" && exit 1) - - # MARK - Process args remove_toc_header_entry=true toc_header="Table of Contents" -generate_toc_cmd=( "${generate_toc}" --start-level=2 ) +generate_toc_cmd=("${generate_toc}" --start-level=2) args=() while (("$#")); do case "${1}" in - "--no_remove_toc_header_entry") - remove_toc_header_entry=false - shift 1 - ;; - "--toc_header") - toc_header="${2}" - shift 2 - ;; - --*) - fail "Unexpected flag ${1}" - ;; - *) - args+=("${1}") - shift 1 - ;; + "--no_remove_toc_header_entry") + remove_toc_header_entry=false + shift 1 + ;; + "--toc_header") + toc_header="${2}" + shift 2 + ;; + --*) + fail "Unexpected flag ${1}" + ;; + *) + args+=("${1}") + shift 1 + ;; esac done - [[ ${#args[@]} != 2 ]] && fail "Expected exactly two files: input and output." in_path="${args[0]}" out_path="${args[1]}" - # MARK - Generate the TOC -toc_dir_path="$( mktemp -d )" +toc_dir_path="$(mktemp -d)" toc_path="${toc_dir_path}/toc.md" cleanup() { @@ -72,30 +75,28 @@ cleanup() { } trap cleanup EXIT -# Generate the TOC -generate_toc_cmd+=( "${in_path}" ) -"${generate_toc_cmd[@]}" > "${toc_path}" - +# Generate the TOC +generate_toc_cmd+=("${in_path}") +"${generate_toc_cmd[@]}" >"${toc_path}" # MARK - Clean up the TOC # Set up the sed command -sed_cmd=( sed -i.bak -E ) +sed_cmd=(sed -i.bak -E) # Remove blank linkes -sed_cmd+=( -e '/^\s*$/d' ) +sed_cmd+=(-e '/^\s*$/d') # Remove the TOC header entry -[[ "${remove_toc_header_entry}" == true ]] && \ - sed_cmd+=( -e '/^[*] \['"${toc_header}"'\]/d' ) +[[ "${remove_toc_header_entry}" == true ]] && + sed_cmd+=(-e '/^[*] \['"${toc_header}"'\]/d') # Specify the path to the TOC. -sed_cmd+=( "${toc_path}" ) +sed_cmd+=("${toc_path}") # Execute the sed command "${sed_cmd[@]}" - # MARK - Update the markdown file with the TOC "${update_markdown_doc_sh}" \ diff --git a/shared.bazelrc b/shared.bazelrc index 54f04a77..63f02cab 100644 --- a/shared.bazelrc +++ b/shared.bazelrc @@ -24,11 +24,10 @@ build:cache --experimental_remote_cache_async build:cache --experimental_remote_cache_compression # Recommended by BuildBuddy -# TODO: Rename this to remote_build_event_upload once we are no longer supporting 6.x.x. -build --experimental_remote_build_event_upload=minimal -build --noslim_profile -build --experimental_profile_include_target_label -build --experimental_profile_include_primary_output +build --remote_build_event_upload=minimal +build --noslim_profile +build --experimental_profile_include_target_label +build --experimental_profile_include_primary_output build --nolegacy_important_outputs # Finish BES upload in the background. Disable BES upload when running. @@ -39,3 +38,6 @@ run --bes_results_url= # Easily run without caches common:no_cache --remote_cache= --disk_cache= --repository_cache= + +# Do not autoload any legacy symbols that are now provided in separate repos. +common --incompatible_autoload_externally= diff --git a/shlib/lib/BUILD.bazel b/shlib/lib/BUILD.bazel index e6ae6b1e..2c1dde23 100644 --- a/shlib/lib/BUILD.bazel +++ b/shlib/lib/BUILD.bazel @@ -48,11 +48,17 @@ sh_library( sh_library( name = "git", srcs = ["git.sh"], + data = [ + "//tools/git", + ], ) sh_library( name = "github", srcs = ["github.sh"], + data = [ + "@multitool//tools/gh", + ], ) # MARK: - Collect Files for Integation Tests diff --git a/shlib/lib/arrays.sh b/shlib/lib/arrays.sh index 1cb9b479..7ce7f897 100644 --- a/shlib/lib/arrays.sh +++ b/shlib/lib/arrays.sh @@ -13,7 +13,9 @@ cgrindel_bazel_shlib_lib_arrays_loaded() { return; } # stderr: None. sort_items() { local IFS=$'\n' - sort -u <<<"$*" + # Use LC_ALL=C to ensure that sort is in byte order. Keep things consistent on + # different systems. + LC_ALL=C sort -u <<<"$*" } # Prints the arguments with each argument on its own line. @@ -25,7 +27,7 @@ sort_items() { # stdout: A line per item. # stderr: None. print_by_line() { - for item in "${@:-}" ; do + for item in "${@:-}"; do echo "${item}" done } @@ -53,7 +55,7 @@ join_by() { # while (("$#")); do # items+=( $( echo "${1}" | base64) ) # shift 1 -# done +# done # echo "${items[@]}" # } # @@ -63,7 +65,7 @@ join_by() { # while (("$#")); do # items+=( $( echo "${1}" | base64 --decode) ) # shift 1 -# done +# done # echo "${items[@]}" # } @@ -79,7 +81,7 @@ double_quote_items() { while (("$#")); do echo "\"${1}\"" shift 1 - done + done } # Searches for the expected value in the follow-on arguments. If your list is sorted and has @@ -95,19 +97,19 @@ double_quote_items() { # Returns 0 if the expected value is found. Otherwise returns -1. contains_item() { # NOTE: The variables are purposefully short. Bash performance is greatly - # influenced by the number of variables and the length of their names. + # influenced by the number of variables and the length of their names. # x: expected value # Remember the expected value local x="${1}" shift - + # Do a quick regex to see if the value is in the rest of the args # If not, then don't bother looping [[ ! "${*}" =~ ${x} ]] && return 1 # Loop through items for a precise match - for it in "${@}" ; do + for it in "${@}"; do [[ "${it}" == "${x}" ]] && return 0 done @@ -115,8 +117,8 @@ contains_item() { return 1 } -# Searches for the expected value in the follow-on arguments. This function assumes that the list -# items are sorted and unique. Only use this function over 'contains_item' if you expect to have 40 +# Searches for the expected value in the follow-on arguments. This function assumes that the list +# items are sorted and unique. Only use this function over 'contains_item' if you expect to have 40 # or more items in your list. Check out //tools:contains_item_perf_comparison to run some comparisons # between this function and contains_item. # @@ -130,7 +132,7 @@ contains_item() { # Returns 0 if the expected value is found. Otherwise returns -1. contains_item_sorted() { # NOTE: The variables are purposefully short. Bash performance is greatly - # influenced by the number of variables and the length of their names. + # influenced by the number of variables and the length of their names. # Removed count var - Fastest (0.191s vs 0.214s contains_item) # x: expected value # s: start index @@ -151,11 +153,11 @@ contains_item_sorted() { while true; do # Find midpoint - local m=$(( s + (e - s + 1)/2 )) + local m=$((s + (e - s + 1) / 2)) # If the midpoint value (!m) is the expected, found it local mv="${!m}" - [[ "${x}" == "${mv}" ]] && return + [[ "${x}" == "${mv}" ]] && return # If the start index and end index are the same, finished searching [[ $s -eq $e ]] && return 1 @@ -163,10 +165,10 @@ contains_item_sorted() { # Update the start/end index based upon whether the expected is greater # than or less than the midpoint value. if [[ "${x}" < "${mv}" ]]; then - local e=$(( m - 1 )) + local e=$((m - 1)) else [[ $m -eq $e ]] && return 1 - local s=$(( m + 1 )) + local s=$((m + 1)) fi done } diff --git a/shlib/lib/assertions.sh b/shlib/lib/assertions.sh index 064d8dab..8e30abeb 100644 --- a/shlib/lib/assertions.sh +++ b/shlib/lib/assertions.sh @@ -23,12 +23,11 @@ fail() { make_err_msg() { local err_msg="${1}" local prefix="${2:-}" - [[ -z "${prefix}" ]] || \ + [[ -z ${prefix} ]] || local err_msg="${prefix} ${err_msg}" echo "${err_msg}" } - # Asserts that the actual value equals the expected value. # # Args: @@ -43,8 +42,27 @@ assert_equal() { local expected="${1}" local actual="${2}" local err_msg - err_msg="$(make_err_msg "Expected to be equal. expected: ${expected}, actual: ${actual}" "${3:-}")" - [[ "${expected}" == "${actual}" ]] || fail "${err_msg}" + if [[ ${expected} != "${actual}" ]]; then + local diff_output + diff_output=$(diff <(echo "${expected}") <(echo "${actual}") 2>/dev/null || + true) + if [[ -n ${diff_output} ]]; then + err_msg="$(make_err_msg "Expected to be equal. +Expected: +${expected} +Actual: +${actual} +Diff (expected vs actual): +${diff_output}" "${3:-}")" + else + err_msg="$(make_err_msg "Expected to be equal. +Expected: +${expected} +Actual: +${actual}" "${3:-}")" + fi + fail "${err_msg}" + fi } # Asserts that the actual value contains the specified regex pattern. @@ -62,7 +80,7 @@ assert_match() { local actual="${2}" local err_msg err_msg="$(make_err_msg "Expected to match. pattern: ${pattern}, actual: ${actual}" "${3:-}")" - [[ "${actual}" =~ ${pattern} ]] || fail "${err_msg}" + [[ ${actual} =~ ${pattern} ]] || fail "${err_msg}" } # Asserts that the actual value does not contain the specified regex pattern. @@ -80,7 +98,7 @@ assert_no_match() { local actual="${2}" local err_msg err_msg="$(make_err_msg "Expected not to match. pattern: ${pattern}, actual: ${actual}" "${3:-}")" - [[ "${actual}" =~ ${pattern} ]] && fail "${err_msg}" + [[ ${actual} =~ ${pattern} ]] && fail "${err_msg}" # Because this is a negative test, we need to end on a positive note if all is well. echo "" } diff --git a/shlib/lib/env.sh b/shlib/lib/env.sh index 1b3592e3..8468400e 100644 --- a/shlib/lib/env.sh +++ b/shlib/lib/env.sh @@ -8,6 +8,5 @@ cgrindel_bazel_starlib_lib_private_env_loaded() { return; } # Succeeds if the specified executable is found in the path. Otherwise, it fails. is_installed() { local name="${1}" - which "${name}" > /dev/null + which "${name}" >/dev/null } - diff --git a/shlib/lib/fail.sh b/shlib/lib/fail.sh index 411217f4..8107d872 100644 --- a/shlib/lib/fail.sh +++ b/shlib/lib/fail.sh @@ -1,40 +1,37 @@ #!/usr/bin/env bash -# Echos the provided message to stderr and exits with an error (1). -fail() { - local msg="${1:-}" - shift 1 - while (("$#")); do - msg="${msg:-}"$'\n'"${1}" - shift 1 - done - echo >&2 "${msg}" - exit 1 +do_exit() { + local exit_code=${1:-0} + exit "${exit_code}" } # Prints the message to stderr. warn() { - # local msg="${1}" - msg="WARNING: ${1}" - shift 1 - while (("$#")); do - msg="${msg}"$'\n'"${1}" - shift 1 - done - echo >&2 "${msg}" + if [[ ${#} -gt 0 ]]; then + echo >&2 "${@}" + else + cat >&2 + fi +} + +# Echos the provided message to stderr and exits with an error (1). +fail() { + local cmd=(warn) + if [[ ${#} -gt 0 ]]; then + cmd+=("${@}") + fi + "${cmd[@]}" + do_exit 1 } # Print an error message and dump the usage/help for the utility. # This function expects a get_usage function to be defined. usage_error() { - local msg="${1:-}" - cmd=(fail) - [[ -z "${msg:-}" ]] || cmd+=("${msg}" "") - cmd+=("$(get_usage)") - "${cmd[@]}" + [[ ${#} -gt 0 ]] && warn "${@}" + fail "$(get_usage)" } show_usage() { get_usage - exit 0 + do_exit 0 } diff --git a/shlib/lib/files.sh b/shlib/lib/files.sh index 3be14514..b718d38a 100644 --- a/shlib/lib/files.sh +++ b/shlib/lib/files.sh @@ -4,19 +4,26 @@ if [[ $(type -t rlocation) != function ]]; then # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. - set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e + set -uo pipefail + set +e + 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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } + f= + set -e # --- end runfiles.bash initialization v3 --- fi if [[ $(type -t cgrindel_bazel_shlib_lib_paths_loaded) != function ]]; then paths_sh_location=cgrindel_bazel_starlib/shlib/lib/paths.sh - paths_sh="$(rlocation "${paths_sh_location}")" || \ + paths_sh="$(rlocation "${paths_sh_location}")" || (echo >&2 "Failed to locate ${paths_sh_location}" && exit 1) # shellcheck disable=SC1090 # external source source "${paths_sh}" @@ -25,18 +32,17 @@ fi # This is used to determine if the library has been loaded cgrindel_bazel_shlib_lib_files_loaded() { return; } - # Recursively searches for a file starting from the current directory up to the root of the filesystem. # # Flags: # --start_dir: The directory where to start the search. # --error_if_not_found: If specified, the function will return 1 if the file is not found. -# +# # Args: # target_file: The basename for the file to be found. # # Outputs: -# stdout: The fully-qualified path to the +# stdout: The fully-qualified path to the # stderr: None. upsearch() { # Lovingly inspired by https://unix.stackexchange.com/a/13474. @@ -46,19 +52,19 @@ upsearch() { local args=() while (("$#")); do case "${1}" in - "--start_dir") - local start_dir - start_dir="$(normalize_path "${2}")" - shift 2 - ;; - "--error_if_not_found") - local error_if_not_found=1 - shift 1 - ;; - *) - args+=( "${1}" ) - shift 1 - ;; + "--start_dir") + local start_dir + start_dir="$(normalize_path "${2}")" + shift 2 + ;; + "--error_if_not_found") + local error_if_not_found=1 + shift 1 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -66,11 +72,10 @@ upsearch() { slashes=${start_dir//[^\/]/} directory="${start_dir}" - for (( n=${#slashes}; n>0; --n )) - do + for ((n = ${#slashes}; n > 0; --n)); do local test_path="${directory}/${target_file}" - test -e "${test_path}" && \ - normalize_path "${test_path}" && return + test -e "${test_path}" && + normalize_path "${test_path}" && return directory="${directory}/.." done @@ -79,4 +84,3 @@ upsearch() { return 1 fi } - diff --git a/shlib/lib/git.sh b/shlib/lib/git.sh index dbe7986e..5064a093 100644 --- a/shlib/lib/git.sh +++ b/shlib/lib/git.sh @@ -2,8 +2,9 @@ # Git-related Functions -# This is used to determine if the library has been loaded -cgrindel_bazel_starlib_lib_private_git_loaded() { return; } +git_exe_location=cgrindel_bazel_starlib/tools/git/git.exe +git="$(rlocation "${git_exe_location}")" || + (echo >&2 "Failed to locate ${git_exe_location}" && exit 1) # MARK - Default Values @@ -11,22 +12,22 @@ remote=origin # Returns the URL for the git repository. It is typically in the form: # git@github.com:cgrindel/bazel-starlib.git -# OR +# OR # https://github.com/cgrindel/bazel-starlib.git get_git_remote_url() { - git config --get remote.origin.url + "${git}" config --get remote.origin.url } # Fetch the latest info from the remote. -fetch_latest_from_git_remote() { +fetch_latest_from_git_remote() { local remote="${1:-}" local branch="${2:-}" - fetch_cmd=(git fetch) + fetch_cmd=("${git}" fetch) if [[ -n "${remote:-}" ]]; then - fetch_cmd+=( "${remote}" ) - [[ -z "${branch:-}" ]] || fetch_cmd+=( "${branch}" ) + fetch_cmd+=("${remote}") + [[ -z "${branch:-}" ]] || fetch_cmd+=("${branch}") fi - "${fetch_cmd[@]}" 2> /dev/null + "${fetch_cmd[@]}" 2>/dev/null } # MARK - Tag Functions @@ -39,34 +40,33 @@ is_valid_release_tag() { # Returns the commit hash for the provided branch or tag. get_git_commit_hash() { local branch="${1:-}" - git log -n 1 --pretty=format:'%H' "${branch:-}" + "${git}" log -n 1 --pretty=format:'%H' "${branch:-}" } # Returns the list of release tags sorted by most recent to oldest. get_git_release_tags() { local tags=() while IFS=$'\n' read -r line; do tags+=("$line"); done < <( - git tag --sort=refname -l + "${git}" tag --sort=refname -l ) [[ ${#tags[@]} == 0 ]] && return local release_tags=() - for tag in "${tags[@]}" ; do - is_valid_release_tag "${tag}" && release_tags+=( "${tag}" ) + for tag in "${tags[@]}"; do + is_valid_release_tag "${tag}" && release_tags+=("${tag}") done - for release_tag in "${release_tags[@]}" ; do + for release_tag in "${release_tags[@]}"; do echo "${release_tag}" done } git_tag_exists() { local target_tag="${1}" - # local tags=( $(git tag) ) local tags=() while IFS=$'\n' read -r line; do tags+=("$line"); done < <( - git tag + "${git}" tag ) # Make sure that the for loop variable is not tag or something else common. - for cur_tag in "${tags[@]}" ; do + for cur_tag in "${tags[@]}"; do [[ "${cur_tag}" == "${target_tag}" ]] && return done return 1 @@ -76,8 +76,8 @@ create_git_tag() { local tag="${1}" local msg="${2}" local commit="${3:-}" - git_tag_cmd=(git tag -a -m "${msg}" "${tag}") - [[ -z "${commit:-}" ]] || git_tag_cmd+=( "${commit}" ) + git_tag_cmd=("${git}" tag -a -m "${msg}" "${tag}") + [[ -z "${commit:-}" ]] || git_tag_cmd+=("${commit}") "${git_tag_cmd[@]}" } @@ -85,37 +85,36 @@ create_git_release_tag() { local tag="${1}" local commit="${2:-}" msg="Release ${tag}" - git_tag_cmd=( create_git_tag "${tag}" "${msg}" ) - [[ -z "${commit:-}" ]] || git_tag_cmd+=( "${commit}" ) + git_tag_cmd=(create_git_tag "${tag}" "${msg}") + [[ -z "${commit:-}" ]] || git_tag_cmd+=("${commit}") "${git_tag_cmd[@]}" } git_tag_exists_on_remote() { local tag="${1}" local remote="${2:-origin}" - git ls-remote --exit-code "${remote}" "refs/tags/${tag}" > /dev/null + "${git}" ls-remote --exit-code "${remote}" "refs/tags/${tag}" >/dev/null } delete_git_tag() { local tag="${1}" - git tag -d "${tag}" > /dev/null + "${git}" tag -d "${tag}" >/dev/null } push_git_tag_to_remote() { local tag="${1}" local remote="${2:-origin}" - git push "${remote}" "${tag}" + "${git}" push "${remote}" "${tag}" } delete_git_tag_on_remote() { local tag="${1}" local remote="${2:-origin}" - git push --delete "${remote}" "${tag}" > /dev/null + "${git}" push --delete "${remote}" "${tag}" >/dev/null } - # MARK - Branch Functions get_current_branch_name() { - git rev-parse --abbrev-ref HEAD + "${git}" rev-parse --abbrev-ref HEAD } diff --git a/shlib/lib/github.sh b/shlib/lib/github.sh index aab848e1..97b7db3b 100644 --- a/shlib/lib/github.sh +++ b/shlib/lib/github.sh @@ -2,15 +2,16 @@ # Github-related Functions -# This is used to determine if the library has been loaded -cgrindel_bazel_starlib_lib_private_github_loaded() { return; } +gh_location=multitool/tools/gh/gh +gh="$(rlocation "${gh_location}")" || + (echo >&2 "Failed to locate ${gh_location}" && exit 1) # MARK - Github Auth Status Functions # Returns the raw gh auth status displyaing the auth token. # Doc: https://cli.github.com/manual/gh_auth_status get_gh_auth_status() { - gh auth status -t 2>&1 + "${gh}" auth status -t 2>&1 } # Example gh auth status: @@ -23,16 +24,16 @@ get_gh_auth_status() { # Returns the current user's username from the auth status. get_gh_username() { local auth_status="${1:-}" - [[ -z "${auth_status}" ]] && auth_status="$( get_gh_auth_status )" - echo "${auth_status}" | \ + [[ -z "${auth_status}" ]] && auth_status="$(get_gh_auth_status)" + echo "${auth_status}" | sed -E -n 's/^.* Logged in to [^[:space:]]+ account ([^[:space:]]+).*/\1/gp' } # Returns the current user's auth token from the auth status. get_gh_auth_token() { local auth_status="${1:-}" - [[ -z "${auth_status}" ]] && auth_status="$( get_gh_auth_status )" - echo "${auth_status}" | \ + [[ -z "${auth_status}" ]] && auth_status="$(get_gh_auth_status)" + echo "${auth_status}" | sed -E -n 's/^.* Token:[[:space:]]+([^[:space:]]+).*/\1/gp' } @@ -62,7 +63,7 @@ _github_url_owner_sed_cmds+=('s|.*github.com/([^/]+)/.*|\1|gp') # owner and repo name. _get_github_repo_pattern_index() { local repo_url="${1}" - for (( i = 0; i < ${#_github_url_patterns[@]}; i++ )); do + for ((i = 0; i < ${#_github_url_patterns[@]}; i++)); do pattern="${_github_url_patterns[$i]}" [[ "${repo_url}" =~ ${pattern} ]] && echo $i && return done @@ -72,14 +73,14 @@ _get_github_repo_pattern_index() { # Succeeds if the URL is a Github repo URL. Otherwise, it fails. is_github_repo_url() { local repo_url="${1}" - _get_github_repo_pattern_index "${repo_url}" > /dev/null + _get_github_repo_pattern_index "${repo_url}" >/dev/null } # Return the Github repository owner from the repository URL. get_gh_repo_owner() { local repo_url="${1}" local pattern_index - pattern_index=$( _get_github_repo_pattern_index "${repo_url}" ) + pattern_index=$(_get_github_repo_pattern_index "${repo_url}") local sed_cmd="${_github_url_owner_sed_cmds[${pattern_index}]}" echo "${repo_url}" | sed -E -n "${sed_cmd}" } @@ -93,7 +94,7 @@ get_gh_repo_name() { # Succeeds if the Github release exists. Otherwise, it fails. gh_release_exists() { local tag="${1}" - gh release view "${tag}" 2> /dev/null + "${gh}" release view "${tag}" 2>/dev/null } # MARK - Github API Functions @@ -102,9 +103,9 @@ gh_release_exists() { get_gh_api_base_url() { local repo_url="${1}" local owner - owner="$( get_gh_repo_owner "${repo_url}" )" + owner="$(get_gh_repo_owner "${repo_url}")" local name - name="$( get_gh_repo_name "${repo_url}" )" + name="$(get_gh_repo_name "${repo_url}")" echo "https://api.github.com/repos/${owner}/${name}" } @@ -116,15 +117,15 @@ get_gh_changelog() { local api_args=(--method POST) while (("$#")); do case "${1}" in - --*) - # Add the arg name and the value to the api args array - api_args+=(-F "${1:2}=${2}") - shift 2 - ;; - *) - args+=("${1}") - shift 1 - ;; + --*) + # Add the arg name and the value to the api args array + api_args+=(-F "${1:2}=${2}") + shift 2 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -132,5 +133,60 @@ get_gh_changelog() { [[ ${#api_args[@]} == 0 ]] && fail "Expected one or more API args." # Execute the API call - gh api "repos/{owner}/{repo}/releases/generate-notes" "${api_args[@]}" --jq '.body' + "${gh}" api "repos/{owner}/{repo}/releases/generate-notes" "${api_args[@]}" --jq '.body' +} + +get_gh_changelog_organized() { + local all_changes=() + while IFS=$'\n' read -r line; do all_changes+=("$line"); done < <( + get_gh_changelog "${@}" + ) + + local top_lines=() + local dep_lines=() + local other_lines=() + local full_changelog + for line in "${all_changes[@]}"; do + if [[ "${line}" =~ ^[*][\ ]+[a-z]+: ]]; then + top_lines+=("${line}") + elif [[ "${line}" =~ ^[*][\ ]+[a-z]+\(deps\): ]]; then + dep_lines+=("${line}") + elif [[ "${line}" =~ ^[*][*]Full\ Changelog ]]; then + full_changelog="${line}" + elif [[ ! "${line}" =~ ^[\ ]*$ ]] && [[ ! "${line}" =~ ^# ]]; then + other_lines+=("${line}") + fi + done + + local all_output=("## What's Changed" "") + if [[ "${#top_lines[@]}" -gt 0 ]]; then + all_output+=( + "### Highlights" + "" + "${top_lines[@]}" + "" + ) + fi + if [[ "${#dep_lines[@]}" -gt 0 ]]; then + all_output+=( + "### Dependency Updates" + "" + "${dep_lines[@]}" + "" + ) + fi + if [[ "${#other_lines[@]}" -gt 0 ]]; then + all_output+=( + "### Other Changes" + "" + "${other_lines[@]}" + "" + ) + fi + if [[ -n "${full_changelog:-}" ]]; then + all_output+=("${full_changelog}") + fi + if [[ "${#all_output[@]}" -gt 0 ]]; then + printf "%s\n" "${all_output[@]}" + fi } diff --git a/shlib/lib/messages.sh b/shlib/lib/messages.sh index b3d69e70..3d494ca3 100644 --- a/shlib/lib/messages.sh +++ b/shlib/lib/messages.sh @@ -8,7 +8,7 @@ cgrindel_bazel_shlib_lib_messages_loaded() { return; } # Flags: # --exit_code: Used to specify the exit code to return/exit. # --no_exit: If specified, the function will `return` the exit code instead of calling `exit`. -# +# # Args: # *: All of the collected args are combined to create an error message. If no values are # specified, then a default error message is used. @@ -23,19 +23,19 @@ exit_with_msg() { local args=() while (("$#")); do case "${1}" in - "--exit_code") - local exit_code - exit_code=$(($2)) - shift 2 - ;; - "--no_exit") - local no_exit=1 - shift 1 - ;; - *) - args+=("${1}") - shift 1 - ;; + "--exit_code") + local exit_code + exit_code=$(($2)) + shift 2 + ;; + "--no_exit") + local no_exit=1 + shift 1 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -48,4 +48,3 @@ exit_with_msg() { fi exit ${exit_code} } - diff --git a/shlib/lib/paths.sh b/shlib/lib/paths.sh index 39e44626..df41aab2 100644 --- a/shlib/lib/paths.sh +++ b/shlib/lib/paths.sh @@ -21,11 +21,10 @@ normalize_path() { local basename basename="$(basename "${path}")" fi - dirname="$(cd "${dirname}" > /dev/null && pwd)" + dirname="$(cd "${dirname}" >/dev/null && pwd)" if [[ -z "${basename:-}" ]]; then echo "${dirname}" else echo "${dirname}/${basename}" fi } - diff --git a/shlib/rules/private/execute_binary.bzl b/shlib/rules/private/execute_binary.bzl index dd037bcb..311a257a 100644 --- a/shlib/rules/private/execute_binary.bzl +++ b/shlib/rules/private/execute_binary.bzl @@ -5,7 +5,7 @@ load(":execute_binary_utils.bzl", "execute_binary_utils") file_placeholder = execute_binary_utils.file_placeholder def _create_file_args_placeholder_dict(ctx): - return {p: fa.files.to_list()[0] for fa, p in ctx.attr.file_arguments.items()} + return {p: fa[DefaultInfo].files.to_list()[0] for fa, p in ctx.attr.file_arguments.items()} def _execute_binary_impl(ctx): if len(ctx.attr.args) > 0: diff --git a/shlib/tools/contains_item_perf_comparison.sh b/shlib/tools/contains_item_perf_comparison.sh index 6db60bf7..075a3f45 100755 --- a/shlib/tools/contains_item_perf_comparison.sh +++ b/shlib/tools/contains_item_perf_comparison.sh @@ -2,13 +2,20 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- arrays_lib="$(rlocation cgrindel_bazel_starlib/shlib/lib/arrays.sh)" @@ -21,27 +28,27 @@ test_iterations=${1:-100} create_array() { local item_count=${1} - local max_val=$(( item_count - 1 )) - local width=$(( ${#max_val} )) + local max_val=$((item_count - 1)) + local width=$((${#max_val})) local output=() local val=0 - for (( ; val < item_count; val++ )); do - output+=( "$(printf "%0${width}d" $val)" ) + for (( ; val < item_count; val++)); do + output+=("$(printf "%0${width}d" $val)") done print_by_line "${output[@]}" } do_contains_item_perf_test() { - for (( i = 0; i < test_iterations; i++ )); do - for item in "${@}" ; do + for ((i = 0; i < test_iterations; i++)); do + for item in "${@}"; do contains_item "${item}" "${@}" done done } do_contains_item_sorted_perf_test() { - for (( i = 0; i < test_iterations; i++ )); do - for item in "${@}" ; do + for ((i = 0; i < test_iterations; i++)); do + for item in "${@}"; do contains_item_sorted "${item}" "${@}" done done @@ -51,15 +58,15 @@ echo "Test iterations: ${test_iterations}" echo "" array_sizes=(25 30 35 40 45 50) -for size in "${array_sizes[@]}" ; do - echo "array size: ${size}" +for size in "${array_sizes[@]}"; do + echo "array size: ${size}" array=() while IFS=$'\n' read -r line; do array+=("$line"); done < <( create_array "${size}" ) - contains_item_time="$( (time do_contains_item_perf_test "${array[@]}") 2>&1 )" - contains_item_sorted_time="$( (time do_contains_item_sorted_perf_test "${array[@]}") 2>&1 )" - echo "contains_item: ${contains_item_time}" - echo "contains_item_sorted: ${contains_item_sorted_time}" + contains_item_time="$( (time do_contains_item_perf_test "${array[@]}") 2>&1)" + contains_item_sorted_time="$( (time do_contains_item_sorted_perf_test "${array[@]}") 2>&1)" + echo "contains_item: ${contains_item_time}" + echo "contains_item_sorted: ${contains_item_sorted_time}" echo "" done diff --git a/tests/bzlformat_tests/tools_tests/buildifier_test.sh b/tests/bzlformat_tests/tools_tests/buildifier_test.sh index 64c8880d..31f2bc0d 100755 --- a/tests/bzlformat_tests/tools_tests/buildifier_test.sh +++ b/tests/bzlformat_tests/tools_tests/buildifier_test.sh @@ -2,28 +2,34 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/assertions.sh source "${assertions_sh}" buildifier_sh_location=cgrindel_bazel_starlib/bzlformat/tools/buildifier.sh -buildifier_sh="$(rlocation "${buildifier_sh_location}")" || \ +buildifier_sh="$(rlocation "${buildifier_sh_location}")" || (echo >&2 "Failed to locate ${buildifier_sh_location}" && exit 1) - # MARK - Constants out_path=result.bzl @@ -40,7 +46,6 @@ cat >"${dep_z_path}" <<-'EOF' ZZZ_LIST = [] EOF - cat >"${bad_bzl_path}" <<-'EOF' load(":zzz.bzl", "ZZZ_LIST") load(":aaa.bzl", "AAA_LIST") @@ -51,10 +56,10 @@ FOO_LIST = [ ] + AAA_LIST + ZZZ_LIST EOF +# MARK - Test With Defaults -# MARK - Test With Defaults - -expected="$(cat <<-'EOF' +expected="$( + cat <<-'EOF' load(":aaa.bzl", "AAA_LIST") load(":zzz.bzl", "ZZZ_LIST") @@ -66,13 +71,13 @@ EOF )" "${buildifier_sh}" "${bad_bzl_path}" "${out_path}" -actual="$(< "${out_path}")" +actual="$(<"${out_path}")" assert_equal "${expected}" "${actual}" "With defaults" - # MARK - Test Format Only (lint: off) -expected="$(cat <<-'EOF' +expected="$( + cat <<-'EOF' load(":aaa.bzl", "AAA_LIST") load(":zzz.bzl", "ZZZ_LIST") @@ -84,13 +89,13 @@ EOF )" "${buildifier_sh}" --lint_mode off "${bad_bzl_path}" "${out_path}" -actual="$(< "${out_path}")" +actual="$(<"${out_path}")" assert_equal "${expected}" "${actual}" "Format only." - # MARK - Test Lint Fix (lint: fix) -expected="$(cat <<-'EOF' +expected="$( + cat <<-'EOF' load(":aaa.bzl", "AAA_LIST") load(":zzz.bzl", "ZZZ_LIST") @@ -102,13 +107,13 @@ EOF )" "${buildifier_sh}" --lint_mode fix "${bad_bzl_path}" "${out_path}" -actual="$(< "${out_path}")" +actual="$(<"${out_path}")" assert_equal "${expected}" "${actual}" "Format and lint fix." - # MARK - Test Lint Warn (lint: warn) With Bad File -expected="$(cat <<-'EOF' +expected="$( + cat <<-'EOF' load(":aaa.bzl", "AAA_LIST") load(":zzz.bzl", "ZZZ_LIST") @@ -122,10 +127,9 @@ EOF exit_code=0 "${buildifier_sh}" --lint_mode warn "${bad_bzl_path}" "${out_path}" || exit_code=$? assert_equal 4 ${exit_code} "Expected check mode failure (4)." -actual="$(< "${out_path}")" +actual="$(<"${out_path}")" assert_equal "${expected}" "${actual}" "Format and lint (warn) with bad file." - # MARK - Test Lint Warn (lint: warn) With Good File cat >"${good_bzl_path}" <<-'EOF' @@ -140,7 +144,8 @@ FOO_LIST = [ ] + AAA_LIST + ZZZ_LIST EOF -expected="$(cat <<-'EOF' +expected="$( + cat <<-'EOF' """Module doc comment.""" load(":aaa.bzl", "AAA_LIST") @@ -154,11 +159,10 @@ EOF )" "${buildifier_sh}" --lint_mode warn "${good_bzl_path}" "${out_path}" -actual="$(< "${out_path}")" +actual="$(<"${out_path}")" assert_equal "${expected}" "${actual}" "Format and lint (warn) with good file." - # MARK - Test Help -output="$( "${buildifier_sh}" --help )" +output="$("${buildifier_sh}" --help)" assert_match "Executes buildifier for a Starlark file" "${output}" "Confirm help output." diff --git a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/common_tests/normalize_pkg_test.sh b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/common_tests/normalize_pkg_test.sh index 75ab941d..1c9ff0cc 100755 --- a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/common_tests/normalize_pkg_test.sh +++ b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/common_tests/normalize_pkg_test.sh @@ -2,13 +2,20 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_lib="$(rlocation cgrindel_bazel_starlib/shlib/lib/assertions.sh)" diff --git a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/missing_pkgs_test.sh b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/missing_pkgs_test.sh index 7c0d1cee..a93ee0ab 100755 --- a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/missing_pkgs_test.sh +++ b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/missing_pkgs_test.sh @@ -2,39 +2,46 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" paths_sh_location=cgrindel_bazel_starlib/shlib/lib/paths.sh -paths_sh="$(rlocation "${paths_sh_location}")" || \ +paths_sh="$(rlocation "${paths_sh_location}")" || (echo >&2 "Failed to locate ${paths_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/paths.sh source "${paths_sh}" messages_sh_location=cgrindel_bazel_starlib/shlib/lib/messages.sh -messages_sh="$(rlocation "${messages_sh_location}")" || \ +messages_sh="$(rlocation "${messages_sh_location}")" || (echo >&2 "Failed to locate ${messages_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/messages.sh source "${messages_sh}" buildozer_location=buildifier_prebuilt/buildozer/buildozer -buildozer="$(rlocation "${buildozer_location}")" || \ +buildozer="$(rlocation "${buildozer_location}")" || (echo >&2 "Failed to locate ${buildozer_location}" && exit 1) create_scratch_dir_sh_location=rules_bazel_integration_test/tools/create_scratch_dir.sh -create_scratch_dir_sh="$(rlocation "${create_scratch_dir_sh_location}")" || \ +create_scratch_dir_sh="$(rlocation "${create_scratch_dir_sh_location}")" || (echo >&2 "Failed to locate ${create_scratch_dir_sh_location}" && exit 1) bazel="${BIT_BAZEL_BINARY:-}" @@ -43,9 +50,9 @@ workspace_dir="${BIT_WORKSPACE_DIR:-}" # Process args while (("$#")); do case "${1}" in - *) - shift 1 - ;; + *) + shift 1 + ;; esac done @@ -66,7 +73,7 @@ while IFS=$'\n' read -r line; do missing_pkgs+=("$line"); done < <( assert_msg="Missing packages, no exclusions" expected_array=(// //foo //foo/bar) assert_equal ${#expected_array[@]} ${#missing_pkgs[@]} "${assert_msg}" -for (( i = 0; i < ${#expected_array[@]}; i++ )); do +for ((i = 0; i < ${#expected_array[@]}; i++)); do assert_equal "${expected_array[${i}]}" "${missing_pkgs[${i}]}" "${assert_msg}[${i}]" done @@ -86,7 +93,7 @@ while IFS=$'\n' read -r line; do missing_pkgs+=("$line"); done < <( assert_msg="Missing packages, with exclusions" expected_array=(// //foo/bar) assert_equal ${#expected_array[@]} ${#missing_pkgs[@]} "${assert_msg}" -for (( i = 0; i < ${#expected_array[@]}; i++ )); do +for ((i = 0; i < ${#expected_array[@]}; i++)); do assert_equal "${expected_array[${i}]}" "${missing_pkgs[${i}]}" "${assert_msg}[${i}]" done @@ -101,7 +108,7 @@ assert_msg="Update missing packages, with exclusions" # will parse each space-separated item. expected_array=("Updating the following packages:" // //foo/bar) assert_equal ${#expected_array[@]} ${#fix_pkgs[@]} "${assert_msg}" -for (( i = 0; i < ${#expected_array[@]}; i++ )); do +for ((i = 0; i < ${#expected_array[@]}; i++)); do assert_equal "${expected_array[${i}]}" "${fix_pkgs[${i}]}" "${assert_msg}[${i}]" done @@ -117,7 +124,7 @@ while IFS=$'\n' read -r line; do missing_pkgs+=("$line"); done < <( assert_msg="Missing packages after removing exclusions" expected_array=(//foo) assert_equal ${#expected_array[@]} ${#missing_pkgs[@]} "${assert_msg}" -for (( i = 0; i < ${#expected_array[@]}; i++ )); do +for ((i = 0; i < ${#expected_array[@]}; i++)); do assert_equal "${expected_array[${i}]}" "${missing_pkgs[${i}]}" "${assert_msg}[${i}]" done @@ -130,7 +137,7 @@ assert_msg="Update missing packages after removing exclusions" # will parse each space-separated item. expected_array=("Updating the following packages:" //foo) assert_equal ${#expected_array[@]} ${#fix_pkgs[@]} "${assert_msg}" -for (( i = 0; i < ${#expected_array[@]}; i++ )); do +for ((i = 0; i < ${#expected_array[@]}; i++)); do assert_equal "${expected_array[${i}]}" "${fix_pkgs[${i}]}" "${assert_msg}[${i}]" done @@ -143,7 +150,7 @@ while IFS=$'\n' read -r line; do missing_pkgs+=("$line"); done < <( assert_msg="Expect no missing packages" expected_array=() assert_equal ${#expected_array[@]} ${#missing_pkgs[@]} "${assert_msg}" -for (( i = 0; i < ${#expected_array[@]}; i++ )); do +for ((i = 0; i < ${#expected_array[@]}; i++)); do assert_equal "${expected_array[${i}]}" "${missing_pkgs[${i}]}" "${assert_msg}[${i}]" done @@ -156,6 +163,6 @@ assert_msg="Update with no missing packages" # will parse each space-separated item. expected_array=("No missing package updates were found.") assert_equal ${#expected_array[@]} ${#fix_pkgs[@]} "${assert_msg}" -for (( i = 0; i < ${#expected_array[@]}; i++ )); do +for ((i = 0; i < ${#expected_array[@]}; i++)); do assert_equal "${expected_array[${i}]}" "${fix_pkgs[${i}]}" "${assert_msg}[${i}]" done diff --git a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/MODULE.bazel b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/MODULE.bazel index 6dfc2e96..81e79ae8 100644 --- a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/MODULE.bazel +++ b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/MODULE.bazel @@ -9,5 +9,5 @@ local_path_override( path = "../../../../..", ) -bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "bazel_skylib", version = "1.8.2") bazel_dep(name = "rules_shell", version = "0.3.0") diff --git a/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/generate_release_notes_test.sh b/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/generate_release_notes_test.sh index 744b445c..86aca987 100755 --- a/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/generate_release_notes_test.sh +++ b/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/generate_release_notes_test.sh @@ -2,31 +2,38 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" setup_git_repo_sh_location=cgrindel_bazel_starlib/tests/setup_git_repo.sh -setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || \ +setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || (echo >&2 "Failed to locate ${setup_git_repo_sh_location}" && exit 1) generate_release_notes_with_template_sh_location=cgrindel_bazel_starlib/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/generate_release_notes_with_template.sh -generate_release_notes_with_template_sh="$(rlocation "${generate_release_notes_with_template_sh_location}")" || \ +generate_release_notes_with_template_sh="$(rlocation "${generate_release_notes_with_template_sh_location}")" || (echo >&2 "Failed to locate ${generate_release_notes_with_template_sh_location}" && exit 1) generate_release_notes_with_workspace_name_sh_location=cgrindel_bazel_starlib/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/generate_release_notes_with_workspace_name.sh -generate_release_notes_with_workspace_name_sh="$(rlocation "${generate_release_notes_with_workspace_name_sh_location}")" || \ +generate_release_notes_with_workspace_name_sh="$(rlocation "${generate_release_notes_with_workspace_name_sh_location}")" || (echo >&2 "Failed to locate ${generate_release_notes_with_workspace_name_sh_location}" && exit 1) # MARK - Setup @@ -34,19 +41,18 @@ generate_release_notes_with_workspace_name_sh="$(rlocation "${generate_release_n # shellcheck source=SCRIPTDIR/../../../setup_git_repo.sh source "${setup_git_repo_sh}" - # MARK - Test tag="v999.0.0" # Test with template -actual="$( "${generate_release_notes_with_template_sh}" "${tag}" )" +actual="$("${generate_release_notes_with_template_sh}" "${tag}")" assert_match "name = \"cgrindel_bazel_starlib\"" "${actual}" "Did not find workspace name." assert_match "## What Has Changed" "${actual}" "Did not find release notes header." assert_match "bazel_starlib_dependencies()" "${actual}" "Did not find template content." # Test with workspace_name -actual="$( "${generate_release_notes_with_workspace_name_sh}" "${tag}" )" +actual="$("${generate_release_notes_with_workspace_name_sh}" "${tag}")" assert_match "name = \"foo_bar\"" "${actual}" "Did not find workspace name." assert_match "## What Has Changed" "${actual}" "Did not find release notes header." assert_match "bazel_starlib_dependencies()" "${actual}" "Did not find template content." diff --git a/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/generate_workspace_snippet_test.sh b/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/generate_workspace_snippet_test.sh index 7577de27..41ac43bb 100755 --- a/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/generate_workspace_snippet_test.sh +++ b/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/generate_workspace_snippet_test.sh @@ -2,39 +2,46 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" setup_git_repo_sh_location=cgrindel_bazel_starlib/tests/setup_git_repo.sh -setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || \ +setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || (echo >&2 "Failed to locate ${setup_git_repo_sh_location}" && exit 1) without_template_sh_location=cgrindel_bazel_starlib/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/without_template.sh -without_template_sh="$(rlocation "${without_template_sh_location}")" || \ +without_template_sh="$(rlocation "${without_template_sh_location}")" || (echo >&2 "Failed to locate ${without_template_sh_location}" && exit 1) with_template_sh_location=cgrindel_bazel_starlib/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/with_template.sh -with_template_sh="$(rlocation "${with_template_sh_location}")" || \ +with_template_sh="$(rlocation "${with_template_sh_location}")" || (echo >&2 "Failed to locate ${with_template_sh_location}" && exit 1) with_sha256_file_and_url_template_sh_location=cgrindel_bazel_starlib/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/with_sha256_file_and_url_template.sh -with_sha256_file_and_url_template_sh="$(rlocation "${with_sha256_file_and_url_template_sh_location}")" || \ +with_sha256_file_and_url_template_sh="$(rlocation "${with_sha256_file_and_url_template_sh_location}")" || (echo >&2 "Failed to locate ${with_sha256_file_and_url_template_sh_location}" && exit 1) archive_sha256_location=cgrindel_bazel_starlib/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/archive_sha256 -archive_sha256="$(rlocation "${archive_sha256_location}")" || \ +archive_sha256="$(rlocation "${archive_sha256_location}")" || (echo >&2 "Failed to locate ${archive_sha256_location}" && exit 1) # MARK - Setup @@ -46,17 +53,17 @@ source "${setup_git_repo_sh}" tag="v999.0.0" -actual="$( "${without_template_sh}" --tag "${tag}" )" +actual="$("${without_template_sh}" --tag "${tag}")" assert_match 'http_archive\(' "${actual}" "Without Template http_archive" assert_match 'name = "cgrindel_bazel_starlib"' "${actual}" "Without Template name attribute" assert_no_match bazel_starlib_dependencies "${actual}" "Without Template bazel_starlib_dependencies" -actual="$( "${with_template_sh}" --tag "${tag}" )" +actual="$("${with_template_sh}" --tag "${tag}")" assert_match 'http_archive\(' "${actual}" "With Template http_archive" assert_match 'name = "cgrindel_bazel_starlib"' "${actual}" "With Template name attribute" assert_match bazel_starlib_dependencies "${actual}" "With Template bazel_starlib_dependencies" -actual="$( "${with_sha256_file_and_url_template_sh}" --tag "${tag}" )" +actual="$("${with_sha256_file_and_url_template_sh}" --tag "${tag}")" assert_match \ 'https://github.com/cgrindel/bazel-starlib/releases/download/v999.0.0/bazel-starlib.v999.0.0.tar.gz' \ "${actual}" \ @@ -65,12 +72,12 @@ assert_match \ 'https://mirror.foo.org/cgrindel/bazel-starlib/bazel-starlib.v999.0.0.tar.gz' \ "${actual}" \ "With SHA256 File and URL Template correct custom URL" -assert_no_match 'strip_prefix' "${actual}" "With SHA256 File and URL Template no strip_prefix" +assert_no_match 'strip_prefix' "${actual}" "With SHA256 File and URL Template no strip_prefix" assert_match \ 'name = "cgrindel_bazel_starlib"' \ "${actual}" \ "With SHA256 File and URL Template name attribute" -expected_sha256="$(< "${archive_sha256}")" +expected_sha256="$(<"${archive_sha256}")" assert_match \ 'sha256 = "'"${expected_sha256}"'"' \ "${actual}" \ diff --git a/tests/bzlrelease_tests/rules_tests/hash_sha256_tests/hash_sha256_test.sh b/tests/bzlrelease_tests/rules_tests/hash_sha256_tests/hash_sha256_test.sh index 9ef58686..751a02e0 100755 --- a/tests/bzlrelease_tests/rules_tests/hash_sha256_tests/hash_sha256_test.sh +++ b/tests/bzlrelease_tests/rules_tests/hash_sha256_tests/hash_sha256_test.sh @@ -2,24 +2,31 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- fail() { local msg="${1}" - echo >&2 "${msg}" + echo >&2 "${msg}" exit 1 } hash_file="${1}" expected_hash="${2}" -actual_hash="$(< "${hash_file}")" -[[ "${actual_hash}" == "${expected_hash}" ]] || \ +actual_hash="$(<"${hash_file}")" +[[ "${actual_hash}" == "${expected_hash}" ]] || fail "Expected actual hash to equal expected. actual: ${actual_hash}, expected: ${expected_hash}" diff --git a/tests/bzlrelease_tests/rules_tests/release_artifact_tests/BUILD.bazel b/tests/bzlrelease_tests/rules_tests/release_artifact_tests/BUILD.bazel index 15a6f8af..0050df4d 100644 --- a/tests/bzlrelease_tests/rules_tests/release_artifact_tests/BUILD.bazel +++ b/tests/bzlrelease_tests/rules_tests/release_artifact_tests/BUILD.bazel @@ -16,7 +16,10 @@ release_archive( sh_test( name = "archive_test", srcs = ["archive_test.sh"], - data = [":archive"], + data = [ + ":archive", + "//tools/tar", + ], deps = [ "@cgrindel_bazel_starlib//shlib/lib:assertions", "@rules_shell//shell/runfiles", diff --git a/tests/bzlrelease_tests/rules_tests/release_artifact_tests/archive_test.sh b/tests/bzlrelease_tests/rules_tests/release_artifact_tests/archive_test.sh index 8f897c3c..77d08b8b 100755 --- a/tests/bzlrelease_tests/rules_tests/release_artifact_tests/archive_test.sh +++ b/tests/bzlrelease_tests/rules_tests/release_artifact_tests/archive_test.sh @@ -2,30 +2,41 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" archive_tar_gz_location=cgrindel_bazel_starlib/tests/bzlrelease_tests/rules_tests/release_artifact_tests/archive.tar.gz -archive_tar_gz="$(rlocation "${archive_tar_gz_location}")" || \ +archive_tar_gz="$(rlocation "${archive_tar_gz_location}")" || (echo >&2 "Failed to locate ${archive_tar_gz_location}" && exit 1) +tar_exe_location=cgrindel_bazel_starlib/tools/tar/tar.exe +tar="$(rlocation "${tar_exe_location}")" || + (echo >&2 "Failed to locate ${tar_exe_location}" && exit 1) + # MARK - Test -contents="$(tar -tf "${archive_tar_gz}")" -assert_match "bzlrelease/" "${contents}" -assert_match "bzlrelease/private/" "${contents}" -assert_match "bzlrelease/tools/" "${contents}" +contents="$("${tar}" -tf "${archive_tar_gz}")" +assert_match "bzlrelease/" "${contents}" +assert_match "bzlrelease/private/" "${contents}" +assert_match "bzlrelease/tools/" "${contents}" diff --git a/tests/bzlrelease_tests/rules_tests/update_readme_tests/update_readme_test.sh b/tests/bzlrelease_tests/rules_tests/update_readme_tests/update_readme_test.sh index 8aa4e049..19f0d1e2 100755 --- a/tests/bzlrelease_tests/rules_tests/update_readme_tests/update_readme_test.sh +++ b/tests/bzlrelease_tests/rules_tests/update_readme_tests/update_readme_test.sh @@ -2,38 +2,45 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" setup_git_repo_sh_location=cgrindel_bazel_starlib/tests/setup_git_repo.sh -setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || \ +setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || (echo >&2 "Failed to locate ${setup_git_repo_sh_location}" && exit 1) update_readme_sh_location=cgrindel_bazel_starlib/tests/bzlrelease_tests/rules_tests/update_readme_tests/update_readme.sh -update_readme_sh="$(rlocation "${update_readme_sh_location}")" || \ +update_readme_sh="$(rlocation "${update_readme_sh_location}")" || (echo >&2 "Failed to locate ${update_readme_sh_location}" && exit 1) - # MARK - Setup # shellcheck source=SCRIPTDIR/../../../setup_git_repo.sh source "${setup_git_repo_sh}" -readme_content="$(cat <<-EOF +readme_content="$( + cat <<-EOF Text before workspace snippet Text should be replaced @@ -49,30 +56,28 @@ EOF tag_name="v99999.0.0" - # MARK - Test Specify README path readme_path="${BUILD_WORKSPACE_DIRECTORY}/foo/README.md" mkdir -p "$(dirname "${readme_path}")" -echo "${readme_content}" > "${readme_path}" +echo "${readme_content}" >"${readme_path}" "${update_readme_sh}" --readme "${readme_path}" "${tag_name}" -actual="$(< "${readme_path}")" +actual="$(<"${readme_path}")" assert_no_match "Text should be replaced" "${actual}" assert_match "http_archive" "${actual}" assert_match "${tag_name}" "${actual}" assert_match "bazel_dep" "${actual}" - # MARK - Test Find README.md readme_path="${BUILD_WORKSPACE_DIRECTORY}/README.md" -echo "${readme_content}" > "${readme_path}" +echo "${readme_content}" >"${readme_path}" "${update_readme_sh}" "${tag_name}" -actual="$(< "${readme_path}")" +actual="$(<"${readme_path}")" assert_no_match "Text should be replaced" "${actual}" assert_match "http_archive" "${actual}" assert_match "${tag_name}" "${actual}" diff --git a/tests/bzlrelease_tests/tools_tests/generate_gh_changelog_test.sh b/tests/bzlrelease_tests/tools_tests/generate_gh_changelog_test.sh index f48e3940..0057ce65 100755 --- a/tests/bzlrelease_tests/tools_tests/generate_gh_changelog_test.sh +++ b/tests/bzlrelease_tests/tools_tests/generate_gh_changelog_test.sh @@ -2,59 +2,62 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/fail.sh source "${fail_sh}" env_sh_location=cgrindel_bazel_starlib/shlib/lib/env.sh -env_sh="$(rlocation "${env_sh_location}")" || \ +env_sh="$(rlocation "${env_sh_location}")" || (echo >&2 "Failed to locate ${env_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/env.sh source "${env_sh}" generate_gh_changelog_sh_location=cgrindel_bazel_starlib/bzlrelease/tools/generate_gh_changelog.sh -generate_gh_changelog_sh="$(rlocation "${generate_gh_changelog_sh_location}")" || \ +generate_gh_changelog_sh="$(rlocation "${generate_gh_changelog_sh_location}")" || (echo >&2 "Failed to locate ${generate_gh_changelog_sh_location}" && exit 1) setup_git_repo_sh_location=cgrindel_bazel_starlib/tests/setup_git_repo.sh -setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || \ +setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || (echo >&2 "Failed to locate ${setup_git_repo_sh_location}" && exit 1) -is_installed git || fail "Could not find git." - # MARK - Setup # shellcheck source=SCRIPTDIR/../../setup_git_repo.sh source "${setup_git_repo_sh}" cd "${repo_dir}" - -# MARK - Test changelog between two known tags +# MARK - Test changelog between two known tags tag_name="v0.1.1" prev_tag_name="v0.1.0" -result="$( "${generate_gh_changelog_sh}" --previous_tag_name "${prev_tag_name}" "${tag_name}" )" +result="$("${generate_gh_changelog_sh}" --previous_tag_name "${prev_tag_name}" "${tag_name}")" # [[ "${result}" =~ "**Full Changelog**: https://github.com/cgrindel/bazel-starlib/compare/v0.1.0...v0.1.1" ]] || \ -[[ "${result}" =~ \*\*Full\ Changelog\*\*:\ https://github.com/cgrindel/bazel-starlib/compare/v0\.1\.0\.\.\.v0\.1\.1 ]] || \ +[[ "${result}" =~ \*\*Full\ Changelog\*\*:\ https://github.com/cgrindel/bazel-starlib/compare/v0\.1\.0\.\.\.v0\.1\.1 ]] || fail "Expected to find changelog URL for v0.1.0...v0.1.1. result: ${result}" - # MARK - Test changelog to a new tag tag_name="v99999.0.0" -result="$( "${generate_gh_changelog_sh}" "${tag_name}" )" +result="$("${generate_gh_changelog_sh}" "${tag_name}")" match='[*][*]Full Changelog[*][*].*v9999' [[ "${result}" =~ $match ]] || fail "Expected to find changelog URL for ${tag_name}. result: ${result}" diff --git a/tests/bzlrelease_tests/tools_tests/generate_git_archive_test.sh b/tests/bzlrelease_tests/tools_tests/generate_git_archive_test.sh index decd64a2..b47ecf49 100755 --- a/tests/bzlrelease_tests/tools_tests/generate_git_archive_test.sh +++ b/tests/bzlrelease_tests/tools_tests/generate_git_archive_test.sh @@ -2,50 +2,54 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/fail.sh source "${fail_sh}" env_sh_location=cgrindel_bazel_starlib/shlib/lib/env.sh -env_sh="$(rlocation "${env_sh_location}")" || \ +env_sh="$(rlocation "${env_sh_location}")" || (echo >&2 "Failed to locate ${env_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/env.sh source "${env_sh}" setup_git_repo_sh_location=cgrindel_bazel_starlib/tests/setup_git_repo.sh -setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || \ +setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || (echo >&2 "Failed to locate ${setup_git_repo_sh_location}" && exit 1) generate_git_archive_sh_location=cgrindel_bazel_starlib/bzlrelease/tools/generate_git_archive.sh -generate_git_archive_sh="$(rlocation "${generate_git_archive_sh_location}")" || \ +generate_git_archive_sh="$(rlocation "${generate_git_archive_sh_location}")" || (echo >&2 "Failed to locate ${generate_git_archive_sh_location}" && exit 1) generate_sha256_sh_location=cgrindel_bazel_starlib/bzlrelease/tools/generate_sha256.sh -generate_sha256_sh="$(rlocation "${generate_sha256_sh_location}")" || \ +generate_sha256_sh="$(rlocation "${generate_sha256_sh_location}")" || (echo >&2 "Failed to locate ${generate_sha256_sh_location}" && exit 1) -is_installed git || fail "Could not find git." - # MARK - Setup # shellcheck source=SCRIPTDIR/../../setup_git_repo.sh source "${setup_git_repo_sh}" cd "${repo_dir}" - # MARK - Test # NOTE: Checking the SHA256 values of compressed archive files is not portable @@ -57,41 +61,41 @@ tag="v0.1.1" # Download the Github archive github_targz_path="github.tar.gz" curl -s -L "https://github.com/cgrindel/bazel-starlib/archive/${tag}.tar.gz" -o "${github_targz_path}" -expected="$( gunzip < "${github_targz_path}" | "${generate_sha256_sh}" )" +expected="$(gunzip <"${github_targz_path}" | "${generate_sha256_sh}")" # Uncompressed, output to stdout -actual="$( - "${generate_git_archive_sh}" --tag_name "${tag}" --nocompress | "${generate_sha256_sh}" +actual="$( + "${generate_git_archive_sh}" --tag_name "${tag}" --nocompress | "${generate_sha256_sh}" )" -[[ "${actual}" == "${expected}" ]] || \ - fail "SHA256 for uncompressed archive did not match. actual: ${actual}, expected: ${expected}" +[[ "${actual}" == "${expected}" ]] || + fail "SHA256 for uncompressed archive did not match. actual: ${actual}, expected: ${expected}" # Compressed, output to stdout -actual="$( +actual="$( "${generate_git_archive_sh}" --tag_name "${tag}" | gunzip | "${generate_sha256_sh}" )" -[[ "${actual}" == "${expected}" ]] || \ - fail "SHA256 for compressed archive did not match. actual: ${actual}, expected: ${expected}" +[[ "${actual}" == "${expected}" ]] || + fail "SHA256 for compressed archive did not match. actual: ${actual}, expected: ${expected}" # Uncompressed, output to file output_path="output.tar" "${generate_git_archive_sh}" --tag_name "v0.1.1" --output "${output_path}" --nocompress [[ -f "${output_path}" ]] || fail "Expected uncompressed file to exist. ${output_path}" -actual="$( "${generate_sha256_sh}" --source "${output_path}" )" -[[ "${actual}" == "${expected}" ]] || \ +actual="$("${generate_sha256_sh}" --source "${output_path}")" +[[ "${actual}" == "${expected}" ]] || fail "SHA256 for uncompressed archive file did not match. actual: ${actual}, expected: ${expected}" # Compressed, output to file output_path="output.tar.gz" "${generate_git_archive_sh}" --tag_name "v0.1.1" --output "${output_path}" [[ -f "${output_path}" ]] || fail "Expected uncompressed file to exist. ${output_path}" -actual="$( gunzip < "${output_path}" | "${generate_sha256_sh}" )" -[[ "${actual}" == "${expected}" ]] || \ +actual="$(gunzip <"${output_path}" | "${generate_sha256_sh}")" +[[ "${actual}" == "${expected}" ]] || fail "SHA256 for compressed archive file did not match. actual: ${actual}, expected: ${expected}" # Non-existent tag output_path="non-existent.tar.gz" "${generate_git_archive_sh}" --tag_name "v9999.0.0" --output "${output_path}" [[ -f "${output_path}" ]] || fail "Expected file to exist when tag does not exist. ${output_path}" -[[ -s "${output_path}" ]] || \ +[[ -s "${output_path}" ]] || fail "Expected file to not be empty for when tag does not exist. ${output_path}" diff --git a/tests/bzlrelease_tests/tools_tests/generate_module_snippet_test.sh b/tests/bzlrelease_tests/tools_tests/generate_module_snippet_test.sh index 1fd2d0ec..8849deb8 100755 --- a/tests/bzlrelease_tests/tools_tests/generate_module_snippet_test.sh +++ b/tests/bzlrelease_tests/tools_tests/generate_module_snippet_test.sh @@ -2,32 +2,39 @@ # --- 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 +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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -o errexit +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: ${BASH_SOURCE[0]} 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}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/assertions.sh source "${assertions_sh}" generate_module_snippet_sh_location=cgrindel_bazel_starlib/bzlrelease/tools/generate_module_snippet.sh -generate_module_snippet_sh="$(rlocation "${generate_module_snippet_sh_location}")" || \ +generate_module_snippet_sh="$(rlocation "${generate_module_snippet_sh_location}")" || (echo >&2 "Failed to locate ${generate_module_snippet_sh_location}" && exit 1) # MARK - Test -output="$( "${generate_module_snippet_sh}" --module_name "rules_chicken" --version "1.2.3" )" -expected="$(cat <<-EOF +output="$("${generate_module_snippet_sh}" --module_name "rules_chicken" --version "1.2.3")" +expected="$( + cat <<-EOF \`\`\`python bazel_dep(name = "rules_chicken", version = "1.2.3") \`\`\` @@ -35,8 +42,9 @@ EOF )" assert_equal "${expected}" "${output}" "module with version" -output="$( "${generate_module_snippet_sh}" --module_name "rules_chicken" --version "v1.2.3" )" -expected="$(cat <<-EOF +output="$("${generate_module_snippet_sh}" --module_name "rules_chicken" --version "v1.2.3")" +expected="$( + cat <<-EOF \`\`\`python bazel_dep(name = "rules_chicken", version = "1.2.3") \`\`\` @@ -44,8 +52,9 @@ EOF )" assert_equal "${expected}" "${output}" "module with tag" -output="$( "${generate_module_snippet_sh}" --module_name "rules_chicken" --version "v1.2.3" --dev_dependency )" -expected="$(cat <<-EOF +output="$("${generate_module_snippet_sh}" --module_name "rules_chicken" --version "v1.2.3" --dev_dependency)" +expected="$( + cat <<-EOF \`\`\`python bazel_dep( name = "rules_chicken", diff --git a/tests/bzlrelease_tests/tools_tests/generate_release_notes_test.sh b/tests/bzlrelease_tests/tools_tests/generate_release_notes_test.sh index 4895a133..db3294b2 100755 --- a/tests/bzlrelease_tests/tools_tests/generate_release_notes_test.sh +++ b/tests/bzlrelease_tests/tools_tests/generate_release_notes_test.sh @@ -2,39 +2,44 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Dependencies env_sh_location=cgrindel_bazel_starlib/shlib/lib/env.sh -env_sh="$(rlocation "${env_sh_location}")" || \ +env_sh="$(rlocation "${env_sh_location}")" || (echo >&2 "Failed to locate ${env_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/env.sh source "${env_sh}" assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/assertions.sh source "${assertions_sh}" setup_git_repo_sh_location=cgrindel_bazel_starlib/tests/setup_git_repo.sh -setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || \ +setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || (echo >&2 "Failed to locate ${setup_git_repo_sh_location}" && exit 1) generate_release_notes_sh_location=cgrindel_bazel_starlib/bzlrelease/tools/generate_release_notes.sh -generate_release_notes_sh="$(rlocation "${generate_release_notes_sh_location}")" || \ +generate_release_notes_sh="$(rlocation "${generate_release_notes_sh_location}")" || (echo >&2 "Failed to locate ${generate_release_notes_sh_location}" && exit 1) -is_installed git || fail "Could not find git." - # MARK - Setup generate_module_snippet_sh="${PWD}/generate_module_snippet.sh" @@ -83,7 +88,6 @@ echo "WORKSPACE SNIPPET CONTENT" EOF chmod +x "${generate_workspace_snippet_sh}" - # shellcheck source=SCRIPTDIR/../../setup_git_repo.sh source "${setup_git_repo_sh}" cd "${repo_dir}" @@ -94,20 +98,20 @@ cd "${repo_dir}" tag="v0.1.1" -actual="$( +actual="$( "${generate_release_notes_sh}" \ --generate_workspace_snippet "${generate_workspace_snippet_sh}" \ - "${tag}" + "${tag}" )" assert_match "## What Has Changed" "${actual}" assert_match "## Workspace Snippet" "${actual}" assert_match "WORKSPACE SNIPPET CONTENT" "${actual}" assert_no_match "## Bazel Module Snippet" "${actual}" -actual="$( +actual="$( "${generate_release_notes_sh}" \ --generate_module_snippet "${generate_module_snippet_sh}" \ - "${tag}" + "${tag}" )" assert_match "## What Has Changed" "${actual}" assert_match "## Bazel Module Snippet" "${actual}" diff --git a/tests/bzlrelease_tests/tools_tests/generate_sha256_test.sh b/tests/bzlrelease_tests/tools_tests/generate_sha256_test.sh index 00c042af..415f6fb7 100755 --- a/tests/bzlrelease_tests/tools_tests/generate_sha256_test.sh +++ b/tests/bzlrelease_tests/tools_tests/generate_sha256_test.sh @@ -2,60 +2,67 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/fail.sh source "${fail_sh}" generate_sha256_sh_location=cgrindel_bazel_starlib/bzlrelease/tools/generate_sha256.sh -generate_sha256_sh="$(rlocation "${generate_sha256_sh_location}")" || \ +generate_sha256_sh="$(rlocation "${generate_sha256_sh_location}")" || (echo >&2 "Failed to locate ${generate_sha256_sh_location}" && exit 1) # MARK - Utilities Check utilities=(openssl shasum) utilities_to_test=() -for utility in "${utilities[@]}" ; do - which "${utility}" > /dev/null && utilities_to_test+=( "${utility}" ) +for utility in "${utilities[@]}"; do + which "${utility}" >/dev/null && utilities_to_test+=("${utility}") done -[[ ${#utilities_to_test[@]} == 0 ]] && \ +[[ ${#utilities_to_test[@]} == 0 ]] && fail "This platform does not support any of the SHA256 utilities." # MARK - Setup source_path="source" -echo "This file will be hashed." > "${source_path}" +echo "This file will be hashed." >"${source_path}" expected_hash="d85406eb129904c21b9b7c286a0efb775cf6681815035bd82f8ad19285deb250" # MARK - Tests err_msg_prefix="Flags test" output_path=output_flags -"${generate_sha256_sh}" --source "${source_path}" --output "${output_path}" || \ +"${generate_sha256_sh}" --source "${source_path}" --output "${output_path}" || fail "${err_msg_prefix} - Execution failed." -actual_hash="$(< "${output_path}")" -[[ "${actual_hash}" == "${expected_hash}" ]] || \ +actual_hash="$(<"${output_path}")" +[[ "${actual_hash}" == "${expected_hash}" ]] || fail "${err_msg_prefix} - Expected actual hash to equal expected. actual: ${actual_hash}, expected: ${expected_hash}" -for utility in "${utilities_to_test[@]}" ; do +for utility in "${utilities_to_test[@]}"; do err_msg_prefix="Utility test for ${utility}" output_path="output_${utility}" - "${generate_sha256_sh}" --source "${source_path}" --output "${output_path}" --utility "${utility}" || \ + "${generate_sha256_sh}" --source "${source_path}" --output "${output_path}" --utility "${utility}" || fail "${err_msg_prefix} - Execution failed." - actual_hash="$(< "${output_path}")" - [[ "${actual_hash}" == "${expected_hash}" ]] || \ + actual_hash="$(<"${output_path}")" + [[ "${actual_hash}" == "${expected_hash}" ]] || fail "${err_msg_prefix} - Expected actual hash to equal expected. actual: ${actual_hash}, expected: ${expected_hash}" done diff --git a/tests/bzlrelease_tests/tools_tests/generate_workspace_snippet_test.sh b/tests/bzlrelease_tests/tools_tests/generate_workspace_snippet_test.sh index 087c2e90..6264c3a1 100755 --- a/tests/bzlrelease_tests/tools_tests/generate_workspace_snippet_test.sh +++ b/tests/bzlrelease_tests/tools_tests/generate_workspace_snippet_test.sh @@ -2,33 +2,40 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Resources fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/fail.sh source "${fail_sh}" setup_git_repo_sh_location=cgrindel_bazel_starlib/tests/setup_git_repo.sh -setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || \ +setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || (echo >&2 "Failed to locate ${setup_git_repo_sh_location}" && exit 1) generate_workspace_snippet_sh_location=cgrindel_bazel_starlib/bzlrelease/tools/generate_workspace_snippet.sh -generate_workspace_snippet_sh="$(rlocation "${generate_workspace_snippet_sh_location}")" || \ +generate_workspace_snippet_sh="$(rlocation "${generate_workspace_snippet_sh_location}")" || (echo >&2 "Failed to locate ${generate_workspace_snippet_sh_location}" && exit 1) workspace_snippet_tmpl_location=cgrindel_bazel_starlib/tests/bzlrelease_tests/tools_tests/workspace_snippet.tmpl -workspace_snippet_tmpl="$(rlocation "${workspace_snippet_tmpl_location}")" || \ +workspace_snippet_tmpl="$(rlocation "${workspace_snippet_tmpl_location}")" || (echo >&2 "Failed to locate ${workspace_snippet_tmpl_location}" && exit 1) # MARK - Setup @@ -44,12 +51,13 @@ strip_prefix="bazel-starlib-1.2.3" # MARK - Test Extracting Info from Git Repository actual_snippet="$( -"${generate_workspace_snippet_sh}" \ - --sha256 "${sha256}" \ - --tag "${tag}" + "${generate_workspace_snippet_sh}" \ + --sha256 "${sha256}" \ + --tag "${tag}" )" -expected_snippet=$(cat <<-EOF +expected_snippet=$( + cat <<-EOF \`\`\`python http_archive( name = "cgrindel_bazel_starlib", @@ -62,19 +70,20 @@ http_archive( \`\`\` EOF ) -[[ "${actual_snippet}" == "${expected_snippet}" ]] || \ +[[ "${actual_snippet}" == "${expected_snippet}" ]] || fail $'Snippet with defaults did not match expected. actual:\n'"${actual_snippet}"$'\nexpected:\n'"${expected_snippet}" # MARK - Test with custom workspace_name actual_snippet="$( -"${generate_workspace_snippet_sh}" \ - --workspace_name "foo_bar" \ - --sha256 "${sha256}" \ - --tag "${tag}" + "${generate_workspace_snippet_sh}" \ + --workspace_name "foo_bar" \ + --sha256 "${sha256}" \ + --tag "${tag}" )" -expected_snippet=$(cat <<-EOF +expected_snippet=$( + cat <<-EOF \`\`\`python http_archive( name = "foo_bar", @@ -87,14 +96,15 @@ http_archive( \`\`\` EOF ) -[[ "${actual_snippet}" == "${expected_snippet}" ]] || \ +[[ "${actual_snippet}" == "${expected_snippet}" ]] || fail $'Snippet with custom workspace_name did not match expected. actual:\n'"${actual_snippet}"$'\nexpected:\n'"${expected_snippet}" # MARK - Test write to file output_path="snippet.bzl" -expected_snippet=$(cat <<-EOF +expected_snippet=$( + cat <<-EOF \`\`\`python http_archive( name = "cgrindel_bazel_starlib", @@ -112,11 +122,10 @@ EOF --sha256 "${sha256}" \ --tag "${tag}" \ --output "${output_path}" -actual_snippet="$(< "${output_path}")" -[[ "${actual_snippet}" == "${expected_snippet}" ]] || \ +actual_snippet="$(<"${output_path}")" +[[ "${actual_snippet}" == "${expected_snippet}" ]] || fail $'Snippet written to file did not match expected. actual:\n'"${actual_snippet}"$'\nexpected:\n'"${expected_snippet}" - # MARK - Test Without Template owner=acme @@ -128,17 +137,18 @@ url2='http://mirror.bazel.build/github.com/${owner}/${repo}/releases/download/${ strip_prefix="rules_fun-1.2.3" actual_snippet="$( -"${generate_workspace_snippet_sh}" \ - --sha256 "${sha256}" \ - --tag "${tag}" \ - --no_github_source_archive_url \ - --url "${url1}" \ - --url "${url2}" \ - --owner "${owner}" \ - --repo "${repo}" + "${generate_workspace_snippet_sh}" \ + --sha256 "${sha256}" \ + --tag "${tag}" \ + --no_github_source_archive_url \ + --url "${url1}" \ + --url "${url2}" \ + --owner "${owner}" \ + --repo "${repo}" )" -expected_snippet=$(cat <<-EOF +expected_snippet=$( + cat <<-EOF \`\`\`python http_archive( name = "${owner}_${repo}", @@ -152,40 +162,37 @@ http_archive( \`\`\` EOF ) -[[ "${actual_snippet}" == "${expected_snippet}" ]] || \ +[[ "${actual_snippet}" == "${expected_snippet}" ]] || fail $'Snippet with specified parameters did not match expected. actual:\n'"${actual_snippet}"$'\nexpected:\n'"${expected_snippet}" - # MARK - Test With Template actual_snippet="$( -"${generate_workspace_snippet_sh}" \ - --sha256 "${sha256}" \ - --tag "${tag}" \ - --template "${workspace_snippet_tmpl}" + "${generate_workspace_snippet_sh}" \ + --sha256 "${sha256}" \ + --tag "${tag}" \ + --template "${workspace_snippet_tmpl}" )" -[[ "${actual_snippet}" =~ load.*http_archive ]] || \ +[[ "${actual_snippet}" =~ load.*http_archive ]] || fail "Did not find load statement from the template." -[[ "${actual_snippet}" =~ http_archive\( ]] || \ +[[ "${actual_snippet}" =~ http_archive\( ]] || fail "Did not find http_archive statement from the utility." - # MARK - Test Arg Checks err_output="$( -"${generate_workspace_snippet_sh}" \ - --sha256 "${sha256}" \ - 2>&1 || true + "${generate_workspace_snippet_sh}" \ + --sha256 "${sha256}" \ + 2>&1 || true )" [[ "${err_output}" =~ Expected\ a\ tag\ value\. ]] || fail "Missing tag failure." err_output="$( -"${generate_workspace_snippet_sh}" \ - --tag "${tag}" \ - --sha256 "${sha256}" \ - --no_github_source_archive_url \ - 2>&1 || true + "${generate_workspace_snippet_sh}" \ + --tag "${tag}" \ + --sha256 "${sha256}" \ + --no_github_source_archive_url \ + 2>&1 || true )" [[ "${err_output}" =~ Expected\ one\ or\ more\ url\ templates\. ]] || fail "Missing url template failure." - diff --git a/tests/bzlrelease_tests/tools_tests/update_readme_test.sh b/tests/bzlrelease_tests/tools_tests/update_readme_test.sh index aa06b13a..42d5dea0 100755 --- a/tests/bzlrelease_tests/tools_tests/update_readme_test.sh +++ b/tests/bzlrelease_tests/tools_tests/update_readme_test.sh @@ -2,35 +2,42 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/assertions.sh source "${assertions_sh}" update_readme_sh_location=cgrindel_bazel_starlib/bzlrelease/tools/update_readme.sh -update_readme_sh="$(rlocation "${update_readme_sh_location}")" || \ +update_readme_sh="$(rlocation "${update_readme_sh_location}")" || (echo >&2 "Failed to locate ${update_readme_sh_location}" && exit 1) - # MARK - Set up export BUILD_WORKSPACE_DIRECTORY="${PWD}" tag_name="v99999.0.0" -readme_content="$(cat <<-EOF +readme_content="$( + cat <<-EOF Text before workspace snippet Text should be replaced @@ -111,15 +118,16 @@ chmod +x "${generate_workspace_snippet_sh}" readme_path="${BUILD_WORKSPACE_DIRECTORY}/README.md" # Write README.md -echo "${readme_content}" > "${readme_path}" +echo "${readme_content}" >"${readme_path}" "${update_readme_sh}" \ --generate_workspace_snippet "${generate_workspace_snippet_sh}" \ --generate_module_snippet "${generate_module_snippet_sh}" \ "${tag_name}" -actual="$(< "${readme_path}")" -expected="$(cat <<-EOF +actual="$(<"${readme_path}")" +expected="$( + cat <<-EOF Text before workspace snippet WORKSPACE SNIPPET CONTENT diff --git a/tests/bzltidy_tests/tidy_all_test.sh b/tests/bzltidy_tests/tidy_all_test.sh index 405fe03d..029233f0 100755 --- a/tests/bzltidy_tests/tidy_all_test.sh +++ b/tests/bzltidy_tests/tidy_all_test.sh @@ -2,33 +2,39 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/assertions.sh source "${assertions_sh}" arrays_sh_location=cgrindel_bazel_starlib/shlib/lib/arrays.sh -arrays_sh="$(rlocation "${arrays_sh_location}")" || \ +arrays_sh="$(rlocation "${arrays_sh_location}")" || (echo >&2 "Failed to locate ${arrays_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../shlib/lib/arrays.sh source "${arrays_sh}" - create_scratch_dir_sh_location=rules_bazel_integration_test/tools/create_scratch_dir.sh -create_scratch_dir_sh="$(rlocation "${create_scratch_dir_sh_location}")" || \ +create_scratch_dir_sh="$(rlocation "${create_scratch_dir_sh_location}")" || (echo >&2 "Failed to locate ${create_scratch_dir_sh_location}" && exit 1) # MARK - Functions @@ -85,7 +91,7 @@ output_prefix_regex='\[tidy_all\]' # Tidy all modified workspaces, but there are none. assert_msg="//:tidy_modified, no modifications" revert_changes "${scratch_dir}" -output="$( "${bazel}" run //:tidy_modified )" +output="$("${bazel}" run //:tidy_modified)" tidy_out_files=() while IFS=$'\n' read -r line; do tidy_out_files+=("$line"); done < <( find_tidy_out_files "${scratch_dir}" @@ -97,8 +103,8 @@ assert_match "${output_prefix_regex}"\ No\ workspaces\ to\ tidy\. "${output}" "$ # Tidy all modified workspaces with modification in bar assert_msg="//:tidy_modified, modification in bar" revert_changes "${scratch_dir}" -echo "# Modification" >> child_workspaces/bar/BUILD.bazel -output="$( "${bazel}" run //:tidy_modified )" +echo "# Modification" >>child_workspaces/bar/BUILD.bazel +output="$("${bazel}" run //:tidy_modified)" tidy_out_files=() while IFS=$'\n' read -r line; do tidy_out_files+=("$line"); done < <( find_tidy_out_files "${scratch_dir}" @@ -110,9 +116,9 @@ assert_match "${output_prefix_regex}"\ Running\ //:my_tidy\ in\ .*bar "${output} # Tidy all modified workspaces with modification in parent and bar assert_msg="//:tidy_modified, modification in parent and bar" revert_changes "${scratch_dir}" -echo "# Modification" >> BUILD.bazel -echo "# Modification" >> child_workspaces/bar/BUILD.bazel -output="$( "${bazel}" run //:tidy_modified )" +echo "# Modification" >>BUILD.bazel +echo "# Modification" >>child_workspaces/bar/BUILD.bazel +output="$("${bazel}" run //:tidy_modified)" tidy_out_files=() while IFS=$'\n' read -r line; do tidy_out_files+=("$line"); done < <( find_tidy_out_files "${scratch_dir}" @@ -127,7 +133,7 @@ assert_match \ # Tidy all all workspaces. assert_msg="//:tidy_all" revert_changes "${scratch_dir}" -output="$( "${bazel}" run //:tidy_all )" +output="$("${bazel}" run //:tidy_all)" tidy_out_files=() while IFS=$'\n' read -r line; do tidy_out_files+=("$line"); done < <( find_tidy_out_files "${scratch_dir}" diff --git a/tests/bzltidy_tests/workspace/child_workspaces/bar/do_bar_tidy.sh b/tests/bzltidy_tests/workspace/child_workspaces/bar/do_bar_tidy.sh index bfd078da..3abf7361 100755 --- a/tests/bzltidy_tests/workspace/child_workspaces/bar/do_bar_tidy.sh +++ b/tests/bzltidy_tests/workspace/child_workspaces/bar/do_bar_tidy.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -cd "${BUILD_WORKSPACE_DIRECTORY}" || \ +cd "${BUILD_WORKSPACE_DIRECTORY}" || (echo >&2 "BUILD_WORKSPACE_DIRECTORY not defined." && exit 1) -echo "bar tidy ran" >> bar.tidy_out +echo "bar tidy ran" >>bar.tidy_out diff --git a/tests/bzltidy_tests/workspace/do_parent_tidy.sh b/tests/bzltidy_tests/workspace/do_parent_tidy.sh index f1c3cdaf..0ac34984 100755 --- a/tests/bzltidy_tests/workspace/do_parent_tidy.sh +++ b/tests/bzltidy_tests/workspace/do_parent_tidy.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -cd "${BUILD_WORKSPACE_DIRECTORY}" || \ +cd "${BUILD_WORKSPACE_DIRECTORY}" || (echo >&2 "BUILD_WORKSPACE_DIRECTORY not defined." && exit 1) -echo "parent tidy ran" >> parent.tidy_out +echo "parent tidy ran" >>parent.tidy_out diff --git a/tests/markdown_tests/tools_tests/markdown_toc_tests/generate_toc_test.sh b/tests/markdown_tests/tools_tests/markdown_toc_tests/generate_toc_test.sh index 13900320..37d8186b 100755 --- a/tests/markdown_tests/tools_tests/markdown_toc_tests/generate_toc_test.sh +++ b/tests/markdown_tests/tools_tests/markdown_toc_tests/generate_toc_test.sh @@ -2,26 +2,32 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" generate_toc_location=cgrindel_bazel_starlib/markdown/tools/markdown_toc/cmd/generate_toc/generate_toc_/generate_toc -generate_toc="$(rlocation "${generate_toc_location}")" || \ +generate_toc="$(rlocation "${generate_toc_location}")" || (echo >&2 "Failed to locate ${generate_toc_location}" && exit 1) - # MARK - Setup input_file="input.md" @@ -42,21 +48,21 @@ EOF # MARK - Test read stdin, write stdout, default start level msg="read stdin, write stdout, default start level " -output="$( "${generate_toc}" < "${input_file}" )" +output="$("${generate_toc}" <"${input_file}")" assert_match "Heading 1" "${output}" "${msg}" assert_match "Heading 2" "${output}" "${msg}" # MARK - Test read stdin, write stdout, start level 2 msg="read stdin, write stdout, start level 2" -output="$( "${generate_toc}" --start-level 2 < "${input_file}" )" +output="$("${generate_toc}" --start-level 2 <"${input_file}")" assert_no_match "Heading 1" "${output}" "${msg}" assert_match "Heading 2" "${output}" "${msg}" # MARK - Test read file, write stdout, default start level msg="read file, write stdout, default start level " -output="$( "${generate_toc}" "${input_file}" )" +output="$("${generate_toc}" "${input_file}")" assert_match "Heading 1" "${output}" "${msg}" assert_match "Heading 2" "${output}" "${msg}" @@ -65,7 +71,7 @@ assert_match "Heading 2" "${output}" "${msg}" msg="read file, write stdout, default start level " output_file="output.md" "${generate_toc}" --output "${output_file}" "${input_file}" -output="$( < "${output_file}" )" +output="$(<"${output_file}")" assert_match "Heading 1" "${output}" "${msg}" assert_match "Heading 2" "${output}" "${msg}" @@ -73,5 +79,5 @@ assert_match "Heading 2" "${output}" "${msg}" msg="invalid start level" fail_result=false -"${generate_toc}" --start-level 0 < "${input_file}" || fail_result=true +"${generate_toc}" --start-level 0 <"${input_file}" || fail_result=true assert_equal "true" "${fail_result}" "${msg}" diff --git a/tests/markdown_tests/tools_tests/update_markdown_doc_test.sh b/tests/markdown_tests/tools_tests/update_markdown_doc_test.sh index b64a2057..394fc4e5 100755 --- a/tests/markdown_tests/tools_tests/update_markdown_doc_test.sh +++ b/tests/markdown_tests/tools_tests/update_markdown_doc_test.sh @@ -2,31 +2,39 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/assertions.sh source "${assertions_sh}" update_markdown_doc_sh_location=cgrindel_bazel_starlib/markdown/tools/update_markdown_doc.sh -update_markdown_doc_sh="$(rlocation "${update_markdown_doc_sh_location}")" || \ +update_markdown_doc_sh="$(rlocation "${update_markdown_doc_sh_location}")" || (echo >&2 "Failed to locate ${update_markdown_doc_sh_location}" && exit 1) # MARK - Test Using --marker Flag markdown_path="original.md" -markdown_content="$(cat <<-EOF +markdown_content="$( + cat <<-EOF Text before snippet Text should be replaced @@ -34,15 +42,16 @@ Text should be replaced Text after snippet EOF )" -echo "${markdown_content}" > "${markdown_path}" +echo "${markdown_content}" >"${markdown_path}" update_path="update.md" -update_content="$(cat <<-EOF +update_content="$( + cat <<-EOF Here is some new text. This has 2 lines. EOF )" -echo "${update_content}" > "${update_path}" +echo "${update_content}" >"${update_path}" output_path="output.md" "${update_markdown_doc_sh}" \ @@ -50,8 +59,9 @@ output_path="output.md" --update "${update_path}" \ "${markdown_path}" "${output_path}" -output_content="$(< "${output_path}" )" -expected_content="$(cat <<-'EOF' +output_content="$(<"${output_path}")" +expected_content="$( + cat <<-'EOF' Text before snippet Here is some new text. @@ -62,11 +72,11 @@ EOF )" assert_equal "${expected_content}" "${output_content}" "Content assertion for --marker test." - # MARK - Test Using --marker_begin and --marker_end Flags another_markdown_path="another.md" -another_markdown_content="$(cat <<-EOF +another_markdown_content="$( + cat <<-EOF Text before snippet Text should be replaced @@ -74,7 +84,7 @@ Text should be replaced Text after snippet EOF )" -echo "${another_markdown_content}" > "${another_markdown_path}" +echo "${another_markdown_content}" >"${another_markdown_path}" another_output_path="another_output.md" "${update_markdown_doc_sh}" \ @@ -83,8 +93,9 @@ another_output_path="another_output.md" --update "${update_path}" \ "${another_markdown_path}" "${another_output_path}" -another_output_content="$(< "${another_output_path}" )" -expected_content="$(cat <<-'EOF' +another_output_content="$(<"${another_output_path}")" +expected_content="$( + cat <<-'EOF' Text before snippet Here is some new text. diff --git a/tests/markdown_tests/tools_tests/update_markdown_toc_test.sh b/tests/markdown_tests/tools_tests/update_markdown_toc_test.sh index 9984cf8d..003f60a6 100755 --- a/tests/markdown_tests/tools_tests/update_markdown_toc_test.sh +++ b/tests/markdown_tests/tools_tests/update_markdown_toc_test.sh @@ -2,31 +2,38 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../shlib/lib/assertions.sh source "${assertions_sh}" update_markdown_toc_sh_location=cgrindel_bazel_starlib/markdown/tools/update_markdown_toc.sh -update_markdown_toc_sh="$(rlocation "${update_markdown_toc_sh_location}")" || \ +update_markdown_toc_sh="$(rlocation "${update_markdown_toc_sh_location}")" || (echo >&2 "Failed to locate ${update_markdown_toc_sh_location}" && exit 1) - # MARK - Test with Defaults -markdown_content="$(cat <<-'EOF' +markdown_content="$( + cat <<-'EOF' # Document Title ## Table of Contents @@ -41,14 +48,15 @@ EOF )" markdown_path="original.md" -echo "${markdown_content}" > "${markdown_path}" +echo "${markdown_content}" >"${markdown_path}" output_path="output.md" "${update_markdown_toc_sh}" "${markdown_path}" "${output_path}" -output_content="$( < "${output_path}" )" +output_content="$(<"${output_path}")" -expected_content="$(cat <<-'EOF' +expected_content="$( + cat <<-'EOF' # Document Title ## Table of Contents @@ -65,10 +73,10 @@ EOF )" assert_equal "${expected_content}" "${output_content}" "With defaults" - # MARK - Test --no_remove_toc_header_entry -markdown_content="$(cat <<-'EOF' +markdown_content="$( + cat <<-'EOF' # Document Title ## Table of Contents @@ -83,14 +91,15 @@ EOF )" markdown_path="original.md" -echo "${markdown_content}" > "${markdown_path}" +echo "${markdown_content}" >"${markdown_path}" output_path="output.md" "${update_markdown_toc_sh}" --no_remove_toc_header_entry "${markdown_path}" "${output_path}" -output_content="$( < "${output_path}" )" +output_content="$(<"${output_path}")" -expected_content="$(cat <<-'EOF' +expected_content="$( + cat <<-'EOF' # Document Title ## Table of Contents @@ -108,10 +117,10 @@ EOF )" assert_equal "${expected_content}" "${output_content}" "With --no_remove_toc_header_entry" - # MARK - Test --toc_header -markdown_content="$(cat <<-'EOF' +markdown_content="$( + cat <<-'EOF' # Document Title ## Contents @@ -126,14 +135,15 @@ EOF )" markdown_path="original.md" -echo "${markdown_content}" > "${markdown_path}" +echo "${markdown_content}" >"${markdown_path}" output_path="output.md" "${update_markdown_toc_sh}" --toc_header "Contents" "${markdown_path}" "${output_path}" -output_content="$( < "${output_path}" )" +output_content="$(<"${output_path}")" -expected_content="$(cat <<-'EOF' +expected_content="$( + cat <<-'EOF' # Document Title ## Contents diff --git a/tests/shlib_tests/lib_tests/arrays_tests/contains_item_sorted_test.sh b/tests/shlib_tests/lib_tests/arrays_tests/contains_item_sorted_test.sh index 8c5644bd..9c56596d 100755 --- a/tests/shlib_tests/lib_tests/arrays_tests/contains_item_sorted_test.sh +++ b/tests/shlib_tests/lib_tests/arrays_tests/contains_item_sorted_test.sh @@ -2,33 +2,39 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" arrays_sh_location=cgrindel_bazel_starlib/shlib/lib/arrays.sh -arrays_sh="$(rlocation "${arrays_sh_location}")" || \ +arrays_sh="$(rlocation "${arrays_sh_location}")" || (echo >&2 "Failed to locate ${arrays_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/arrays.sh source "${arrays_sh}" - # MARK - Even Numbered Array array=(aa ab ac ba bb bc) -for item in "${array[@]}" ; do +for item in "${array[@]}"; do contains_item_sorted "${item}" "${array[@]}" || fail "Expected '${item}' to be found." done @@ -38,24 +44,22 @@ contains_item_sorted "za" "${array[@]}" && fail "Expected 'za' not to be found" array=(aa ab ac ba bb) -for item in "${array[@]}" ; do +for item in "${array[@]}"; do contains_item_sorted "${item}" "${array[@]}" || fail "Expected '${item}' to be found." done contains_item_sorted "zb" "${array[@]}" && fail "Expected 'zb' not to be found" - # MARK - One Item Array array=(aa) -for item in "${array[@]}" ; do +for item in "${array[@]}"; do contains_item_sorted "${item}" "${array[@]}" || fail "Expected '${item}' to be found." done contains_item_sorted "zc" "${array[@]}" && fail "Expected 'zc' not to be found" - # MARK - Empty Array contains_item_sorted "aa" && fail "Expected 'aa' not to be found in empty array" diff --git a/tests/shlib_tests/lib_tests/arrays_tests/contains_item_test.sh b/tests/shlib_tests/lib_tests/arrays_tests/contains_item_test.sh index ca6900fa..960c50f0 100755 --- a/tests/shlib_tests/lib_tests/arrays_tests/contains_item_test.sh +++ b/tests/shlib_tests/lib_tests/arrays_tests/contains_item_test.sh @@ -2,23 +2,30 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" arrays_sh_location=cgrindel_bazel_starlib/shlib/lib/arrays.sh -arrays_sh="$(rlocation "${arrays_sh_location}")" || \ +arrays_sh="$(rlocation "${arrays_sh_location}")" || (echo >&2 "Failed to locate ${arrays_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/arrays.sh source "${arrays_sh}" @@ -33,7 +40,7 @@ contains_item az "${array[@]}" || fail "Expected 'az' to be contained in array." contains_item m "${array[@]}" && fail "Expected 'm' not to be contained in array." # This test will pass the shortcut, but will not find the entry -contains_item a "${array[@]}" && fail "Expected `a` not to be contained in array." +contains_item a "${array[@]}" && fail "Expected $(a) not to be contained in array." # If we made it this far, we want to be sure to exit success exit 0 diff --git a/tests/shlib_tests/lib_tests/arrays_tests/double_quote_items_test.sh b/tests/shlib_tests/lib_tests/arrays_tests/double_quote_items_test.sh index 5ecc034c..41c3bfb1 100755 --- a/tests/shlib_tests/lib_tests/arrays_tests/double_quote_items_test.sh +++ b/tests/shlib_tests/lib_tests/arrays_tests/double_quote_items_test.sh @@ -2,36 +2,42 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" arrays_sh_location=cgrindel_bazel_starlib/shlib/lib/arrays.sh -arrays_sh="$(rlocation "${arrays_sh_location}")" || \ +arrays_sh="$(rlocation "${arrays_sh_location}")" || (echo >&2 "Failed to locate ${arrays_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/arrays.sh source "${arrays_sh}" - # MARK - Test args=(a b c) actual=() while IFS=$'\n' read -r line; do actual+=("$line"); done < <( - double_quote_items "${args[@]}" + double_quote_items "${args[@]}" ) assert_equal 3 ${#actual[@]} assert_equal "\"a\"" "${actual[0]}" @@ -42,7 +48,7 @@ assert_equal "\"c\"" "${actual[2]}" args=("hello world" "chicken smidgen" "howdy, joe") actual=() while IFS=$'\n' read -r line; do actual+=("$line"); done < <( - double_quote_items "${args[@]}" + double_quote_items "${args[@]}" ) assert_equal 3 ${#actual[@]} assert_equal "\"hello world\"" "${actual[0]}" diff --git a/tests/shlib_tests/lib_tests/arrays_tests/join_by_test.sh b/tests/shlib_tests/lib_tests/arrays_tests/join_by_test.sh index 134767d9..4670d3a1 100755 --- a/tests/shlib_tests/lib_tests/arrays_tests/join_by_test.sh +++ b/tests/shlib_tests/lib_tests/arrays_tests/join_by_test.sh @@ -2,23 +2,30 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" arrays_sh_location=cgrindel_bazel_starlib/shlib/lib/arrays.sh -arrays_sh="$(rlocation "${arrays_sh_location}")" || \ +arrays_sh="$(rlocation "${arrays_sh_location}")" || (echo >&2 "Failed to locate ${arrays_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/arrays.sh source "${arrays_sh}" diff --git a/tests/shlib_tests/lib_tests/arrays_tests/print_by_line_test.sh b/tests/shlib_tests/lib_tests/arrays_tests/print_by_line_test.sh index da07d2d2..062c5055 100755 --- a/tests/shlib_tests/lib_tests/arrays_tests/print_by_line_test.sh +++ b/tests/shlib_tests/lib_tests/arrays_tests/print_by_line_test.sh @@ -2,23 +2,30 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" arrays_sh_location=cgrindel_bazel_starlib/shlib/lib/arrays.sh -arrays_sh="$(rlocation "${arrays_sh_location}")" || \ +arrays_sh="$(rlocation "${arrays_sh_location}")" || (echo >&2 "Failed to locate ${arrays_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/arrays.sh source "${arrays_sh}" diff --git a/tests/shlib_tests/lib_tests/arrays_tests/sort_items_test.sh b/tests/shlib_tests/lib_tests/arrays_tests/sort_items_test.sh index 76d97bf1..8c1c0012 100755 --- a/tests/shlib_tests/lib_tests/arrays_tests/sort_items_test.sh +++ b/tests/shlib_tests/lib_tests/arrays_tests/sort_items_test.sh @@ -2,36 +2,42 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" arrays_sh_location=cgrindel_bazel_starlib/shlib/lib/arrays.sh -arrays_sh="$(rlocation "${arrays_sh_location}")" || \ +arrays_sh="$(rlocation "${arrays_sh_location}")" || (echo >&2 "Failed to locate ${arrays_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/arrays.sh source "${arrays_sh}" - -array=(b e a c e) -expected=(a b c e) +array=(b e a c swift e Swift Source) +expected=(Source Swift a b c e swift) actual=() while IFS=$'\n' read -r line; do actual+=("$line"); done < <( sort_items "${array[@]}" ) assert_equal "${#expected[@]}" "${#actual[@]}" -for (( i = 0; i < ${#expected[@]}; i++ )); do +for ((i = 0; i < ${#expected[@]}; i++)); do assert_equal "${expected[i]}" "${actual[i]}" done diff --git a/tests/shlib_tests/lib_tests/assertions_tests/assert_equal_test.sh b/tests/shlib_tests/lib_tests/assertions_tests/assert_equal_test.sh index ea64bb8c..021af31b 100755 --- a/tests/shlib_tests/lib_tests/assertions_tests/assert_equal_test.sh +++ b/tests/shlib_tests/lib_tests/assertions_tests/assert_equal_test.sh @@ -2,28 +2,34 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" assert_fail_sh_location=cgrindel_bazel_starlib/tests/shlib_tests/lib_tests/assertions_tests/assert_fail.sh -assert_fail_sh="$(rlocation "${assert_fail_sh_location}")" || \ +assert_fail_sh="$(rlocation "${assert_fail_sh_location}")" || (echo >&2 "Failed to locate ${assert_fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/assert_fail.sh source "${assert_fail_sh}" - # MARK - Test assert_equal reset_fail_err_msgs @@ -40,3 +46,13 @@ reset_fail_err_msgs assert_equal "hello" "hello" assert_no_fail reset_fail_err_msgs + +# Test diff functionality with multi-line strings +reset_fail_err_msgs +assert_equal "line1 +line2 +line3" "line1 +line2_modified +line3" +assert_fail 'Expected to be equal.*Expected:.*line1.*line2.*line3.*Actual:.*line1.*line2_modified.*line3.*Diff \(expected vs actual\):' +reset_fail_err_msgs diff --git a/tests/shlib_tests/lib_tests/assertions_tests/assert_fail.sh b/tests/shlib_tests/lib_tests/assertions_tests/assert_fail.sh index 5b0e24c5..a20b1e01 100644 --- a/tests/shlib_tests/lib_tests/assertions_tests/assert_fail.sh +++ b/tests/shlib_tests/lib_tests/assertions_tests/assert_fail.sh @@ -4,14 +4,14 @@ FAIL_ERR_MSGS=() fail() { local err_msg="${1:-Unspecified error occurred.}" - FAIL_ERR_MSGS+=( "${err_msg}" ) + FAIL_ERR_MSGS+=("${err_msg}") } reset_fail_err_msgs() { FAIL_ERR_MSGS=() } -new_fail(){ +new_fail() { if [[ $# -eq 0 ]]; then echo >&2 "Unspecified error occurred." else @@ -27,6 +27,6 @@ assert_fail() { [[ "${FAIL_ERR_MSGS[0]}" =~ ${pattern} ]] || new_fail "Unexpected failure. Found '${FAIL_ERR_MSGS[0]}'. pattern: ${pattern}" } -assert_no_fail(){ +assert_no_fail() { [[ ${#FAIL_ERR_MSGS[@]} == 0 ]] || new_fail "Expected no failures. Found ${#FAIL_ERR_MSGS[@]}." "${FAIL_ERR_MSGS[@]}" } diff --git a/tests/shlib_tests/lib_tests/assertions_tests/assert_match_test.sh b/tests/shlib_tests/lib_tests/assertions_tests/assert_match_test.sh index bc0d75b5..52e848fa 100755 --- a/tests/shlib_tests/lib_tests/assertions_tests/assert_match_test.sh +++ b/tests/shlib_tests/lib_tests/assertions_tests/assert_match_test.sh @@ -2,23 +2,30 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" assert_fail_sh_location=cgrindel_bazel_starlib/tests/shlib_tests/lib_tests/assertions_tests/assert_fail.sh -assert_fail_sh="$(rlocation "${assert_fail_sh_location}")" || \ +assert_fail_sh="$(rlocation "${assert_fail_sh_location}")" || (echo >&2 "Failed to locate ${assert_fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/assert_fail.sh source "${assert_fail_sh}" diff --git a/tests/shlib_tests/lib_tests/assertions_tests/assert_no_match_test.sh b/tests/shlib_tests/lib_tests/assertions_tests/assert_no_match_test.sh index 67e93c21..c90cf2c6 100755 --- a/tests/shlib_tests/lib_tests/assertions_tests/assert_no_match_test.sh +++ b/tests/shlib_tests/lib_tests/assertions_tests/assert_no_match_test.sh @@ -2,23 +2,30 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" assert_fail_sh_location=cgrindel_bazel_starlib/tests/shlib_tests/lib_tests/assertions_tests/assert_fail.sh -assert_fail_sh="$(rlocation "${assert_fail_sh_location}")" || \ +assert_fail_sh="$(rlocation "${assert_fail_sh_location}")" || (echo >&2 "Failed to locate ${assert_fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/assert_fail.sh source "${assert_fail_sh}" diff --git a/tests/shlib_tests/lib_tests/fail_tests/BUILD.bazel b/tests/shlib_tests/lib_tests/fail_tests/BUILD.bazel new file mode 100644 index 00000000..67194531 --- /dev/null +++ b/tests/shlib_tests/lib_tests/fail_tests/BUILD.bazel @@ -0,0 +1,44 @@ +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") +load("@rules_shell//shell:sh_test.bzl", "sh_test") + +bzlformat_pkg(name = "bzlformat") + +sh_test( + name = "warn_test", + srcs = ["warn_test.sh"], + deps = [ + "//shlib/lib:fail", + "@bazel_tools//tools/bash/runfiles", + "@cgrindel_bazel_starlib//shlib/lib:assertions", + ], +) + +sh_test( + name = "fail_test", + srcs = ["fail_test.sh"], + deps = [ + "//shlib/lib:fail", + "@bazel_tools//tools/bash/runfiles", + "@cgrindel_bazel_starlib//shlib/lib:assertions", + ], +) + +sh_test( + name = "usage_error_test", + srcs = ["usage_error_test.sh"], + deps = [ + "//shlib/lib:fail", + "@bazel_tools//tools/bash/runfiles", + "@cgrindel_bazel_starlib//shlib/lib:assertions", + ], +) + +sh_test( + name = "show_usage_test", + srcs = ["show_usage_test.sh"], + deps = [ + "//shlib/lib:fail", + "@bazel_tools//tools/bash/runfiles", + "@cgrindel_bazel_starlib//shlib/lib:assertions", + ], +) diff --git a/tests/shlib_tests/lib_tests/fail_tests/fail_test.sh b/tests/shlib_tests/lib_tests/fail_tests/fail_test.sh new file mode 100755 index 00000000..02b6df0e --- /dev/null +++ b/tests/shlib_tests/lib_tests/fail_tests/fail_test.sh @@ -0,0 +1,79 @@ +#!/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) +# shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh +source "${assertions_sh}" + +fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh +fail_sh="$(rlocation "${fail_sh_location}")" || + (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) +# shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh +source "${fail_sh}" + +# MARK - Test Setup + +# Override do_exit to capture exit code instead of actually exiting +captured_exit_code="" +do_exit() { + captured_exit_code="${1:-0}" +} + +# MARK - Test + +test_fail_with_args() { + local actual + captured_exit_code="" + actual="$(fail "Error occurred" "Something went wrong" 2>&1)" + assert_equal "Error occurred Something went wrong" "${actual}" + assert_equal "1" "${captured_exit_code}" +} + +test_fail_with_stdin() { + local actual + captured_exit_code="" + actual="$( + fail 2>&1 </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) +# shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh +source "${assertions_sh}" + +fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh +fail_sh="$(rlocation "${fail_sh_location}")" || + (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) +# shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh +source "${fail_sh}" + +# MARK - Test Setup + +# Override do_exit to capture exit code instead of actually exiting +captured_exit_code="" +do_exit() { + captured_exit_code="${1:-0}" +} + +# Mock get_usage function required by show_usage +get_usage() { + echo "Usage: command [options]" + echo " -h, --help Show this help message" +} + +# MARK - Test + +test_show_usage() { + local actual + captured_exit_code="" + actual="$(show_usage)" + assert_equal "Usage: command [options] + -h, --help Show this help message" "${actual}" + assert_equal "0" "${captured_exit_code}" +} + +# Run tests +test_show_usage diff --git a/tests/shlib_tests/lib_tests/fail_tests/usage_error_test.sh b/tests/shlib_tests/lib_tests/fail_tests/usage_error_test.sh new file mode 100755 index 00000000..2eba291c --- /dev/null +++ b/tests/shlib_tests/lib_tests/fail_tests/usage_error_test.sh @@ -0,0 +1,72 @@ +#!/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) +# shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh +source "${assertions_sh}" + +fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh +fail_sh="$(rlocation "${fail_sh_location}")" || + (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) +# shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh +source "${fail_sh}" + +# MARK - Test Setup + +# Override do_exit to capture exit code instead of actually exiting +captured_exit_code="" +do_exit() { + captured_exit_code="${1:-0}" +} + +# Mock get_usage function required by usage_error +get_usage() { + echo "Usage: command [options]" +} + +# MARK - Test + +test_usage_error_with_args() { + local actual + captured_exit_code="" + actual="$(usage_error "Invalid option" "Try again" 2>&1)" + assert_equal "Invalid option Try again +Usage: command [options]" "${actual}" + assert_equal "1" "${captured_exit_code}" +} + +test_usage_error_no_args() { + local actual + captured_exit_code="" + actual="$(usage_error 2>&1)" + assert_equal "Usage: command [options]" "${actual}" + assert_equal "1" "${captured_exit_code}" +} + +# Run tests +test_usage_error_with_args +test_usage_error_no_args diff --git a/tests/shlib_tests/lib_tests/fail_tests/warn_test.sh b/tests/shlib_tests/lib_tests/fail_tests/warn_test.sh new file mode 100755 index 00000000..f8aebf9b --- /dev/null +++ b/tests/shlib_tests/lib_tests/fail_tests/warn_test.sh @@ -0,0 +1,65 @@ +#!/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) +# shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh +source "${assertions_sh}" + +fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh +fail_sh="$(rlocation "${fail_sh_location}")" || + (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) +# shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh +source "${fail_sh}" + +# MARK - Test + +test_warn_with_args() { + local actual + actual="$(warn "Hello" "World" 2>&1)" + assert_equal "Hello World" "${actual}" +} + +test_warn_with_stdin() { + local actual + actual="$( + warn 2>&1 </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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" files_sh_location=cgrindel_bazel_starlib/shlib/lib/files.sh -files_sh="$(rlocation "${files_sh_location}")" || \ +files_sh="$(rlocation "${files_sh_location}")" || (echo >&2 "Failed to locate ${files_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/files.sh source "${files_sh}" diff --git a/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel b/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel index d0380a96..6ad4dee8 100644 --- a/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel +++ b/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel @@ -10,6 +10,9 @@ bzlformat_pkg(name = "bzlformat") sh_test( name = "git_integration_test", srcs = ["git_integration_test.sh"], + data = [ + "//tools/git", + ], env_inherit = GH_ENV_INHERIT, tags = INTEGRATION_TEST_TAGS, deps = [ diff --git a/tests/shlib_tests/lib_tests/git_tests/git_integration_test.sh b/tests/shlib_tests/lib_tests/git_tests/git_integration_test.sh index 29deb9d7..9c1c5e67 100755 --- a/tests/shlib_tests/lib_tests/git_tests/git_integration_test.sh +++ b/tests/shlib_tests/lib_tests/git_tests/git_integration_test.sh @@ -2,46 +2,55 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh source "${fail_sh}" env_sh_location=cgrindel_bazel_starlib/shlib/lib/env.sh -env_sh="$(rlocation "${env_sh_location}")" || \ +env_sh="$(rlocation "${env_sh_location}")" || (echo >&2 "Failed to locate ${env_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/env.sh source "${env_sh}" setup_git_repo_sh_location=cgrindel_bazel_starlib/tests/setup_git_repo.sh -setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || \ +setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || (echo >&2 "Failed to locate ${setup_git_repo_sh_location}" && exit 1) git_sh_location=cgrindel_bazel_starlib/shlib/lib/git.sh -git_sh="$(rlocation "${git_sh_location}")" || \ +git_sh="$(rlocation "${git_sh_location}")" || (echo >&2 "Failed to locate ${git_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/git.sh source "${git_sh}" arrays_sh_location=cgrindel_bazel_starlib/shlib/lib/arrays.sh -arrays_sh="$(rlocation "${arrays_sh_location}")" || \ +arrays_sh="$(rlocation "${arrays_sh_location}")" || (echo >&2 "Failed to locate ${arrays_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/arrays.sh source "${arrays_sh}" -is_installed git || fail "Could not find git." +git_exe_location=cgrindel_bazel_starlib/tools/git/git.exe +git="$(rlocation "${git_exe_location}")" || + (echo >&2 "Failed to locate ${git_exe_location}" && exit 1) # MARK - Setup @@ -49,8 +58,8 @@ is_installed git || fail "Could not find git." source "${setup_git_repo_sh}" cd "${repo_dir}" -git config user.email "noone@example.org" -git config user.name "No one" +"${git}" config user.email "noone@example.org" +"${git}" config user.name "No one" # MARK - Test @@ -87,7 +96,7 @@ contains_item "3.2.1" "${release_tags[@]}" || fail "Expected tag '3.2.1' to be f git_tag_exists "v9999.0.0" && fail "Did not expect v9999.0.0 to exist." git_tag_exists "v0.1.1" || fail "Did expect v0.1.1 to exist." -commit="$( get_git_commit_hash "v0.1.1" )" +commit="$(get_git_commit_hash "v0.1.1")" expected_commit="fc5ed94542dc764ba17670803ca06eddafc5beb1" -[[ "${commit}" == "${expected_commit}" ]] || \ +[[ "${commit}" == "${expected_commit}" ]] || fail "Unexpected commit hash. actual: ${commit}, expected:${expected_commit}" diff --git a/tests/shlib_tests/lib_tests/github_tests/BUILD.bazel b/tests/shlib_tests/lib_tests/github_tests/BUILD.bazel index fed92008..a25e66f4 100644 --- a/tests/shlib_tests/lib_tests/github_tests/BUILD.bazel +++ b/tests/shlib_tests/lib_tests/github_tests/BUILD.bazel @@ -94,9 +94,24 @@ sh_test( ], ) +sh_test( + name = "get_gh_changelog_organized_test", + srcs = ["get_gh_changelog_organized_test.sh"], + env_inherit = GH_ENV_INHERIT, + tags = INTEGRATION_TEST_TAGS, + deps = [ + "//shlib/lib:env", + "//shlib/lib:fail", + "//shlib/lib:github", + "//tests:setup_git_repo", + "@rules_shell//shell/runfiles", + ], +) + _TEST_NAMES = [ "get_gh_auth_status_test", "get_gh_changelog_test", + "get_gh_changelog_organized_test", ] test_suite( diff --git a/tests/shlib_tests/lib_tests/github_tests/get_gh_api_base_url_test.sh b/tests/shlib_tests/lib_tests/github_tests/get_gh_api_base_url_test.sh index 07834fa0..e1225e82 100755 --- a/tests/shlib_tests/lib_tests/github_tests/get_gh_api_base_url_test.sh +++ b/tests/shlib_tests/lib_tests/github_tests/get_gh_api_base_url_test.sh @@ -2,30 +2,36 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh source "${fail_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/github.sh source "${github_sh}" - # MARK - Test urls=() @@ -36,9 +42,8 @@ urls+=(https://github.com/cgrindel/bazel-starlib) urls+=(https://api.github.com/repos/cgrindel/bazel-starlib) expected="https://api.github.com/repos/cgrindel/bazel-starlib" -for url in "${urls[@]}" ; do - actual="$( get_gh_api_base_url "${url}" )" - [[ "${actual}" == "${expected}" ]] || \ +for url in "${urls[@]}"; do + actual="$(get_gh_api_base_url "${url}")" + [[ "${actual}" == "${expected}" ]] || fail "Expected base API URL not found. url: ${url}, expected: ${expected}, actual: ${actual}" done - diff --git a/tests/shlib_tests/lib_tests/github_tests/get_gh_auth_status_test.sh b/tests/shlib_tests/lib_tests/github_tests/get_gh_auth_status_test.sh index 9c6c1373..8752063d 100755 --- a/tests/shlib_tests/lib_tests/github_tests/get_gh_auth_status_test.sh +++ b/tests/shlib_tests/lib_tests/github_tests/get_gh_auth_status_test.sh @@ -2,38 +2,43 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh source "${fail_sh}" env_sh_location=cgrindel_bazel_starlib/shlib/lib/env.sh -env_sh="$(rlocation "${env_sh_location}")" || \ +env_sh="$(rlocation "${env_sh_location}")" || (echo >&2 "Failed to locate ${env_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/env.sh source "${env_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/github.sh source "${github_sh}" -is_installed gh || fail "Could not find Github CLI (gh)." - # MARK - Test -result="$( get_gh_auth_status )" +result="$(get_gh_auth_status)" [[ "${result}" =~ "Logged in to " ]] || fail "Expected auth status to indicate a user is logged in." diff --git a/tests/shlib_tests/lib_tests/github_tests/get_gh_auth_token_test.sh b/tests/shlib_tests/lib_tests/github_tests/get_gh_auth_token_test.sh index 0cf5e679..c4de7a69 100755 --- a/tests/shlib_tests/lib_tests/github_tests/get_gh_auth_token_test.sh +++ b/tests/shlib_tests/lib_tests/github_tests/get_gh_auth_token_test.sh @@ -2,28 +2,34 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh source "${fail_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/github.sh source "${github_sh}" - # MARK - Test auth_status=" @@ -34,6 +40,6 @@ github.com " expected="1234567899b95cd24c3e91d210388a28bf560b73" -actual="$( get_gh_auth_token "${auth_status}" )" -[[ "${actual}" == "${expected}" ]] || \ +actual="$(get_gh_auth_token "${auth_status}")" +[[ "${actual}" == "${expected}" ]] || fail "Expected auth token not found. actual: ${actual}, expected: ${expected}" diff --git a/tests/shlib_tests/lib_tests/github_tests/get_gh_changelog_organized_test.sh b/tests/shlib_tests/lib_tests/github_tests/get_gh_changelog_organized_test.sh new file mode 100755 index 00000000..2f9a1b9d --- /dev/null +++ b/tests/shlib_tests/lib_tests/github_tests/get_gh_changelog_organized_test.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# --- begin runfiles.bash initialization v3 --- +# Copy-pasted from the Bazel Bash runfiles library v3. +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e +# --- end runfiles.bash initialization v3 --- + +# MARK - Locate Dependencies + +fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh +fail_sh="$(rlocation "${fail_sh_location}")" || + (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) +# shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh +source "${fail_sh}" + +env_sh_location=cgrindel_bazel_starlib/shlib/lib/env.sh +env_sh="$(rlocation "${env_sh_location}")" || + (echo >&2 "Failed to locate ${env_sh_location}" && exit 1) +# shellcheck source=SCRIPTDIR/../../../../shlib/lib/env.sh +source "${env_sh}" + +github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh +github_sh="$(rlocation "${github_sh_location}")" || + (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) +# shellcheck source=SCRIPTDIR/../../../../shlib/lib/github.sh +source "${github_sh}" + +setup_git_repo_sh_location=cgrindel_bazel_starlib/tests/setup_git_repo.sh +setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || + (echo >&2 "Failed to locate ${setup_git_repo_sh_location}" && exit 1) + +# MARK - Setup + +# shellcheck source=SCRIPTDIR/../../../setup_git_repo.sh +source "${setup_git_repo_sh}" +cd "${repo_dir}" + +# MARK - Test + +tag_name="v0.25.1" +prev_tag_name="v0.24.0" +result="$( + get_gh_changelog_organized \ + --tag_name "${tag_name}" \ + --previous_tag_name "${prev_tag_name}" +)" +[[ "${result}" =~ \*\*Full\ Changelog\*\*:\ https://github\.com/cgrindel/bazel-starlib/compare/v0\.24\.0\.\.\.v0\.25\.1 ]] || + fail "Expected to find changelog URL for v0.24.0...v0.25.1. result: ${result}" + +[[ "${result}" =~ "## What's Changed" ]] || fail "No What's Changed" + +[[ "${result}" =~ "### Highlights" ]] || fail "No Highlights" + +[[ "${result}" =~ "### Dependency Updates" ]] || fail "No Dependency Updates" + +[[ ! "${result}" =~ "### Other Changes" ]] || fail "Found Other Changes" + +[[ "${result}" =~ "### Dependency Updates" ]] || fail "No Dependency Updates" + +# The single quotes around the EOF tell bash to not perform any expansion inside +# the string. +expected=$( + cat <<'EOF' +## What's Changed + +### Highlights + +* chore: update README.md for v0.24.0 by @cgrindel-app-token-generator[bot] in https://github.com/cgrindel/bazel-starlib/pull/503 +* feat: use BSD tar toolchain for release archive functionality by @cgrindel in https://github.com/cgrindel/bazel-starlib/pull/504 +* chore: update README.md for v0.25.0 by @cgrindel-app-token-generator[bot] in https://github.com/cgrindel/bazel-starlib/pull/505 +* fix: include `//tools/tar` in release by @cgrindel in https://github.com/cgrindel/bazel-starlib/pull/509 + +### Dependency Updates + +* chore(deps): update dependency bazel to v8.1.0 by @cgrindel-self-hosted-renovate[bot] in https://github.com/cgrindel/bazel-starlib/pull/506 +* chore(deps): update dependency bazel to v8.1.1 by @cgrindel-self-hosted-renovate[bot] in https://github.com/cgrindel/bazel-starlib/pull/507 +* fix(deps): update dependency markdown-link-check to v3.13.7 by @cgrindel-self-hosted-renovate[bot] in https://github.com/cgrindel/bazel-starlib/pull/508 + +**Full Changelog**: https://github.com/cgrindel/bazel-starlib/compare/v0.24.0...v0.25.1 +EOF +) + +[[ "${result}" == "${expected}" ]] || fail "Does not equal" diff --git a/tests/shlib_tests/lib_tests/github_tests/get_gh_changelog_test.sh b/tests/shlib_tests/lib_tests/github_tests/get_gh_changelog_test.sh index f4eaa96d..2336999c 100755 --- a/tests/shlib_tests/lib_tests/github_tests/get_gh_changelog_test.sh +++ b/tests/shlib_tests/lib_tests/github_tests/get_gh_changelog_test.sh @@ -2,41 +2,46 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh source "${fail_sh}" env_sh_location=cgrindel_bazel_starlib/shlib/lib/env.sh -env_sh="$(rlocation "${env_sh_location}")" || \ +env_sh="$(rlocation "${env_sh_location}")" || (echo >&2 "Failed to locate ${env_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/env.sh source "${env_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/github.sh source "${github_sh}" setup_git_repo_sh_location=cgrindel_bazel_starlib/tests/setup_git_repo.sh -setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || \ +setup_git_repo_sh="$(rlocation "${setup_git_repo_sh_location}")" || (echo >&2 "Failed to locate ${setup_git_repo_sh_location}" && exit 1) -is_installed gh || fail "Could not find Github CLI (gh)." - # MARK - Setup # shellcheck source=SCRIPTDIR/../../../setup_git_repo.sh @@ -47,7 +52,6 @@ cd "${repo_dir}" tag_name="v0.1.1" prev_tag_name="v0.1.0" -result="$( get_gh_changelog --tag_name "${tag_name}" --previous_tag_name "${prev_tag_name}" )" -[[ "${result}" =~ \*\*Full\ Changelog\*\*:\ https://github\.com/cgrindel/bazel-starlib/compare/v0\.1\.0\.\.\.v0\.1\.1 ]] || \ +result="$(get_gh_changelog --tag_name "${tag_name}" --previous_tag_name "${prev_tag_name}")" +[[ "${result}" =~ \*\*Full\ Changelog\*\*:\ https://github\.com/cgrindel/bazel-starlib/compare/v0\.1\.0\.\.\.v0\.1\.1 ]] || fail "Expected to find changelog URL for v0.1.0...v0.1.1. result: ${result}" - diff --git a/tests/shlib_tests/lib_tests/github_tests/get_gh_repo_name_test.sh b/tests/shlib_tests/lib_tests/github_tests/get_gh_repo_name_test.sh index 5f5e5310..a48a0c69 100755 --- a/tests/shlib_tests/lib_tests/github_tests/get_gh_repo_name_test.sh +++ b/tests/shlib_tests/lib_tests/github_tests/get_gh_repo_name_test.sh @@ -2,30 +2,36 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh source "${fail_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/github.sh source "${github_sh}" - # MARK - Test urls=() @@ -36,9 +42,9 @@ urls+=(https://github.com/chicken-smidgen/bazel-starlib) urls+=(https://api.github.com/repos/chicken-smidgen/bazel-starlib) expected=bazel-starlib -for (( i = 0; i < ${#urls[@]}; i++ )); do +for ((i = 0; i < ${#urls[@]}; i++)); do url="${urls[$i]}" - actual="$( get_gh_repo_name "${url}" )" - [[ "${actual}" == "${expected}" ]] || \ + actual="$(get_gh_repo_name "${url}")" + [[ "${actual}" == "${expected}" ]] || fail "Expected name not found. url: ${url}, expected: ${expected}, actual: ${actual}" done diff --git a/tests/shlib_tests/lib_tests/github_tests/get_gh_repo_owner_test.sh b/tests/shlib_tests/lib_tests/github_tests/get_gh_repo_owner_test.sh index 1746fff5..e62e3b58 100755 --- a/tests/shlib_tests/lib_tests/github_tests/get_gh_repo_owner_test.sh +++ b/tests/shlib_tests/lib_tests/github_tests/get_gh_repo_owner_test.sh @@ -2,30 +2,36 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh source "${fail_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/github.sh source "${github_sh}" - # MARK - Test urls=() @@ -42,10 +48,10 @@ expected_owners+=(chicken-smidgen) expected_owners+=(chicken-smidgen) expected_owners+=(chicken-smidgen) -for (( i = 0; i < ${#urls[@]}; i++ )); do +for ((i = 0; i < ${#urls[@]}; i++)); do url="${urls[$i]}" expected="${expected_owners[$i]}" - actual="$( get_gh_repo_owner "${url}" )" - [[ "${actual}" == "${expected}" ]] || \ + actual="$(get_gh_repo_owner "${url}")" + [[ "${actual}" == "${expected}" ]] || fail "Expected owner not found. url: ${url}, expected: ${expected}, actual: ${actual}" done diff --git a/tests/shlib_tests/lib_tests/github_tests/get_gh_username_test.sh b/tests/shlib_tests/lib_tests/github_tests/get_gh_username_test.sh index 34c10d42..250d7f42 100755 --- a/tests/shlib_tests/lib_tests/github_tests/get_gh_username_test.sh +++ b/tests/shlib_tests/lib_tests/github_tests/get_gh_username_test.sh @@ -2,30 +2,36 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh source "${fail_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/github.sh source "${github_sh}" - # MARK - Test auth_status=" @@ -38,6 +44,6 @@ github.com " expected="cgrindel" -actual="$( get_gh_username "${auth_status}" )" -[[ "${actual}" == "${expected}" ]] || \ +actual="$(get_gh_username "${auth_status}")" +[[ "${actual}" == "${expected}" ]] || fail "Expected username not found. actual: ${actual}, expected: ${expected}" diff --git a/tests/shlib_tests/lib_tests/github_tests/is_github_repo_url_test.sh b/tests/shlib_tests/lib_tests/github_tests/is_github_repo_url_test.sh index d87e66f3..0cfeae63 100755 --- a/tests/shlib_tests/lib_tests/github_tests/is_github_repo_url_test.sh +++ b/tests/shlib_tests/lib_tests/github_tests/is_github_repo_url_test.sh @@ -2,30 +2,36 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Dependencies fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh source "${fail_sh}" github_sh_location=cgrindel_bazel_starlib/shlib/lib/github.sh -github_sh="$(rlocation "${github_sh_location}")" || \ +github_sh="$(rlocation "${github_sh_location}")" || (echo >&2 "Failed to locate ${github_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/github.sh source "${github_sh}" - # MARK - Test good_urls=() @@ -33,7 +39,7 @@ good_urls+=(git@github.com:cgrindel/bazel-starlib.git) good_urls+=(https://github.com/cgrindel/bazel-starlib.git) good_urls+=(https://github.com/cgrindel/bazel-starlib) -for url in "${good_urls[@]}" ; do +for url in "${good_urls[@]}"; do is_github_repo_url "${url}" || fail "Expected '${url}' to be a Github URL." done @@ -41,7 +47,7 @@ bad_urls=() bad_urls+=(git@example.org:cgrindel/bazel-starlib.git) bad_urls+=(https://example.org/cgrindel/bazel-starlib.git) -for url in "${bad_urls[@]}" ; do +for url in "${bad_urls[@]}"; do is_github_repo_url "${url}" && fail "Expected '${url}' to not be a Github URL." done diff --git a/tests/shlib_tests/lib_tests/messages_tests/exit_with_msg_test.sh b/tests/shlib_tests/lib_tests/messages_tests/exit_with_msg_test.sh index 4491af7f..db8b8c43 100755 --- a/tests/shlib_tests/lib_tests/messages_tests/exit_with_msg_test.sh +++ b/tests/shlib_tests/lib_tests/messages_tests/exit_with_msg_test.sh @@ -2,23 +2,30 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" messages_sh_location=cgrindel_bazel_starlib/shlib/lib/messages.sh -messages_sh="$(rlocation "${messages_sh_location}")" || \ +messages_sh="$(rlocation "${messages_sh_location}")" || (echo >&2 "Failed to locate ${messages_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/messages.sh source "${messages_sh}" @@ -31,7 +38,7 @@ exit_code=$? assert_equal "Unspecified error occurred." "${msg}" assert_equal 1 ${exit_code} -msg=$(exit_with_msg --no_exit "My custom message" 2>&1) +msg=$(exit_with_msg --no_exit "My custom message" 2>&1) exit_code=$? assert_equal "My custom message" "${msg}" assert_equal 1 ${exit_code} @@ -41,7 +48,7 @@ exit_code=$? assert_equal "Unspecified error occurred." "${msg}" assert_equal 123 ${exit_code} -msg=$(exit_with_msg --no_exit --exit_code 123 "My custom message" 2>&1) +msg=$(exit_with_msg --no_exit --exit_code 123 "My custom message" 2>&1) exit_code=$? assert_equal "My custom message" "${msg}" assert_equal 123 ${exit_code} @@ -50,4 +57,3 @@ msg=$(exit_with_msg --no_exit "First msg" "Second msg" 2>&1) exit_code=$? assert_equal "First msg Second msg" "${msg}" assert_equal 1 ${exit_code} - diff --git a/tests/shlib_tests/lib_tests/paths_tests/normalize_path_test.sh b/tests/shlib_tests/lib_tests/paths_tests/normalize_path_test.sh index c745f0bd..3b0c88f7 100755 --- a/tests/shlib_tests/lib_tests/paths_tests/normalize_path_test.sh +++ b/tests/shlib_tests/lib_tests/paths_tests/normalize_path_test.sh @@ -2,23 +2,30 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" paths_sh_location=cgrindel_bazel_starlib/shlib/lib/paths.sh -paths_sh="$(rlocation "${paths_sh_location}")" || \ +paths_sh="$(rlocation "${paths_sh_location}")" || (echo >&2 "Failed to locate ${paths_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/paths.sh source "${paths_sh}" diff --git a/tests/shlib_tests/rules_tests/execute_binary_tests/execute_binary_no_args_test.sh b/tests/shlib_tests/rules_tests/execute_binary_tests/execute_binary_no_args_test.sh index f88de55d..f9794fe4 100755 --- a/tests/shlib_tests/rules_tests/execute_binary_tests/execute_binary_no_args_test.sh +++ b/tests/shlib_tests/rules_tests/execute_binary_tests/execute_binary_no_args_test.sh @@ -2,23 +2,30 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" my_bin_no_args_sh_location=cgrindel_bazel_starlib/tests/shlib_tests/rules_tests/execute_binary_tests/my_bin_no_args.sh -my_bin="$(rlocation "${my_bin_no_args_sh_location}")" || \ +my_bin="$(rlocation "${my_bin_no_args_sh_location}")" || (echo >&2 "Failed to locate ${my_bin_no_args_sh_location}" && exit 1) output=$("${my_bin}") diff --git a/tests/shlib_tests/rules_tests/execute_binary_tests/execute_binary_with_args_test.sh b/tests/shlib_tests/rules_tests/execute_binary_tests/execute_binary_with_args_test.sh index fbb00128..e5cede57 100755 --- a/tests/shlib_tests/rules_tests/execute_binary_tests/execute_binary_with_args_test.sh +++ b/tests/shlib_tests/rules_tests/execute_binary_tests/execute_binary_with_args_test.sh @@ -2,23 +2,30 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" my_bin_with_args_sh_location=cgrindel_bazel_starlib/tests/shlib_tests/rules_tests/execute_binary_tests/my_bin_with_args.sh -my_bin="$(rlocation "${my_bin_with_args_sh_location}")" || \ +my_bin="$(rlocation "${my_bin_with_args_sh_location}")" || (echo >&2 "Failed to locate ${my_bin_with_args_sh_location}" && exit 1) # MARK - Additional Assertions @@ -50,11 +57,9 @@ ${output} " assert_embedded_args "${output}" - [[ "${output}" =~ Data:\ This\ is\ a\ data\ file\. ]] || fail "Did not see data file output." [[ "${output}" =~ Input:\ This\ is\ an\ input\ file\. ]] || fail "Did not see input file output." - # MARK - Test that additional arguments are passed along properly output=$("${my_bin}" additional_arg) diff --git a/tests/shlib_tests/rules_tests/execute_binary_tests/find_workspace.sh b/tests/shlib_tests/rules_tests/execute_binary_tests/find_workspace.sh index 373f124b..4e6f6aaa 100755 --- a/tests/shlib_tests/rules_tests/execute_binary_tests/find_workspace.sh +++ b/tests/shlib_tests/rules_tests/execute_binary_tests/find_workspace.sh @@ -3,4 +3,7 @@ # This utility expects to be run at the root of a Bazel workspace. It fails if # it is not. -[[ -f "WORKSPACE" ]] || (echo >&2 "WORKSPACE not found." ; exit 1) +[[ -f "WORKSPACE" ]] || ( + echo >&2 "WORKSPACE not found." + exit 1 +) diff --git a/tests/shlib_tests/rules_tests/execute_binary_tests/find_workspace_eb_test.sh b/tests/shlib_tests/rules_tests/execute_binary_tests/find_workspace_eb_test.sh index 1164884b..29c444c0 100755 --- a/tests/shlib_tests/rules_tests/execute_binary_tests/find_workspace_eb_test.sh +++ b/tests/shlib_tests/rules_tests/execute_binary_tests/find_workspace_eb_test.sh @@ -2,26 +2,33 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" # tests/shlib_tests/rules_tests/execute_binary_tests find_workspace_eb_location=cgrindel_bazel_starlib/tests/shlib_tests/rules_tests/execute_binary_tests/find_workspace_eb.sh -find_workspace_eb="$(rlocation "${find_workspace_eb_location}")" || \ +find_workspace_eb="$(rlocation "${find_workspace_eb_location}")" || (echo >&2 "Failed to locate ${find_workspace_eb_location}" && exit 1) # MARK - Test diff --git a/tests/shlib_tests/rules_tests/execute_binary_tests/my_bin.sh b/tests/shlib_tests/rules_tests/execute_binary_tests/my_bin.sh index bc545ab3..921c162e 100755 --- a/tests/shlib_tests/rules_tests/execute_binary_tests/my_bin.sh +++ b/tests/shlib_tests/rules_tests/execute_binary_tests/my_bin.sh @@ -2,20 +2,26 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Args Count - echo "Args Count: ${#}" -for (( i = 1; i <= ${#}; i++ )); do +for ((i = 1; i <= ${#}; i++)); do echo " ${i}: ${!i}" done @@ -26,26 +32,26 @@ check_data_file=false args=() while (("$#")); do case "${1}" in - "--check_data_file") - check_data_file=true - shift 1 - ;; - "--input") - input_file="${2}" - shift 2 - ;; - *) - args+=("${1}") - shift 1 - ;; + "--check_data_file") + check_data_file=true + shift 1 + ;; + "--input") + input_file="${2}" + shift 2 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done if [[ "${check_data_file}" == true ]]; then data_txt_location=cgrindel_bazel_starlib/tests/shlib_tests/rules_tests/execute_binary_tests/data.txt - data_txt="$(rlocation "${data_txt_location}")" || \ + data_txt="$(rlocation "${data_txt_location}")" || (echo >&2 "Failed to locate ${data_txt_location}" && exit 1) - echo "Data: $(< "${data_txt}")" + echo "Data: $(<"${data_txt}")" fi -[[ -z "${input_file:-}" ]] || echo "Input: $(< "${input_file}")" +[[ -z "${input_file:-}" ]] || echo "Input: $(<"${input_file}")" diff --git a/tests/shlib_tests/rules_tests/execute_binary_tests/process_file.sh b/tests/shlib_tests/rules_tests/execute_binary_tests/process_file.sh index 814807ef..b80bee96 100755 --- a/tests/shlib_tests/rules_tests/execute_binary_tests/process_file.sh +++ b/tests/shlib_tests/rules_tests/execute_binary_tests/process_file.sh @@ -2,40 +2,46 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps data_file_txt_location=cgrindel_bazel_starlib/tests/shlib_tests/rules_tests/execute_binary_tests/data.txt -data_file_txt="$(rlocation "${data_file_txt_location}")" || \ +data_file_txt="$(rlocation "${data_file_txt_location}")" || (echo >&2 "Failed to locate ${data_file_txt_location}" && exit 1) args=() while (("$#")); do case "${1}" in - "--file") - arg_file="${2}" - shift 2 - ;; - *) - args+=("${1}") - shift 1 - ;; + "--file") + arg_file="${2}" + shift 2 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done - -data="$(< "${data_file_txt}")" +data="$(<"${data_file_txt}")" echo "Data: ${data}" if [[ -n "${arg_file:-}" ]]; then - arg_file_data="$(< "${arg_file}")" + arg_file_data="$(<"${arg_file}")" echo "Arg File: ${arg_file_data}" fi diff --git a/tests/shlib_tests/rules_tests/execute_binary_tests/process_file_consumer.sh b/tests/shlib_tests/rules_tests/execute_binary_tests/process_file_consumer.sh index f2c44229..30e28352 100755 --- a/tests/shlib_tests/rules_tests/execute_binary_tests/process_file_consumer.sh +++ b/tests/shlib_tests/rules_tests/execute_binary_tests/process_file_consumer.sh @@ -2,41 +2,46 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps fail_sh_location=cgrindel_bazel_starlib/shlib/lib/fail.sh -fail_sh="$(rlocation "${fail_sh_location}")" || \ +fail_sh="$(rlocation "${fail_sh_location}")" || (echo >&2 "Failed to locate ${fail_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/fail.sh source "${fail_sh}" - # MARK - Process Args args=() while (("$#")); do case "${1}" in - "--process_file") - process_file="${2}" - shift 2 - ;; - *) - args+=("${1}") - shift 1 - ;; + "--process_file") + process_file="${2}" + shift 2 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done [[ -z "${process_file:-}" ]] && fail "Expected a process_file executable" "${process_file}" - diff --git a/tests/shlib_tests/rules_tests/execute_binary_tests/process_file_consumer_eb_test.sh b/tests/shlib_tests/rules_tests/execute_binary_tests/process_file_consumer_eb_test.sh index d632b2f8..b1a57241 100755 --- a/tests/shlib_tests/rules_tests/execute_binary_tests/process_file_consumer_eb_test.sh +++ b/tests/shlib_tests/rules_tests/execute_binary_tests/process_file_consumer_eb_test.sh @@ -2,31 +2,37 @@ # --- begin runfiles.bash initialization v3 --- # Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; 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: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e +set -uo pipefail +set +e +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: ${BASH_SOURCE[0]} cannot find $f" + exit 1 + } +f= +set -e # --- end runfiles.bash initialization v3 --- # MARK - Locate Deps assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh -assertions_sh="$(rlocation "${assertions_sh_location}")" || \ +assertions_sh="$(rlocation "${assertions_sh_location}")" || (echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1) # shellcheck source=SCRIPTDIR/../../../../shlib/lib/assertions.sh source "${assertions_sh}" process_file_consumer_eb_sh_location=cgrindel_bazel_starlib/tests/shlib_tests/rules_tests/execute_binary_tests/process_file_consumer_eb.sh -process_file_consumer_eb_sh="$(rlocation "${process_file_consumer_eb_sh_location}")" || \ +process_file_consumer_eb_sh="$(rlocation "${process_file_consumer_eb_sh_location}")" || (echo >&2 "Failed to locate ${process_file_consumer_eb_sh_location}" && exit 1) - # MARK - Test -output="$( "${process_file_consumer_eb_sh}" )" +output="$("${process_file_consumer_eb_sh}")" # Look for output from process_file.sh assert_match "Data: This is a data file." "${output}" diff --git a/tests/tools_tests/git_tests/BUILD.bazel b/tests/tools_tests/git_tests/BUILD.bazel new file mode 100644 index 00000000..43df2458 --- /dev/null +++ b/tests/tools_tests/git_tests/BUILD.bazel @@ -0,0 +1,29 @@ +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") +load("@rules_shell//shell:sh_test.bzl", "sh_test") + +bzlformat_pkg(name = "bzlformat") + +sh_test( + name = "git_vars_test", + srcs = ["git_vars_test.sh"], + env = { + "GIT": "$(GIT)", + }, + toolchains = ["//tools/git:vars"], + deps = [ + "@bazel_tools//tools/bash/runfiles", + "@cgrindel_bazel_starlib//shlib/lib:assertions", + ], +) + +sh_test( + name = "git_binary_test", + srcs = ["git_binary_test.sh"], + data = [ + "//tools/git", + ], + deps = [ + "@bazel_tools//tools/bash/runfiles", + "@cgrindel_bazel_starlib//shlib/lib:assertions", + ], +) diff --git a/tests/tools_tests/git_tests/git_binary_test.sh b/tests/tools_tests/git_tests/git_binary_test.sh new file mode 100755 index 00000000..4ec5fde4 --- /dev/null +++ b/tests/tools_tests/git_tests/git_binary_test.sh @@ -0,0 +1,34 @@ +#!/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}" + +git_exe_location=cgrindel_bazel_starlib/tools/git/git.exe +git_exe="$(rlocation "${git_exe_location}")" || + (echo >&2 "Failed to locate ${git_exe_location}" && exit 1) + +# MARK - Test + +"${git_exe}" --help diff --git a/tests/tools_tests/git_tests/git_vars_test.sh b/tests/tools_tests/git_tests/git_vars_test.sh new file mode 100755 index 00000000..95ba5d4b --- /dev/null +++ b/tests/tools_tests/git_tests/git_vars_test.sh @@ -0,0 +1,32 @@ +#!/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}" + +# MARK - Test + +if [[ -z "${GIT:-}" ]]; then + fail "GIT env var was not set." +fi diff --git a/tests/updatesrc_tests/workspace/MODULE.bazel b/tests/updatesrc_tests/workspace/MODULE.bazel index b2224e67..6f356c8a 100644 --- a/tests/updatesrc_tests/workspace/MODULE.bazel +++ b/tests/updatesrc_tests/workspace/MODULE.bazel @@ -9,4 +9,4 @@ local_path_override( path = "../../..", ) -bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "bazel_skylib", version = "1.8.2") diff --git a/tools/format/BUILD.bazel b/tools/format/BUILD.bazel new file mode 100644 index 00000000..dd2e4a14 --- /dev/null +++ b/tools/format/BUILD.bazel @@ -0,0 +1,11 @@ +load("@aspect_rules_lint//format:defs.bzl", "format_multirun") +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") + +bzlformat_pkg(name = "bzlformat") + +format_multirun( + name = "format", + shell = "@aspect_rules_lint//format:shfmt", + starlark = "@buildifier_prebuilt//:buildifier", + visibility = ["//:__subpackages__"], +) diff --git a/tools/gh/BUILD.bazel b/tools/gh/BUILD.bazel new file mode 100644 index 00000000..72314ef5 --- /dev/null +++ b/tools/gh/BUILD.bazel @@ -0,0 +1,9 @@ +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") + +bzlformat_pkg(name = "bzlformat") + +filegroup( + name = "all_files", + srcs = glob(["*"]), + visibility = ["//:__subpackages__"], +) diff --git a/tools/gh/multitool.lock.json b/tools/gh/multitool.lock.json new file mode 100644 index 00000000..3db035b0 --- /dev/null +++ b/tools/gh/multitool.lock.json @@ -0,0 +1,47 @@ +{ + "$schema": "https://raw.githubusercontent.com/theoremlp/rules_multitool/main/lockfile.schema.json", + "gh": { + "binaries": [ + { + "kind": "archive", + "url": "https://github.com/cli/cli/releases/download/v2.66.1/gh_2.66.1_linux_arm64.tar.gz", + "file": "gh_2.66.1_linux_arm64/bin/gh", + "sha256": "f11a2c3d1a2cfd97106fa6405fbb4c1254a7e91be38537148ab7d27209698a6b", + "os": "linux", + "cpu": "arm64" + }, + { + "kind": "archive", + "url": "https://github.com/cli/cli/releases/download/v2.66.1/gh_2.66.1_linux_amd64.tar.gz", + "file": "gh_2.66.1_linux_amd64/bin/gh", + "sha256": "387b4e9a717ddf2efa8426a774f14463bf64e41fb7bec3463c737cf5413e5a79", + "os": "linux", + "cpu": "x86_64" + }, + { + "kind": "archive", + "url": "https://github.com/cli/cli/releases/download/v2.66.1/gh_2.66.1_macOS_amd64.zip", + "file": "gh_2.66.1_macOS_amd64/bin/gh", + "sha256": "7ae1b19f5b4c46545be7c9a16a52b922b9dee4755f051c7fa6f105784632d035", + "os": "macos", + "cpu": "arm64" + }, + { + "kind": "archive", + "url": "https://github.com/cli/cli/releases/download/v2.66.1/gh_2.66.1_macOS_amd64.zip", + "file": "gh_2.66.1_macOS_amd64/bin/gh", + "sha256": "7ae1b19f5b4c46545be7c9a16a52b922b9dee4755f051c7fa6f105784632d035", + "os": "macos", + "cpu": "x86_64" + }, + { + "kind": "archive", + "url": "https://github.com/cli/cli/releases/download/v2.66.1/gh_2.66.1_windows_amd64.zip", + "file": "bin/gh.exe", + "sha256": "2f8cd5d8bcffc65dc4dc69bb48ca536b53f792744ba7da7e75b238bde9deb2bf", + "os": "windows", + "cpu": "x86_64" + } + ] + } +} diff --git a/tools/git/BUILD.bazel b/tools/git/BUILD.bazel new file mode 100644 index 00000000..1d65fc75 --- /dev/null +++ b/tools/git/BUILD.bazel @@ -0,0 +1,68 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") +load(":git_binary.bzl", "git_binary") +load(":git_vars.bzl", "git_vars") + +bzlformat_pkg(name = "bzlformat") + +filegroup( + name = "all_files", + srcs = glob(["*"]), + visibility = ["//:__subpackages__"], +) + +toolchain_type( + name = "toolchain_type", + visibility = ["//visibility:public"], +) + +git_vars( + name = "vars", + visibility = ["//visibility:public"], +) + +git_binary( + name = "git", + visibility = ["//visibility:public"], +) + +bzl_library( + name = "extensions", + srcs = ["extensions.bzl"], + visibility = ["//visibility:public"], + deps = [":local_git"], +) + +bzl_library( + name = "git_binary", + srcs = ["git_binary.bzl"], + visibility = ["//visibility:public"], + deps = [":git_toolchains"], +) + +bzl_library( + name = "git_toolchain", + srcs = ["git_toolchain.bzl"], + visibility = ["//visibility:public"], + deps = [":git_toolchains"], +) + +bzl_library( + name = "git_vars", + srcs = ["git_vars.bzl"], + visibility = ["//visibility:public"], + deps = [":git_toolchains"], +) + +bzl_library( + name = "local_git", + srcs = ["local_git.bzl"], + visibility = ["//visibility:public"], + deps = [":git_toolchains"], +) + +bzl_library( + name = "git_toolchains", + srcs = ["git_toolchains.bzl"], + visibility = ["//visibility:public"], +) diff --git a/tools/git/extensions.bzl b/tools/git/extensions.bzl new file mode 100644 index 00000000..7d090bd0 --- /dev/null +++ b/tools/git/extensions.bzl @@ -0,0 +1,10 @@ +"""Implementation of bzlmod extensions related to GitHub CLI.""" + +load(":local_git.bzl", "local_git") + +def _local_git_ext(_): + local_git(name = "bazel_starlib_git_toolchains") + +local_git_ext = module_extension( + implementation = _local_git_ext, +) diff --git a/tools/git/git_binary.bzl b/tools/git/git_binary.bzl new file mode 100644 index 00000000..b72b05c1 --- /dev/null +++ b/tools/git/git_binary.bzl @@ -0,0 +1,37 @@ +"""Implementation for `git_binary` rule.""" + +load(":git_toolchains.bzl", "git_toolchains") + +# Heavily inspired by +# https://github.com/bazelbuild/bazel-skylib/blob/7209de9148e98dc20425cf83747613f23d40827b/rules/native_binary.bzl#L23 + +def _git_binary_impl(ctx): + out = ctx.actions.declare_file( + ctx.attr.out if (ctx.attr.out != "") else ctx.attr.name + ".exe", + ) + git_bin = ctx.toolchains[git_toolchains.type].git_info.git + ctx.actions.symlink( + target_file = git_bin, + output = out, + is_executable = True, + ) + return DefaultInfo( + executable = out, + files = depset([out]), + ) + +git_binary = rule( + implementation = _git_binary_impl, + executable = True, + doc = "Expose the `git` binary.", + attrs = { + # "out" is attr.string instead of attr.output, so that it is select()'able. + "out": attr.string( + default = "", + doc = "An output name for the copy of the binary. Defaults to " + + "name.exe. (We add .exe to the name by default because it's " + + "required on Windows and tolerated on other platforms.)", + ), + }, + toolchains = [git_toolchains.type], +) diff --git a/tools/git/git_toolchain.bzl b/tools/git/git_toolchain.bzl new file mode 100644 index 00000000..cbbfbd0f --- /dev/null +++ b/tools/git/git_toolchain.bzl @@ -0,0 +1,41 @@ +"""Implementation for the `git_toolchain` rule.""" + +load(":git_toolchains.bzl", "git_toolchains") + +def _git_toolchain_impl(ctx): + git = ctx.executable.git + default_info = DefaultInfo( + files = depset([git]), + runfiles = ctx.runfiles(files = [git]), + ) + template_variables = platform_common.TemplateVariableInfo({ + "GIT": git.path, + }) + toolchain_info = platform_common.ToolchainInfo( + git_info = git_toolchains.GitInfo(git = git), + template_variables = template_variables, + ) + + return [ + default_info, + toolchain_info, + template_variables, + ] + +git_toolchain = rule( + implementation = _git_toolchain_impl, + attrs = { + "git": attr.label( + mandatory = True, + executable = True, + cfg = "exec", + doc = "The `git` utility.", + allow_single_file = True, + ), + }, + provides = [ + platform_common.ToolchainInfo, + platform_common.TemplateVariableInfo, + ], + doc = "Defines a toolchain for the GitHub CLI.", +) diff --git a/tools/git/git_toolchains.bzl b/tools/git/git_toolchains.bzl new file mode 100644 index 00000000..795599bd --- /dev/null +++ b/tools/git/git_toolchains.bzl @@ -0,0 +1,15 @@ +"""Implementation of the `git_toolchains` module.""" + +_TOOLCHAIN_TYPE = "@cgrindel_bazel_starlib//tools/git:toolchain_type" + +_GitInfo = provider( + fields = { + "git": "The `git` utility as an exeutable `File`.", + }, + doc = "Information about the GitHub CLI.", +) + +git_toolchains = struct( + type = _TOOLCHAIN_TYPE, + GitInfo = _GitInfo, +) diff --git a/tools/git/git_vars.bzl b/tools/git/git_vars.bzl new file mode 100644 index 00000000..0152a39e --- /dev/null +++ b/tools/git/git_vars.bzl @@ -0,0 +1,22 @@ +"""Implementation of the `git_vars` rule.""" + +load(":git_toolchains.bzl", "git_toolchains") + +def _git_vars_impl(ctx): + git_info = ctx.toolchains[git_toolchains.type].git_info + git = git_info.git + template_variables = platform_common.TemplateVariableInfo({ + "GIT": git.path, + }) + return [template_variables] + +git_vars = rule( + implementation = _git_vars_impl, + provides = [ + platform_common.TemplateVariableInfo, + ], + toolchains = [git_toolchains.type], + # The doc says that you can use the toolchain type, but they did not work + # for me. I saw that rules_erlang did something like this. + doc = "Provides make variable substitution for `genrule` and `sh_xxx`.", +) diff --git a/tools/git/local_git.bzl b/tools/git/local_git.bzl new file mode 100644 index 00000000..b14cefc5 --- /dev/null +++ b/tools/git/local_git.bzl @@ -0,0 +1,40 @@ +"""Implementation of the `local_git` repository rule.""" + +load(":git_toolchains.bzl", "git_toolchains") + +_BUILD_TPL = """\ +load("@cgrindel_bazel_starlib//tools/git:git_toolchain.bzl", "git_toolchain") +load("@cgrindel_bazel_starlib//tools/git:git_vars.bzl", "git_vars") + +git_toolchain( + name = "local_git", + git = ":{link_name}", + visibility = ["//visibility:public"], +) + +toolchain( + name = "local_git_toolchain", + toolchain = ":local_git", + toolchain_type = "{toolchain_type}", + # visibility = ["//visibility:public"], +) +""" + +def _local_git_impl(rctx): + git_path = rctx.which("git") + if not git_path: + fail("Could not find `git` in the PATH.") + + link_name = "git" + rctx.symlink(git_path, link_name) + + rctx.file("BUILD.bazel", _BUILD_TPL.format( + link_name = link_name, + toolchain_type = git_toolchains.type, + )) + +local_git = repository_rule( + implementation = _local_git_impl, + local = True, + doc = "Detect the local installation of the GitHub CLI and define a toolchain.", +) diff --git a/tools/tar/BUILD.bazel b/tools/tar/BUILD.bazel new file mode 100644 index 00000000..3ae24be3 --- /dev/null +++ b/tools/tar/BUILD.bazel @@ -0,0 +1,29 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") +load(":tar_binary.bzl", "tar_binary") + +bzlformat_pkg(name = "bzlformat") + +filegroup( + name = "all_files", + srcs = glob(["*"]), + visibility = ["//:__subpackages__"], +) + +tar_binary( + name = "tar", + visibility = ["//visibility:public"], +) + +bzl_library( + name = "tar_binary", + srcs = ["tar_binary.bzl"], + visibility = ["//visibility:public"], + deps = [":tar_toolchains"], +) + +bzl_library( + name = "tar_toolchains", + srcs = ["tar_toolchains.bzl"], + visibility = ["//visibility:public"], +) diff --git a/tools/tar/tar_binary.bzl b/tools/tar/tar_binary.bzl new file mode 100644 index 00000000..885a55b9 --- /dev/null +++ b/tools/tar/tar_binary.bzl @@ -0,0 +1,37 @@ +"""Implementation for `tar_binary` rule.""" + +load(":tar_toolchains.bzl", "tar_toolchains") + +# Heavily inspired by +# https://tarhub.com/bazelbuild/bazel-skylib/blob/7209de9148e98dc20425cf83747613f23d40827b/rules/native_binary.bzl#L23 + +def _tar_binary_impl(ctx): + out = ctx.actions.declare_file( + ctx.attr.out if (ctx.attr.out != "") else ctx.attr.name + ".exe", + ) + bsdtar = ctx.toolchains[tar_toolchains.type] + ctx.actions.symlink( + target_file = bsdtar.tarinfo.binary, + output = out, + is_executable = True, + ) + return DefaultInfo( + executable = out, + files = depset([out]), + ) + +tar_binary = rule( + implementation = _tar_binary_impl, + executable = True, + doc = "Expose the `tar` binary.", + attrs = { + # "out" is attr.string instead of attr.output, so that it is select()'able. + "out": attr.string( + default = "", + doc = "An output name for the copy of the binary. Defaults to " + + "name.exe. (We add .exe to the name by default because it's " + + "required on Windows and tolerated on other platforms.)", + ), + }, + toolchains = [tar_toolchains.type], +) diff --git a/tools/tar/tar_toolchains.bzl b/tools/tar/tar_toolchains.bzl new file mode 100644 index 00000000..58adc0a4 --- /dev/null +++ b/tools/tar/tar_toolchains.bzl @@ -0,0 +1,5 @@ +"""Implementation of 'tar_toolchains' module.""" + +tar_toolchains = struct( + type = "@aspect_bazel_lib//lib:tar_toolchain_type", +) diff --git a/updatesrc/private/BUILD.bazel b/updatesrc/private/BUILD.bazel index 615bd753..d76c5f7f 100644 --- a/updatesrc/private/BUILD.bazel +++ b/updatesrc/private/BUILD.bazel @@ -1,4 +1,5 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") load("//bzlformat:defs.bzl", "bzlformat_pkg") package(default_visibility = ["//updatesrc:__subpackages__"]) diff --git a/updatesrc/private/update_all.sh b/updatesrc/private/update_all.sh index c357867c..9f6a95bf 100755 --- a/updatesrc/private/update_all.sh +++ b/updatesrc/private/update_all.sh @@ -5,7 +5,7 @@ set -o errexit -o nounset -o pipefail -# Use the Bazel binary specified by the integration test. Otherise, fall back +# Use the Bazel binary specified by the integration test. Otherise, fall back # to bazel. bazel="${BIT_BAZEL_BINARY:-bazel}" @@ -28,18 +28,18 @@ targets_to_run_before=() targets_to_run_after=() while (("$#")); do case "${1}" in - "--run_before") - targets_to_run_before+=( "$2" ) - shift 2 - ;; - "--run_after") - targets_to_run_after+=( "$2" ) - shift 2 - ;; - *) - args+=("${1}") - shift 1 - ;; + "--run_before") + targets_to_run_before+=("$2") + shift 2 + ;; + "--run_after") + targets_to_run_after+=("$2") + shift 2 + ;; + *) + args+=("${1}") + shift 1 + ;; esac done @@ -68,8 +68,8 @@ update_targets=() while IFS=$'\n' read -r line; do update_targets+=("$line"); done < <( "${bazel}" cquery "${bazel_query}" \ --output=starlark \ - --starlark:file="${starlark_file}" \ - | sort + --starlark:file="${starlark_file}" | + sort ) if [[ ${#update_targets[@]} -gt 0 ]]; then run_bazel_targets "${update_targets[@]}"