diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..14088c9 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -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}" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..b288b6f --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml deleted file mode 100644 index 4ddd675..0000000 --- a/.github/workflows/unit-tests.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -name: Run unit tests -on: - push: - branches: - - main - pull_request: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - unit-tests: - runs-on: ubuntu-22.04 - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - name: Install bazelisk - 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}" - - name: Run unit tests - run: ./execute_tests.bash diff --git a/MODULE.bazel b/MODULE.bazel index 442b90b..2d9dca9 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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) diff --git a/style_check.bash b/style_check.bash new file mode 100755 index 0000000..10b24c2 --- /dev/null +++ b/style_check.bash @@ -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}