Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: enable buildifier check on ci #451

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/buildifier.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Buildifier

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main]
pull_request:
branches: [main]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: buildifier
run: bazel run --enable_bzlmod //:buildifier.check
10 changes: 10 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@aspect_bazel_lib_host//:defs.bzl", "host")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
load("//lib:write_source_files.bzl", "write_source_files")
load("//lib:yq.bzl", "yq")
load("//lib:diff_test.bzl", "diff_test")
Expand Down Expand Up @@ -33,6 +34,15 @@ gazelle(
command = "update-repos",
)

buildifier(
name = "buildifier.check",
exclude_patterns = [
"./.git/*",
],
lint_mode = "warn",
mode = "diff",
)

bzl_library(
name = "internal_deps",
srcs = ["internal_deps.bzl"],
Expand Down
11 changes: 6 additions & 5 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

module(
name = "aspect_bazel_lib",
compatibility_level = 1,
version = "0.0.0",
compatibility_level = 1,
)

# Lower-bound versions of our dependencies
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "platforms", version = "0.0.4")

# 0.5.4 is the first version with bzlmod support
bazel_dep(name = "stardoc", repo_name = "io_bazel_stardoc", version = "0.5.4")
bazel_dep(name = "stardoc", version = "0.5.4", repo_name = "io_bazel_stardoc")

ext = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "ext")

use_repo(ext, "copy_directory_toolchains", "copy_to_directory_toolchains", "jq_toolchains", "yq_toolchains", "coreutils_toolchains", "expand_template_toolchains")
use_repo(ext, "copy_directory_toolchains", "copy_to_directory_toolchains", "coreutils_toolchains", "expand_template_toolchains", "jq_toolchains", "yq_toolchains")

register_toolchains(
"@copy_directory_toolchains//:all",
"@copy_to_directory_toolchains//:all",
"@jq_toolchains//:all",
"@yq_toolchains//:all",
"@coreutils_toolchains//:all",
"@expand_template_toolchains//:all"
"@expand_template_toolchains//:all",
)

# Development-only dependencies

bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "6.0.0.1", dev_dependency = True)
9 changes: 9 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ go_rules_dependencies()
go_register_toolchains(version = "1.18.3")

gazelle_dependencies()

# Buildifier
load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")

buildifier_prebuilt_deps()

load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")

buildifier_prebuilt_register_toolchains()
6 changes: 1 addition & 5 deletions docs/strings.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions e2e/bzlmod_write_source_files_external/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
module(
name = "bzlmod_write_source_files_external",
compatibility_level = 1,
version = "0.0.0",
compatibility_level = 1,
)

bazel_dep(name = "aspect_bazel_lib", version = "0.0.0")

local_path_override(
module_name = "aspect_bazel_lib",
path = "../..",
)

test_ext = use_extension("//:test_extension.bzl", "test_ext")

use_repo(test_ext, "test")

6 changes: 1 addition & 5 deletions e2e/copy_to_directory/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
module(
name = "copy_to_directory",
compatibility_level = 1,
version = "0.0.0",
compatibility_level = 1,
)

bazel_dep(name = "bazel_skylib", version = "1.1.1")

bazel_dep(name = "aspect_bazel_lib", version = "0.0.0")

local_path_override(
module_name = "aspect_bazel_lib",
path = "../..",
)

ext = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "ext")

ext.host()

use_repo(ext, "aspect_bazel_lib_host")
10 changes: 4 additions & 6 deletions e2e/coreutils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ genrule(

hashes(
name = "hash",
src = "test.bin"
src = "test.bin",
)

filegroup(
name = "md5",
srcs = [":hash"],
output_group = "md5",
srcs = [":hash"]
)

filegroup(
name = "sha1",
srcs = [":hash"],
output_group = "sha1",
srcs = [":hash"]
)


# This tests that the "in" file to write_source_files can be a
# label to an external repository target when bzlmod is enabled.
write_source_files(
Expand All @@ -34,7 +33,6 @@ write_source_files(
"ls.txt.expected": ":ls.txt",
"sha256.txt": ":hash",
"sha1.txt": ":sha1",
"md5.txt": ":md5"
"md5.txt": ":md5",
},
)

5 changes: 2 additions & 3 deletions e2e/coreutils/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
module(
name = "coreutils",
compatibility_level = 1,
version = "0.0.0",
compatibility_level = 1,
)

bazel_dep(name = "aspect_bazel_lib", version = "0.0.0")

local_path_override(
module_name = "aspect_bazel_lib",
path = "../..",
)

ext = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "ext")
use_repo(ext, "coreutils_toolchains")
use_repo(ext, "coreutils_toolchains")
2 changes: 1 addition & 1 deletion e2e/smoke/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ diff_test(
"@aspect_bazel_lib//lib:bzlmod": "a_stamp_expected_bzlmod",
"//conditions:default": "a_stamp_expected",
}),
)
)
4 changes: 1 addition & 3 deletions e2e/smoke/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module(
name = "smoke",
compatibility_level = 1,
version = "0.0.0",
compatibility_level = 1,
)

bazel_dep(name = "bazel_skylib", version = "1.1.1")

bazel_dep(name = "aspect_bazel_lib", version = "0.0.0")

local_path_override(
module_name = "aspect_bazel_lib",
path = "../..",
Expand Down
9 changes: 9 additions & 0 deletions internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ def bazel_lib_internal_deps():
],
)

http_archive(
name = "buildifier_prebuilt",
sha256 = "e46c16180bc49487bfd0f1ffa7345364718c57334fa0b5b67cb5f27eba10f309",
strip_prefix = "buildifier-prebuilt-6.1.0",
urls = [
"https://github.com/keith/buildifier-prebuilt/archive/6.1.0.tar.gz",
],
)

# Register toolchains for tests
register_jq_toolchains()
register_yq_toolchains()
Expand Down
7 changes: 3 additions & 4 deletions lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,19 @@ bzl_library(
name = "expand_make_vars",
srcs = ["expand_make_vars.bzl"],
deps = [
":expand_template",
"//lib/private/docs:expand_locations",
"//lib/private/docs:expand_variables",
":expand_template",
],
)


bzl_library(
name = "expand_template",
srcs = ["expand_template.bzl"],
deps = [
"//lib/private/docs:expand_locations",
"//lib/private/docs:expand_variables",
"//lib/private/docs:expand_template",
"//lib/private/docs:expand_variables",
],
)

Expand Down Expand Up @@ -273,4 +272,4 @@ bzl_library(
name = "strings",
srcs = ["strings.bzl"],
deps = ["//lib/private/docs:strings"],
)
)
1 change: 1 addition & 0 deletions lib/expand_make_vars.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ load(":expand_template.bzl", _expand_template = "expand_template")

expand_locations = _expand_locations
expand_variables = _expand_variables

# TODO: 2.0 remove re-export from this file.
expand_template = _expand_template
2 changes: 1 addition & 1 deletion lib/expand_template.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

load("//lib/private:expand_template.bzl", _expand_template = "expand_template")

expand_template = _expand_template
expand_template = _expand_template
6 changes: 3 additions & 3 deletions lib/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ load(
"@aspect_bazel_lib//lib:repositories.bzl",
"register_copy_directory_toolchains",
"register_copy_to_directory_toolchains",
"register_jq_toolchains",
"register_yq_toolchains",
"register_coreutils_toolchains",
"register_expand_template_toolchains",
"register_jq_toolchains",
"register_yq_toolchains",
)
load("//lib/private:host_repo.bzl", "host_repo")

Expand All @@ -18,7 +18,7 @@ def _toolchain_extension(mctx):
register_yq_toolchains(register = False)
register_coreutils_toolchains(register = False)
register_expand_template_toolchains(register = False)

create_host_repo = False
for module in mctx.modules:
if len(module.tags.host) > 0:
Expand Down
4 changes: 2 additions & 2 deletions lib/private/base64.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Implementation based on https://gist.github.com/trondhumbor/ce57c0c2816bb45a8fbb
the subset of python available in Starlark.
"""

load(":strings.bzl", "ord", "chr")
load(":strings.bzl", "chr", "ord")

def decode(data):
"""Decode a Base64 encoded string.
Expand Down Expand Up @@ -339,4 +339,4 @@ def _int_to_binary(i, digits = 8):
fail("expected a int between 0 and 255 (inclusive)")
if digits < 1 or digits > 8:
fail("expected digits to be between 1 and 8 (inclusive)")
return INT_TO_BINARY[i][8 - digits:]
return INT_TO_BINARY[i][8 - digits:]
8 changes: 4 additions & 4 deletions lib/private/docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ bzl_library(
srcs = ["//lib/private:expand_template.bzl"],
deps = [
":expand_locations",
"//lib:stamping",
"@bazel_skylib//lib:dicts",
"//lib:stamping"
],
)

Expand Down Expand Up @@ -229,8 +229,8 @@ bzl_library(
name = "base64",
srcs = ["//lib/private:base64.bzl"],
deps = [
":strings"
]
":strings",
],
)

bzl_library(
Expand All @@ -251,7 +251,7 @@ bzl_library(
bzl_library(
name = "expand_template_toolchain",
srcs = ["//lib/private:expand_template_toolchain.bzl"],
deps = ["//lib:stamping"]
deps = ["//lib:stamping"],
)

bzl_library(
Expand Down
Loading