Skip to content
Open
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
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.4.1
7.6.1
56 changes: 56 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

# Controls when the action will run.
on:
push:
branches: [master]
pull_request:
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:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: bazel-contrib/setup-bazel@0.15.0

- name: sonar canner build
run: |
bazel build //:sonar_scanner
bazel build //:sonarqube_coverage_generator

# TODO Building //docs:docs has missing dependencies to rules_java
# and it is failing
# - name: bazel aquery
# run: |
# bazel aquery ...

test:
runs-on: ubuntu-latest
strategy:
matrix:
folder:
- examples/java-workspace
- examples/java-bzlmod
steps:
- uses: actions/checkout@v5
- uses: bazel-contrib/setup-bazel@0.15.0

- name: test coverage
working-directory: ${{ matrix.folder }}
run: |
bazel coverage //...
bazel build //:sonarqube

- name: sonarqube report
working-directory: ${{ matrix.folder }}
# TODO We don't have sonar server to send scan results
continue-on-error: True
run: |
bazel run //:sonarqube

11 changes: 5 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
module(
name = "bazel_sonarqube",
version = "1.0.3",
version = "1.0.5",
compatibility_level = 1,
repo_name = "bazel_sonarqube",
)

bazel_dep(name = "bazel_skylib", version = "1.7.1", repo_name = "bazel_skylib")
bazel_dep(name = "rules_java", version = "8.11.0")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_java", version = "8.16.1")

bazel_dep(
name = "stardoc",
version = "0.7.2",
dev_dependency = True,
repo_name = "io_bazel_stardoc",
version = "0.8.0",
dev_dependency = True
)

non_module_dependencies = use_extension("//:extensions.bzl", "non_module_dependencies")
Expand Down
1,255 changes: 84 additions & 1,171 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,26 @@ Add the following to your `MODULE.bazel` file, setting the `version` to the late
available on [Bazel Central Registry](https://registry.bazel.build/modules/bazel_sonarqube):

```python
bazel_dep(name = "bazel_sonarqube", version = "...")
bazel_dep(name = "bazel_sonarqube", version = "...", dev_dependency = True)
```

#### Change version of the sonar_scanner_cli

All possible `sonar_scanner_cli` versions could be found [on github page](https://github.com/SonarSource/sonar-scanner-cli/releases).
Together with version you must provide [SHA-256](https://en.wikipedia.org/wiki/SHA-2).
The easiest way to get `SHA-256` is run command `bazel aquery ...`.
It will display error with desired and current hash.

Example of usage:

```python
bazel_dep(name = "bazel_sonarqube", version = "...", dev_dependency = True)
non_module_dependencies = use_extension("@bazel_sonarqube//:extensions.bzl", "non_module_dependencies")
non_module_dependencies.settings(
sonar_scanner_cli_version = "6.0.0.4432",
sonar_scanner_cli_sha256 = "965a18c438a213aa2167b51c793116987bc2a9df9ad245c8e02d3ab3e54022e7",
)
use_repo(non_module_dependencies, "org_sonarsource_scanner_cli_sonar_scanner_cli")
```

### With WORKSPACE file (legacy)
Expand Down Expand Up @@ -72,9 +91,9 @@ To execute a SonarQube analysis of a Bazel project, two rules are provided:
`sonarqube` and `sq_project`.

The `sonarqube` rule creates an executable target which will generate SonarQube
sonar-project.properties configuration files, and execute the CLI scanner.
`sonar-project.properties` configuration files, and execute the CLI scanner.

The `sq_project` rule provides the generation of sonar-project.properties
The `sq_project` rule provides the generation of `sonar-project.properties`
configuration, and can be used to create sub-module configurations to be
included in a `sonarqube` target.

Expand All @@ -94,14 +113,12 @@ filegroup(
name = "coverage_report",
srcs = ["bazel-out/_coverage/_coverage_report.dat"], # Created manually
tags = ["manual"],
visibility = ["//visibility:public"],
)

filegroup(
name = "test_reports",
srcs = glob(["bazel-testlogs/**/test.xml"]), # Created manually
tags = ["manual"],
visibility = ["//visibility:public"],
)

load("@bazel_sonarqube//:defs.bzl", "sonarqube")
Expand All @@ -128,6 +145,10 @@ sonarqube(
)
```

The `name` attribute is target name. It is optional attribute, needed when
multiple `sonarqube` is used in the same `BUILD` package.
If not specifie `sonarscan` target name is used.

The `srcs` and `test_srcs` attributes may refer to individual files or
`filegroup` targets.

Expand Down
3 changes: 2 additions & 1 deletion docs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
load("@stardoc//stardoc:stardoc.bzl", "stardoc")


stardoc(
name = "docs",
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions examples/java-bzlmod/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.6.1
2 changes: 0 additions & 2 deletions examples/java/BUILD → examples/java-bzlmod/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ filegroup(
exclude = [".git/**/*[*"], # gitk creates temp files with []
),
tags = ["manual"],
visibility = ["//visibility:public"],
)

filegroup(
name = "coverage_report",
srcs = ["bazel-out/_coverage/_coverage_report.dat"], # Created manually
tags = ["manual"],
visibility = ["//visibility:public"],
)

filegroup(
Expand Down
21 changes: 21 additions & 0 deletions examples/java-bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
###############################################################################
# Bazel now uses Bzlmod by default to manage external dependencies.
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
#
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
###############################################################################

bazel_dep(name = "bazel_sonarqube", version = "1.0.3", dev_dependency = True)
non_module_dependencies = use_extension("@bazel_sonarqube//:extensions.bzl", "non_module_dependencies")
# TODO This needs to be uncommented after 1.0.5 release
# non_module_dependencies.settings(
# sonar_scanner_cli_version = "7.2.0.5079",
# sonar_scanner_cli_sha256 = "30d80b37c8f4be1254b6c43ec8c64291798d97a710c28475958b5e2f10809fe1",
# )
use_repo(non_module_dependencies, "org_sonarsource_scanner_cli_sonar_scanner_cli")

bazel_dep(name = "rules_jvm_external", version = "6.8")

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")

use_repo(maven, "maven")
Loading
Loading