From b756fb0593c96a8a07c034fb3e7a4bb799b117b6 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius Date: Mon, 30 May 2022 22:23:28 +0900 Subject: [PATCH] Remove buildifier from dependencies and use pre-commit-hooks instead (#11) * Remove buildifier from dependencies and use pre-commit-hooks instead * Disable the fetching test on macos * fix buildifier errors * remove the buildifier definition * don't use matrix for the different platform tests --- .github/workflows/workflow.yml | 18 ++++++----- .pre-commit-config.yaml | 13 ++++++++ BUILD.bazel | 8 ++--- WORKSPACE | 58 ---------------------------------- def.bzl | 3 ++ deps.bzl | 9 ++++-- 6 files changed, 35 insertions(+), 74 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 88883bc..c640669 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -5,20 +5,22 @@ on: jobs: build: - strategy: - matrix: - os: - - ubuntu-latest - - macos-latest - - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Test fetch - if: ${{ matrix.os }} == 'ubuntu-latest' run: bazel fetch //... - name: Test run: bazel test //... + + test-mac: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v3 + + - name: Test + run: bazel test //... diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..79f025d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +# See CONTRIBUTING.md for instructions. +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/keith/pre-commit-buildifier + rev: 4.0.1.1 + hooks: + - id: buildifier + args: &args + # Keep this argument in sync with .bazelci/presubmit.yaml + - --warnings=all + - id: buildifier-lint + args: *args diff --git a/BUILD.bazel b/BUILD.bazel index 5b3b8b2..b3a444d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,13 +1,9 @@ -load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") - -buildifier(name = "buildifier") - alias( name = "shellcheck", actual = select({ - "@bazel_tools//src/conditions:linux_x86_64": "@shellcheck_linux_amd64//:shellcheck", - "@bazel_tools//src/conditions:linux_aarch64": "@shellcheck_linux_arm64//:shellcheck", "@bazel_tools//src/conditions:darwin": "@shellcheck_darwin_amd64//:shellcheck", + "@bazel_tools//src/conditions:linux_aarch64": "@shellcheck_linux_arm64//:shellcheck", + "@bazel_tools//src/conditions:linux_x86_64": "@shellcheck_linux_amd64//:shellcheck", #"@bazel_tools//src/conditions:darwin_arm64": "@shellcheck_darwin_arm64//:shellcheck", #"@bazel_tools//src/conditions:windows_x64": "@shellcheck_windows_amd64//:shellcheck", }), diff --git a/WORKSPACE b/WORKSPACE index 8db59ed..db7dee0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,63 +1,5 @@ workspace(name = "com_github_aignas_rules_shellcheck") -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -# buildifier is written in Go and hence needs rules_go to be built. -# See https://github.com/bazelbuild/rules_go for the up to date setup instructions. -http_archive( - name = "io_bazel_rules_go", - sha256 = "ab21448cef298740765f33a7f5acee0607203e4ea321219f2a4c85a6e0fb0a27", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.32.0/rules_go-v0.32.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.32.0/rules_go-v0.32.0.zip", - ], -) - -load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies") - -go_rules_dependencies() - -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains") - -go_register_toolchains(version = "1.18.2") - -http_archive( - name = "bazel_gazelle", - sha256 = "5982e5463f171da99e3bdaeff8c0f48283a7a5f396ec5282910b9e8a49c0dd7e", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.25.0/bazel-gazelle-v0.25.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.25.0/bazel-gazelle-v0.25.0.tar.gz", - ], -) - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") - -# If you use WORKSPACE.bazel, use the following line instead of the bare gazelle_dependencies(): -# gazelle_dependencies(go_repository_default_config = "@//:WORKSPACE.bazel") -gazelle_dependencies() - -http_archive( - name = "com_google_protobuf", - sha256 = "3bd7828aa5af4b13b99c191e8b1e884ebfa9ad371b0ce264605d347f135d2568", - strip_prefix = "protobuf-3.19.4", - urls = [ - "https://github.com/protocolbuffers/protobuf/archive/v3.19.4.tar.gz", - ], -) - -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() - -http_archive( - name = "com_github_bazelbuild_buildtools", - sha256 = "", - strip_prefix = "buildtools-5.1.0", - urls = [ - "https://github.com/bazelbuild/buildtools/archive/refs/tags/5.1.0.tar.gz", - ], -) - load("//:deps.bzl", "shellcheck_dependencies") shellcheck_dependencies() diff --git a/def.bzl b/def.bzl index e933c6f..0ca04c9 100644 --- a/def.bzl +++ b/def.bzl @@ -1,3 +1,6 @@ +"""This file provides all user facing functions. +""" + def _impl_test(ctx): files = [ctx.file._shellcheck] + ctx.files.data script = "exec " + " ".join([f.short_path for f in files]) diff --git a/deps.bzl b/deps.bzl index b9a138c..3337856 100644 --- a/deps.bzl +++ b/deps.bzl @@ -1,10 +1,15 @@ +"""Provides shellcheck dependencies on all supported platforms: +- Linux 64-bit and ARM64 +- OSX 64-bit +""" + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") _LABELS = { + "darwin_amd64": "darwin.x86_64", "linux_amd64": "linux.x86_64", "linux_arm64": "linux.aarch64", - "darwin_amd64": "darwin.x86_64", # darwin_arm64 shellcheck binaries are not distributed from GitHub releases. # windows_amd64 shellcheck binaries are not distributed from GitHub releases. } @@ -20,9 +25,9 @@ def _urls(arch, version): def shellcheck_dependencies(): version = "v0.8.0" sha256 = { + "darwin_amd64": "e065d4afb2620cc8c1d420a9b3e6243c84ff1a693c1ff0e38f279c8f31e86634", "linux_amd64": "ab6ee1b178f014d1b86d1e24da20d1139656c8b0ed34d2867fbb834dad02bf0a", "linux_arm64": "9f47bbff5624babfa712eb9d64ece14c6c46327122d0c54983f627ae3a30a4ac", - "darwin_amd64": "e065d4afb2620cc8c1d420a9b3e6243c84ff1a693c1ff0e38f279c8f31e86634", } for arch, sha256 in sha256.items():