Skip to content

Commit

Permalink
[CI] Split things up using test matrix (#173)
Browse files Browse the repository at this point in the history
* [CI] Split things up using test matrix

* Create buildifier.yaml

* Update main.yml

* Update buildifier.yaml

* Create BUILD.bazel

* Formatting

* More fixes

* Don't run the bzlmod tests

* Mount caches
  • Loading branch information
Bencodes authored Feb 6, 2024
1 parent 2f9ffb2 commit f064701
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 25 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@buildifier_prebuilt//:rules.bzl", "buildifier")

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

buildifier(
name = "buildifier.fix",
disabled_rewrites = [
"label",
],
exclude_patterns = ["./.git/*"],
lint_mode = "fix",
)
26 changes: 26 additions & 0 deletions .github/workflows/buildifier.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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: [master]
pull_request:
branches: [master]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: buildifier
run: bazel run --enable_bzlmod //.github/workflows:buildifier.check
shellcheck:
runs-on: ubuntu-latest
steps:
- name: "Checkout the sources"
uses: actions/checkout@v4
- name: "Lint Shell files"
run: for file in $(ind . -type f -name "*.sh" -not -path "./.github/*"); do shellcheck $file; done;
80 changes: 57 additions & 23 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
name: CI

# Controls when the action will run.
on:
pull_request:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches:
- "master"
branches: [ master ]
pull_request:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

concurrency:
# Cancel previous actions from the same PR: https://stackoverflow.com/a/72408109
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
buildifier:
runs-on: ubuntu-latest
build:
strategy:
matrix:
os: [ ubuntu-latest ]
bzlmod: [ true, false ]
runs-on: ${{ matrix.os }}
steps:
- name: "Checkout the sources"
uses: actions/checkout@v4
Expand All @@ -17,15 +30,25 @@ jobs:
with:
distribution: "zulu"
java-version: "11"
- name: Mount bazel caches
uses: actions/cache@v4
with:
path: |
~/.cache/bazel
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', 'WORKSPACE.bazel') }}
restore-keys: bazel-cache-
- name: "Setup Bazelisk"
uses: bazelbuild/setup-bazelisk@v2
- name: "Linting Starlark"
run: bazel run @buildifier_prebuilt//:buildifier -- -mode check -lint warn -r .
- name: "Lint Shell files"
run: for file in $(ind . -type f -name "*.sh" -not -path "./.github/*"); do shellcheck $file; done;

build-bzlmod:
runs-on: ubuntu-latest
- name: "Configure Bazel"
run: cp .github/workflows/ci.bazelrc .
- name: "Build"
run: bazel build //detekt/wrapper:bin --enable_bzlmod=${{ matrix.bzlmod }}
test:
strategy:
matrix:
os: [ ubuntu-latest ]
bzlmod: [ true ]
runs-on: ${{ matrix.os }}
steps:
- name: "Checkout the sources"
uses: actions/checkout@v4
Expand All @@ -34,18 +57,24 @@ jobs:
with:
distribution: "zulu"
java-version: "11"
- name: Mount bazel caches
uses: actions/cache@v4
with:
path: |
~/.cache/bazel
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', 'WORKSPACE.bazel') }}
restore-keys: bazel-cache-
- name: "Setup Bazelisk"
uses: bazelbuild/setup-bazelisk@v2
- name: "Configure Bazel"
run: cp .github/workflows/ci.bazelrc .
- name: "Build"
run: bazel build //detekt/wrapper:bin --enable_bzlmod=True
- name: "Unit tests"
run: bazel test //... --enable_bzlmod=True
- name: "Integration tests"
run: bash tests/integration/suite.sh
build-workspace:
runs-on: ubuntu-latest
run: bazel test //... --enable_bzlmod=${{ matrix.bzlmod }}
integration-test:
strategy:
matrix:
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: "Checkout the sources"
uses: actions/checkout@v4
Expand All @@ -54,11 +83,16 @@ jobs:
with:
distribution: "zulu"
java-version: "11"
- name: Mount bazel caches
uses: actions/cache@v4
with:
path: |
~/.cache/bazel
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', 'WORKSPACE.bazel') }}
restore-keys: bazel-cache-
- name: "Setup Bazelisk"
uses: bazelbuild/setup-bazelisk@v2
- name: "Configure Bazel"
run: cp .github/workflows/ci.bazelrc .
- name: "Build"
run: bazel build //detekt/wrapper:bin --enable_bzlmod=False
- name: "Unit tests"
run: bazel test //detekt/... --enable_bzlmod=False
- name: "Integration tests"
run: bash tests/integration/suite.sh
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use_repo(detekt, "detekt_cli_all")
bazel_dep(name = "rules_java", version = "5.5.0")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "rules_jvm_external", version = "5.3")

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
name = "rules_detekt_dependencies",
Expand All @@ -29,5 +30,5 @@ maven.install(
use_repo(maven, "rules_detekt_dependencies", "unpinned_rules_detekt_dependencies")

bazel_dep(name = "bazel_skylib", version = "1.4.1", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.5.3", repo_name = "io_bazel_stardoc", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.5.3", dev_dependency = True, repo_name = "io_bazel_stardoc")
bazel_dep(name = "buildifier_prebuilt", version = "6.3.3", dev_dependency = True)
3 changes: 3 additions & 0 deletions detekt/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Bzlmod extensions for detekt
"""

load(
"@bazel_tools//tools/build_defs/repo:http.bzl",
"http_jar",
Expand Down
3 changes: 3 additions & 0 deletions detekt/versions.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Macro for defining detekt versions.
"""

def detekt_version(version, sha256):
"""Create a detekt version.
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ detekt(
name = "detekt_without_config_with_baseline_with_plugin",
srcs = glob(["src/main/kotlin/**/*.kt"]),
baseline = "detekt_baseline.xml",
tags = ["manual"],
plugins = ["@rules_detekt_dependencies//:io_gitlab_arturbosch_detekt_detekt_formatting"],
tags = ["manual"],
)

detekt(
Expand Down

0 comments on commit f064701

Please sign in to comment.