Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
ci: make e2e test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Sep 8, 2022
1 parent 35fe2a1 commit 88e5da5
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 29 deletions.
1 change: 0 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ npm_link_all_packages(name = "node_modules")

compile_pip_requirements(
name = "requirements",
#extra_args = ["--allow-unsafe"],
requirements_in = "requirements.txt",
requirements_txt = "requirements_lock.txt",
)
26 changes: 4 additions & 22 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,17 @@ nodejs_register_toolchains(
node_version = "16.9.0",
)

load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")

npm_translate_lock(
name = "aspect_rules_fmt_npm",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)

load("@aspect_rules_fmt_npm//:repositories.bzl", "npm_repositories")

npm_repositories()

load("@rules_python//python:repositories.bzl", "python_register_toolchains")

python_register_toolchains(
name = "python3",
python_version = "3.10",
)

load("@python3//:defs.bzl", "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse")
load("@aspect_rules_fmt//fmt:dependencies.bzl", "parse_dependencies")

pip_parse(
name = "aspect_rules_fmt_pypi",
python_interpreter_target = interpreter,
requirements_lock = "//:requirements_lock.txt",
)
parse_dependencies()

load("@aspect_rules_fmt_pypi//:requirements.bzl", "install_deps")
load("//fmt:toolchains.bzl", "fmt_register_toolchains")

# Initialize repositories for all packages in requirements_lock.txt.
install_deps()
fmt_register_toolchains()
1 change: 1 addition & 0 deletions e2e/workspace/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --@aspect_rules_fmt//fmt:java_enabled=false
26 changes: 26 additions & 0 deletions e2e/workspace/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,29 @@ local_repository(
load("@aspect_rules_fmt//fmt:repositories.bzl", "rules_fmt_dependencies")

rules_fmt_dependencies()

# If you didn't already register a toolchain providing nodejs, do that:
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)

# If you format python code, you'll need that toolchain as well
load("@rules_python//python:repositories.bzl", "python_register_toolchains")

python_register_toolchains(
name = "python3",
python_version = "3.10",
)

load("@aspect_rules_fmt//fmt:dependencies.bzl", "parse_dependencies")

parse_dependencies()

# Installs toolchains for running programs under Node, Python, etc.
# Be sure to register your own toolchains before this.
load("@aspect_rules_fmt//fmt:toolchains.bzl", "fmt_register_toolchains")

fmt_register_toolchains()
2 changes: 1 addition & 1 deletion fmt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ alias(
# TODO: keith says it would be okay to upstream a proper toolchain for this
# https://github.com/bazelbuild/rules_swift/issues/864
actual = select({
"@bazel_tools//src/conditions:linux": "@swiftformat_linux",
"@bazel_tools//src/conditions:linux": "@swiftformat",
"@bazel_tools//src/conditions:darwin": "@swiftformat_mac",
}),
)
Expand Down
16 changes: 16 additions & 0 deletions fmt/dependencies.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
load("@python3//:defs.bzl", "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse")

def parse_dependencies():
npm_translate_lock(
name = "aspect_rules_fmt_npm",
link_workspace = "aspect_rules_fmt",
pnpm_lock = "@aspect_rules_fmt//:pnpm-lock.yaml",
)

pip_parse(
name = "aspect_rules_fmt_pypi",
python_interpreter_target = interpreter,
requirements_lock = "@aspect_rules_fmt//:requirements_lock.txt",
)
13 changes: 12 additions & 1 deletion fmt/fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ if [[ -z "$BUILD_WORKSPACE_DIRECTORY" ]]; then
exit 1
fi

function on_exit {
code=$?
if [[ $code != 0 ]]; then
echo >&2 "FAILED: A formatter tool exited with code $code"
echo >&2 "Try running 'bazel run @aspect_rules_fmt//fmt' to fix this."
fi
}

trap on_exit EXIT

readonly mode="${1:-fix}"

# --- begin runfiles.bash initialization v2 ---
Expand Down Expand Up @@ -78,7 +88,8 @@ files=$(git ls-files '*.java')
bin=$(rlocation aspect_rules_fmt/fmt/java-format)
[ -n "$files" ] && [ -n "$bin" ] && {
echo "Running java-format..."
echo $files | xargs $bin $javamode
# Setting JAVA_RUNFILES to work around https://github.com/bazelbuild/bazel/issues/12348
echo $files | JAVA_RUNFILES="${RUNFILES_MANIFEST_FILE%_manifest}" xargs $bin $javamode
}

# TODO: don't hardcode "linux"
Expand Down
21 changes: 17 additions & 4 deletions fmt/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def rules_fmt_dependencies():

# TODO: fetch for host platform
http_archive(
name = "swiftformat_linux",
name = "swiftformat",
sha256 = "f8ecce65f67cbc4e855d2a508e1282018cd7427f2b6bc33c83a3416c227233b4",
url = "https://github.com/nicklockwood/SwiftFormat/releases/download/0.49.11/swiftformat_linux.zip",
patch_cmds = ["chmod u+x swiftformat_linux"],
Expand All @@ -62,11 +62,24 @@ def rules_fmt_dependencies():
],
)

http_archive(
name = "rules_nodejs",
sha256 = "5aef09ed3279aa01d5c928e3beb248f9ad32dde6aafe6373a8c994c3ce643064",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.3/rules_nodejs-core-5.5.3.tar.gz"],
)

http_archive(
name = "aspect_rules_js",
sha256 = "538049993bec3ee1ae9b1c3cd669156bca04eb67027b222883e47b0a2aed2e67",
strip_prefix = "rules_js-1.0.0",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.0.0.tar.gz",
sha256 = "25bcb082d49616ac2da538bf7bdd33a9730c8884edbec787fec83db07e4f7f16",
strip_prefix = "rules_js-1.1.0",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.1.0.tar.gz",
)

http_archive(
name = "aspect_bazel_lib",
sha256 = "8ea64f13c6db68356355d6a97dced3d149e9cd7ba3ecb4112960586e914e466d",
strip_prefix = "bazel-lib-1.11.1",
url = "https://github.com/aspect-build/bazel-lib/archive/refs/tags/v1.11.1.tar.gz",
)

http_archive(
Expand Down
11 changes: 11 additions & 0 deletions fmt/toolchains.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")
load("@aspect_rules_fmt_pypi//:requirements.bzl", "install_deps")
load("@aspect_rules_fmt_npm//:repositories.bzl", "npm_repositories")

def fmt_register_toolchains():
buildifier_prebuilt_register_toolchains()

# Initialize repositories for all packages in requirements_lock.txt.
install_deps()

npm_repositories()

0 comments on commit 88e5da5

Please sign in to comment.