Skip to content

Commit

Permalink
ci: Introduce buildifier style check (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyawk authored Apr 9, 2024
1 parent c5e035c commit 4ed7d63
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 32 deletions.
14 changes: 14 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Set up environment

runs:
using: composite
steps:
- name: Install bazelisk
shell: bash
run: |
bazelisk_dir="$(realpath "$(mktemp -d -p .)")"
wget https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-amd64 \
-O "${bazelisk_dir}/bazelisk"
chmod +x "${bazelisk_dir}/bazelisk"
echo "${bazelisk_dir}" >> "${GITHUB_PATH}"
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: Run unit tests
on:
push:
branches:
- main
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
unit-test:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Set up
uses: ./.github/actions/setup
- name: Run unit tests
run: ./execute_tests.bash

style-check:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Set up
uses: ./.github/actions/setup
- name: Run formatters and linters
run: ./style_check.bash
- name: Fail if some files are changed
run: |
if ! git diff --exit-code; then
echo "ERROR: Files are changed by formatters" >&2
exit 1
fi
29 changes: 0 additions & 29 deletions .github/workflows/unit-tests.yml

This file was deleted.

10 changes: 7 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
"""Module for `rules_build_error`.
"""

module(name = "rules_build_error", version = "0.1.0")
module(
name = "rules_build_error",
version = "0.1.0",
)

bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True)

bazel_dep(name = "toolchains_llvm", version = "1.0.0", dev_dependency = True)

llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(
llvm_version = "17.0.6",
)

use_repo(llvm, "llvm_toolchain")

register_toolchains("@llvm_toolchain//:all")

bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)
20 changes: 20 additions & 0 deletions style_check.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
#
# Code style checker (linter and formatter)

set -euo pipefail

# Bazel executable with some arguments
BAZEL_EXECUTABLE=(
"env"
"-i"
BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
BAZELISK_HOME=.cache/bazelisk
"HOME=${HOME}"
"PATH=${PATH}"
bazelisk
)

buildifier_targets="$(git ls-files *.bzl *.bazel BUILD WORKSPACE MODULE | xargs -I{} echo "$(pwd)/{}")"

"${BAZEL_EXECUTABLE[@]}" run -- @buildifier_prebuilt//:buildifier -lint=fix ${buildifier_targets}

0 comments on commit 4ed7d63

Please sign in to comment.