Skip to content
Draft
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
32 changes: 32 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
###############################################################################
## rules_shellcheck bazel configuration
###############################################################################

# Ensure errors are logged to the console
test --test_output=errors

# Fix the excessive rebuilding when using anything that depends on protobuf rules
# See https://github.com/bazelbuild/buildtools/issues/744
common --incompatible_strict_action_env

# Use modern dependency resolution
common --enable_bzlmod

# Speed up builds by skipping the creation of runfile links
build --nobuild_runfile_links

# https://github.com/bazelbuild/bazel/issues/8195
build --incompatible_disallow_empty_glob=true

# https://github.com/bazelbuild/bazel/issues/12821
build --nolegacy_external_runfiles

# Disable network access in sandboxes by default.
build --sandbox_default_allow_network=false

# https://github.com/bazelbuild/bazel/issues/19981
common --incompatible_auto_exec_groups

# https://github.com/bazelbuild/bazel/issues/23043
build --incompatible_autoload_externally=

# https://github.com/bazelbuild/bazel/issues/12933
build --incompatible_config_setting_private_default_visibility

###############################################################################
## Custom user flags
###############################################################################

try-import user.bazelrc

# To update these lines, execute
Expand Down
2 changes: 1 addition & 1 deletion .bcr/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
bcr_test_module:
module_path: "examples/check_glob"
matrix:
platform: ["debian10", "macos", "ubuntu2004"]
platform: ["debian10", "macos", "ubuntu2004", "windows"]
bazel: [7.*, 8.*, 9.*]
tasks:
run_tests:
Expand Down
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# cmd.exe resolves labels unreliably in batch files with LF line endings, so
# batch files are always checked out as CRLF. Shell scripts and shellcheck
# configuration must stay LF, otherwise shellcheck reports the carriage
# returns (and the scripts fail to run) when checked out on Windows.
*.bat text eol=crlf
*.cmd text eol=crlf
*.sh text eol=lf
.shellcheckrc text eol=lf
16 changes: 16 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
- os: ubuntu-latest
- os: windows-latest

steps:
- uses: actions/checkout@v7
Expand All @@ -29,7 +31,21 @@ jobs:
- name: Test
run: bazel test //...

# The examples double as integration tests of the rules as consumed
# from another module. They are run in place here so that every
# platform in the matrix covers them, including Windows where the
# release archive is not produced.
- name: Test example (check_glob)
run: bazel test //...
working-directory: examples/check_glob

- name: Test example (optional_attributes)
run: bazel test //...
working-directory: examples/optional_attributes

- name: Create release archive and notes
# Packaging shells out to Unix tools; see //internal/pkg.
if: runner.os != 'Windows'
# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
run: ./ci/package.sh "${{ github.ref_name }}"
Expand Down
2 changes: 0 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ filegroup(
name = "distribution",
srcs = [
"BUILD.bazel",
"def.bzl",
"deps.bzl",
"CHANGELOG.md",
"LICENSE",
"MODULE.bazel",
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This document is maintaining changes since the last released version (0.1.1)
* Add a `targets` attribute to {obj}`shellcheck_test` for linting `rules_shell` targets and their transitive `deps`.
* Add `//shellcheck/settings:check_generated` and a matching tri-state `check_generated` attribute on
{obj}`shellcheck_test` for linting generated sources.
* Add Windows support, using [rules_batch](https://github.com/periareon/rules_batch) to locate runfiles.

## v0.6.1

Expand Down
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module(

bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "rules_batch", version = "0.1.1")
bazel_dep(name = "rules_shell", version = "0.7.1")

shellcheck = use_extension("//shellcheck/internal:extensions.bzl", "shellcheck")
Expand Down
5 changes: 0 additions & 5 deletions WORKSPACE

This file was deleted.

1 change: 1 addition & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace(name = "rules_shellcheck")
9 changes: 0 additions & 9 deletions def.bzl

This file was deleted.

9 changes: 0 additions & 9 deletions deps.bzl

This file was deleted.

8 changes: 0 additions & 8 deletions examples/check_glob/WORKSPACE

This file was deleted.

1 change: 1 addition & 0 deletions examples/check_glob/WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace(name = "check_glob")
8 changes: 0 additions & 8 deletions examples/optional_attributes/WORKSPACE

This file was deleted.

1 change: 1 addition & 0 deletions examples/optional_attributes/WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace(name = "optional_attributes")
11 changes: 10 additions & 1 deletion internal/pkg/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("//:def.bzl", "shellcheck_test")
load("//shellcheck:shellcheck_test.bzl", "shellcheck_test")

# Packaging shells out to Unix tools (`gzip`, `grep`, `sed`); dependents such
# as :release and :release.shellcheck inherit the incompatibility.
_NOT_WINDOWS = select({
"@platforms//os:windows": ["@platforms//:incompatible"],
"//conditions:default": [],
})

pkg_files(
name = "files",
Expand Down Expand Up @@ -30,6 +37,7 @@ pkg_tar(
":files",
],
out = "rules_shellcheck.tar",
target_compatible_with = _NOT_WINDOWS,
)

genrule(
Expand All @@ -48,6 +56,7 @@ genrule(
"sed \"s|{BUILD_EMBED_LABEL}|$$BUILD_EMBED_LABEL|g\" $< >$@",
]),
stamp = 1,
target_compatible_with = _NOT_WINDOWS,
)

sh_binary(
Expand Down
18 changes: 0 additions & 18 deletions internal/pkg/release_notes.tmpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,3 @@ Add to your `MODULE.bazel` file:
```starlark
bazel_dep(name = "rules_shellcheck", version = "%%TAG%%")
```

## Legacy: using WORKSPACE

Paste this snippet into your `WORKSPACE` file:

```starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_shellcheck",
sha256 = "%%SHA256%%",
url = "https://github.com/aignas/rules_shellcheck/releases/download/%%TAG%%/rules_shellcheck-%%TAG%%.tar.gz",
)

load("@rules_shellcheck//:deps.bzl", "shellcheck_dependencies")

shellcheck_dependencies()
```
32 changes: 27 additions & 5 deletions shellcheck/internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
_EXECUTABLES = [
"aspect_runner.sh",
"test_runner.sh",
]

filegroup(
name = "distribution",
srcs = glob(
["*"],
exclude = ["aspect_runner.sh"],
exclude = _EXECUTABLES,
),
visibility = ["//shellcheck:__pkg__"],
)

# Split out so //internal/pkg can package these with mode 0755;
# aspect_runner.sh is invoked as the executable of ctx.actions.run
# and must be +x when consumed from the release tarball.
# Split out so //internal/pkg can package these with mode 0755; they are
# invoked as executables and must be +x when consumed from the release tarball.
filegroup(
name = "executable_distribution",
srcs = ["aspect_runner.sh"],
srcs = _EXECUTABLES,
visibility = ["//shellcheck:__pkg__"],
)

Expand All @@ -24,3 +28,21 @@ alias(
}),
visibility = ["//visibility:public"],
)

alias(
name = "test_runner",
actual = select({
"@platforms//os:windows": "test_runner.bat",
"//conditions:default": "test_runner.sh",
}),
visibility = ["//visibility:public"],
)

alias(
name = "runfiles_lib",
actual = select({
"@platforms//os:windows": "@rules_batch//batch/runfiles",
"//conditions:default": "@rules_shell//shell/runfiles",
}),
visibility = ["//visibility:public"],
)
34 changes: 14 additions & 20 deletions shellcheck/internal/aspect_runner.bat
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
@echo off
@ECHO OFF
setlocal enabledelayedexpansion

set "output=%~1"
shift

if not "%~1"=="--" (
echo aspect_runner: expected '--' after output path, got: %~1 1>&2
exit /b 1
@REM Usage: aspect_runner.bat <output> -- <shellcheck> [args...]
@REM
@REM Arguments are split from the full argument string because cmd.exe also
@REM splits numbered parameters on "=" (as in --rcfile=...). Forward slashes
@REM are replaced since cmd.exe cannot run a command whose path contains them.
set "args=%*"
for /F "usebackq tokens=1,2,3,*" %%A in ('!args!') do (
set "output=%%~A"
set "shellcheck=%%~C"
set "shellcheck_args=%%D"
)
shift

break > "%output%"

set "cmd="
:loop
if "%~1"=="" goto :run
set "cmd=!cmd! %1"
shift
goto :loop

:run
%cmd%
exit /b %errorlevel%
type nul > "!output:/=\!"
"!shellcheck:/=\!" !shellcheck_args!
exit /b !ERRORLEVEL!
6 changes: 4 additions & 2 deletions shellcheck/internal/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,11 @@ def shellcheck_dependencies():
toolchains = toolchains,
)

def _impl(_):
def _shellcheck_impl(module_ctx):
shellcheck_dependencies()

return module_ctx.extension_metadata(reproducible = True)

shellcheck = module_extension(
implementation = _impl,
implementation = _shellcheck_impl,
)
Loading
Loading