Skip to content

Commit

Permalink
chore: Integrate rules_lint and format files (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmeku authored May 17, 2024
1 parent 96ee05d commit f037327
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 14 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
e2e/
node_modules
cypress/tests/node_modules
4 changes: 2 additions & 2 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ TAG=${GITHUB_REF_NAME}
# The prefix is chosen to match what GitHub generates for source archives
PREFIX="rules_cypress-${TAG:1}"
ARCHIVE="rules_cypress-$TAG.tar.gz"
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip >$ARCHIVE
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')

cat << EOF
cat <<EOF
WORKSPACE snippet:
\`\`\`starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ repos:
rev: v3.1.0
hooks:
- id: prettier
- repo: local
hooks:
- id: aspect_rules_lint
name: Format
language: system
entry: bazel run //:format
files: .*
8 changes: 8 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
load("@npm//:defs.bzl", "npm_link_all_packages")

buildifier(
name = "buildifier",
Expand All @@ -17,6 +18,11 @@ buildifier(
tags = ["manual"], # tag as manual so windows ci does not build it by default
)

alias(
name = "format",
actual = "//tools/format",
)

bzl_library(
name = "internal_deps",
srcs = ["internal_deps.bzl"],
Expand All @@ -26,3 +32,5 @@ bzl_library(
"@bazel_tools//tools/build_defs/repo:utils.bzl",
],
)

npm_link_all_packages(name = "node_modules")
10 changes: 10 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@ bazel_dep(name = "rules_nodejs", version = "5.8.2")

####### Dev dependencies ########

bazel_dep(name = "aspect_rules_lint", version = "0.21.0", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")

node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node", dev_dependency = True)
node.toolchain(node_version = "16.14.2")

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
name = "npm",
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)
use_repo(npm, "npm")

http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# To update CHROME_REVISION, use the below script
Expand Down
21 changes: 21 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ nodejs_register_toolchains(
node_version = DEFAULT_NODE_VERSION,
)

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

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

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

npm_repositories()

# For running our own unit tests
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

Expand Down Expand Up @@ -65,3 +78,11 @@ buildifier_prebuilt_deps()
load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")

buildifier_prebuilt_register_toolchains()

# rules_lint
load(
"@aspect_rules_lint//format:repositories.bzl",
"rules_lint_dependencies",
)

rules_lint_dependencies()
10 changes: 5 additions & 5 deletions e2e/workspace/cli_test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES2022",
"types": ["cypress", "node"]
}
}
"compilerOptions": {
"target": "ES2022",
"types": ["cypress", "node"]
}
}
7 changes: 7 additions & 0 deletions internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ def rules_cypress_internal_deps():
strip_prefix = "buildifier-prebuilt-6.4.0",
urls = ["http://github.com/keith/buildifier-prebuilt/archive/6.4.0.tar.gz"],
)

http_archive(
name = "aspect_rules_lint",
sha256 = "1e679b081750ca9cedad4f79e371ee5e14d9a157de8018661af9fe45879100b2",
strip_prefix = "rules_lint-0.21.0",
url = "https://github.com/aspect-build/rules_lint/releases/download/v0.21.0/rules_lint-v0.21.0.tar.gz",
)
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"devDependencies": {
"prettier": "^3.2.5"
}
}
"devDependencies": {
"prettier": "^3.2.5"
}
}
6 changes: 3 additions & 3 deletions scripts/mirror_releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# Produce a dictionary for the current cypress release,
# suitable for appending to cypress/private/versions.bzl
set -o errexit -o nounset
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

version="${1:-$(curl --silent "https://registry.npmjs.org/cypress/latest" | jq --raw-output ".version")}"

echo " \"$version\": {"
for pkg in darwin-{x,arm}64 linux-{x,arm}64 win32-x64; do
sha256=($(curl -sL "https://cdn.cypress.io/desktop/${version}/${pkg}/cypress.zip" | shasum -a 256))
echo " \"$pkg\": \"$sha256\","
sha256=($(curl -sL "https://cdn.cypress.io/desktop/${version}/${pkg}/cypress.zip" | shasum -a 256))
echo " \"$pkg\": \"$sha256\","
done
echo " },"
echo
Expand Down
20 changes: 20 additions & 0 deletions tools/format/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@aspect_rules_lint//format:defs.bzl", "format_multirun")
load("@npm//:prettier/package_json.bzl", prettier = "bin")

package(default_visibility = ["//visibility:public"])

prettier.prettier_binary(
name = "prettier",
# Allow the binary to be run outside bazel
env = {"BAZEL_BINDIR": "."},
)

format_multirun(
name = "format",
go = None,
javascript = ":prettier",
jsonnet = None,
shell = None,
terraform = None,
yaml = None,
)

0 comments on commit f037327

Please sign in to comment.