Compare commits

..

28 Commits

Author SHA1 Message Date
Francisco Robles Martín
ee95a7cad6
Fix error message when pom or build.gradle are detected (#48) 2024-12-29 22:47:55 +07:00
Dwi Siswanto
616b2df627
docs: update blockquote notes
(adapt https://github.com/orgs/community/discussions/16925)

Signed-off-by: Dwi Siswanto <me@dw1.io>
2023-11-17 21:22:58 +07:00
Ivan Schaller
72254bbe1e fix project basedir path
Signed-off-by: Ivan Schaller <ivan@schaller.sh>
2023-09-25 15:20:37 +07:00
Dwi Siswanto
9017aabde4
chore: update CODEOWNERS 2023-09-12 06:20:22 +07:00
Dwi Siswanto
a76da8f0e6
docs: update README 2023-09-12 06:18:51 +07:00
Dwi Siswanto
513476d3b8 Update readme 2022-06-16 12:34:30 +07:00
Dwi Siswanto
b3336b356f update(entrypoint): code-style & sonar sources pointing to project base dir 2022-06-16 12:33:59 +07:00
Dwi Siswanto
214c4b604a update(entrypoint): remove conditional trigger event & dynamic source encoding
and code-style
2022-06-16 12:28:38 +07:00
Dwi Siswanto
70d39d8c86 Add source encoding 2022-06-16 12:28:25 +07:00
Dwi Siswanto
7e63816c89 Update readme 2022-06-16 12:28:13 +07:00
Dwi Siswanto
9d60bddfc9 update(entrypoint): exit early on Maven/Gradle project, and
- display warning on auth w/o using token
- proper `sonar-project.properties` link
- unset `JAVA_HOME` environment (fix #31)
2022-06-16 12:02:05 +07:00
Dwi Siswanto
c17fe0c59d Update wording 2022-06-16 12:01:28 +07:00
Dwi Siswanto
c4b2851844 Remove unused code 2022-06-16 11:47:29 +07:00
Dwi Siswanto
2796ffc8b5 misc: Wording 2022-06-16 11:13:04 +07:00
Dwi Siswanto
b87ffe4bf5 Update readme 2022-06-16 10:27:37 +07:00
Erdem Karasahin
16486220f2 docker build fail && please check 2022-06-16 10:25:32 +07:00
Dwi Siswanto
d7e1e2bb60 misc: Update code owners 2021-12-17 13:57:02 +07:00
Dwi Siswanto
10a365b29a
Merge pull request #30 from leonardomerlin/patch-1
fix: use official sonnar scanner docker image
2021-10-22 05:33:28 +07:00
Leonardo Merlin
8c154cc36b
fix: use official sonnar scanner docker image
the `newtmitch/docker-sonar-scanner` is not official and not up-to-date with the latest version of sonar.
2021-10-21 10:35:20 +02:00
Dwi Siswanto
c7058a020f Use stable release tag instead of master 2021-04-01 18:43:16 +07:00
dw1
9b52913486
Merge pull request #20 from jankal/master
Update docker base image & respect sonar-project.properties
2020-12-29 09:55:24 +07:00
Alexander Jank
532659cc88
fix(entrypoint): use bash condition correctly 2020-12-20 00:12:55 +01:00
Alexander Jank
c94954550f
fix code-style & reference WORKSPACE dir for file detection 2020-12-18 08:48:17 +00:00
Alexander Jank
9b7b1d0336
update base image; respect sonar-project.properties 2020-12-17 23:23:49 +00:00
Dwi Siswanto
a40c5bc8f6 ✏️ Remove exit status if event action is push 2020-11-09 22:59:28 +07:00
Dwi Siswanto
7da9810073 🔨 Justify scripts 2020-10-11 19:11:26 +07:00
Dwi Siswanto
276b0c8370
Merge pull request #10 from kitabisa/development
🪲 Use GitHub environment instead of child workdir name as defa…
2020-07-26 06:08:30 +07:00
Dwi Siswanto
6c4cd0d6d9 🪲 Use GitHub environment instead of child workdir name as default value of project key & name 2020-07-26 03:20:28 +07:00
5 changed files with 92 additions and 50 deletions

1
CODEOWNERS Normal file
View File

@ -0,0 +1 @@
* @dwisiswant0

View File

@ -1,22 +1,15 @@
FROM newtmitch/sonar-scanner:4.0.0-alpine
FROM sonarsource/sonar-scanner-cli:4
LABEL "com.github.actions.name"="SonarQube Scan"
LABEL "com.github.actions.description"="Scan your code with SonarQube Scanner to detect bugs, vulnerabilities and code smells in more than 25 programming languages."
LABEL "com.github.actions.icon"="check"
LABEL "com.github.actions.color"="green"
LABEL version="0.0.1"
LABEL version="0.0.2"
LABEL repository="https://github.com/kitabisa/sonarqube-action"
LABEL homepage="https://kitabisa.github.io"
LABEL maintainer="dwisiswant0"
RUN npm config set unsafe-perm true && \
npm install --silent --save-dev -g typescript@3.5.2 && \
npm config set unsafe-perm false
ENV NODE_PATH "/usr/lib/node_modules/"
RUN apk add --no-cache ca-certificates jq
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -2,52 +2,76 @@
Using this GitHub Action, scan your code with SonarQube scanner to detects bugs, vulnerabilities and code smells in more than 20 programming languages!
<img src="https://www.sonarqube.org/assets/logo-31ad3115b1b4b120f3d1efd63e6b13ac9f1f89437f0cf6881cc4d8b5603a52b4.svg" width="320px">
<img src="https://assets-eu-01.kc-usercontent.com/d1e40bf0-65fc-01ef-5235-9aeaedac229b/12e3974b-220d-4cde-8f17-2ff9fa9d9c27/SonarQube_Logo.svg" width="320px">
SonarQube is an open-source platform developed by SonarSource for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells, and security vulnerabilities on 20+ programming languages.
## Requirements
* Have SonarQube on server. [Install now](https://docs.sonarqube.org/latest/setup/install-server/) if it's not already the case!
* [SonarQube server](https://docs.sonarqube.org/latest/setup/install-server/).
* That's all!
## Usage
The workflow, usually declared in `.github/workflows/build.yml`, looks like:
The workflow, usually declared in `.github/workflows/build.yaml`, looks like:
```yaml
on: push
name: Main Workflow
on:
# Trigger analysis when pushing in master or pull requests, and when creating
# a pull request.
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
name: SonarQube Scan
jobs:
sonarQubeTrigger:
sonarqube:
name: SonarQube Trigger
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Checking out
uses: actions/checkout@master
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- name: SonarQube Scan
uses: kitabisa/sonarqube-action@master
uses: kitabisa/sonarqube-action@v1.2.0
with:
host: ${{ secrets.SONARQUBE_HOST }}
login: ${{ secrets.SONARQUBE_TOKEN }}
```
You can change the analysis base directory and/ project key _(allowed characters: letters, numbers, -, \_, . and :, with at least one non-digit.)_ by using the optional input like this:
You can change the analysis base directory and/or project key by using the optional input like this:
```yaml
uses: kitabisa/sonarqube-action@master
with:
projectBaseDir: "/path/to/my-custom-project"
host: ${{ secrets.SONARQUBE_HOST }}
login: ${{ secrets.SONARQUBE_TOKEN }}
projectBaseDir: "src/"
projectKey: "my-custom-project"
projectName: "my-custom-project-name"
projectVersion: "v0.0.1"
```
## Secrets
### Inputs
- `host` - **_(Required)_** this is the SonarQube server URL.
- `login` - **_(Required)_** the login or authentication token of a SonarQube user with Execute Analysis permission on the project. See [how to generate SonarQube token](https://docs.sonarqube.org/latest/user-guide/user-token/).
- `password` - The password that goes with the `login` username. This should be left blank if an `login` are authentication token.
These are some of the supported input parameters of action.
You can set all variable in the "Secrets" settings page of your repository.
| **Parameter** | **Description** | **Required?** | **Default** | **Note** |
|----------------------|---------------------------------------------------|---------------|-------------|-----------------------------------------------------------------------------------------------|
| **`host`** | SonarQube server URL | 🟢 | | |
| **`login`** | Login or authentication token of a SonarQube user | 🟢 | | `Execute Analysis` permission required. |
| **`password`** | The password that goes with the `login` username | 🔴 | | This should be left blank if an `login` are authentication token. |
| **`projectBaseDir`** | Set custom project base directory analysis | 🔴 | `.` | |
| **`projectKey`** | The project's unique key | 🔴 | | Allowed characters are: letters, numbers, `-`, `_`, `.` and `:`, with at least one non-digit. |
| **`projectName`** | Name of the project | 🔴 | | It will be displayed on the SonarQube web interface. |
| **`projectVersion`** | The project version | 🔴 | | |
| **`encoding`** | Encoding of the source code | 🔴 | `UTF-8` | |
> [!NOTE]
> If you opt to configure the project metadata and other related settings in a **`sonar-project.properties`** file (must be placed within the base directory, `projectBaseDir`) instead of using input parameters, this action is compatible with that approach!
## License

View File

@ -1,15 +1,18 @@
name: "SonarQube Scan"
description: "Scan your code with SonarQube Scanner to detect bugs, vulnerabilities and code smells in more than 25 programming languages."
author: "Dwi Siswanto"
branding:
icon: "check"
color: "green"
runs:
using: "docker"
image: "Dockerfile"
inputs:
host:
description: "SonarQube server URL"
description: "SonarQube server URL."
required: true
projectKey:
description: "The project's unique key. Allowed characters are: letters, numbers, -, _, . and :, with at least one non-digit."
@ -24,12 +27,16 @@ inputs:
required: false
default: ""
projectBaseDir:
description: "Set the sonar.projectBaseDir analysis property"
description: "Set the sonar.projectBaseDir analysis property."
required: false
default: "."
login:
description: "Login or authentication token of a SonarQube user"
description: "Login or authentication token of a SonarQube user."
required: true
password:
description: "Password that goes with the sonar.login username. This should be left blank if an authentication token is being used."
required: false
required: false
encoding:
description: "Encoding of the source code."
required: false
default: "UTF-8"

View File

@ -2,27 +2,44 @@
set -e
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
EVENT_ACTION=$(jq -r ".action" "${GITHUB_EVENT_PATH}")
if [[ "${EVENT_ACTION}" != "opened" ]]; then
echo "No need to run analysis. It is already triggered by the push event."
exit 78
fi
REPOSITORY_NAME=$(basename "${GITHUB_REPOSITORY}")
if [[ ! -z "${INPUT_PASSWORD}" ]]; then
echo "::warning ::Running this GitHub Action without authentication token is NOT recommended!"
SONAR_PASSWORD="${INPUT_PASSWORD}"
else
SONAR_PASSWORD=""
fi
[[ ! -z ${INPUT_PASSWORD} ]] && SONAR_PASSWORD="${INPUT_PASSWORD}" || SONAR_PASSWORD=""
[[ -z ${INPUT_PROJECTKEY} ]] && SONAR_PROJECTKEY="${PWD##*/}" || SONAR_PROJECTKEY="${INPUT_PROJECTKEY}"
[[ -z ${INPUT_PROJECTNAME} ]] && SONAR_PROJECTNAME="${PWD##*/}" || SONAR_PROJECTNAME="${INPUT_PROJECTNAME}"
[[ -z ${INPUT_PROJECTVERSION} ]] && SONAR_PROJECTVERSION="" || SONAR_PROJECTVERSION="${INPUT_PROJECTVERSION}"
if [[ -f "${INPUT_PROJECTBASEDIR%/}/pom.xml" ]]; then
echo "::error file=${INPUT_PROJECTBASEDIR%/}/pom.xml::Maven project detected. You should run the goal 'org.sonarsource.scanner.maven:sonar' during build rather than using this GitHub Action."
exit 1
fi
if [[ -f "${INPUT_PROJECTBASEDIR%/}/build.gradle" ]]; then
echo "::error file=${INPUT_PROJECTBASEDIR%/}/build.gradle::Gradle project detected. You should use the SonarQube plugin for Gradle during build rather than using this GitHub Action."
exit 1
fi
sonar-scanner \
-Dsonar.host.url=${INPUT_HOST} \
-Dsonar.projectKey=${SONAR_PROJECTKEY} \
-Dsonar.projectName=${SONAR_PROJECTNAME} \
-Dsonar.projectVersion=${SONAR_PROJECTVERSION} \
-Dsonar.projectBaseDir=${INPUT_PROJECTBASEDIR} \
-Dsonar.login=${INPUT_LOGIN} \
-Dsonar.password=${INPUT_PASSWORD} \
-Dsonar.sources=. \
-Dsonar.sourceEncoding=UTF-8
unset JAVA_HOME
if [[ ! -f "${INPUT_PROJECTBASEDIR%/}/sonar-project.properties" ]]; then
[[ -z "${INPUT_PROJECTKEY}" ]] && SONAR_PROJECTKEY="${REPOSITORY_NAME}" || SONAR_PROJECTKEY="${INPUT_PROJECTKEY}"
[[ -z "${INPUT_PROJECTNAME}" ]] && SONAR_PROJECTNAME="${REPOSITORY_NAME}" || SONAR_PROJECTNAME="${INPUT_PROJECTNAME}"
[[ -z "${INPUT_PROJECTVERSION}" ]] && SONAR_PROJECTVERSION="" || SONAR_PROJECTVERSION="${INPUT_PROJECTVERSION}"
sonar-scanner \
-Dsonar.host.url="${INPUT_HOST}" \
-Dsonar.projectKey="${SONAR_PROJECTKEY}" \
-Dsonar.projectName="${SONAR_PROJECTNAME}" \
-Dsonar.projectVersion="${SONAR_PROJECTVERSION}" \
-Dsonar.projectBaseDir="${INPUT_PROJECTBASEDIR}" \
-Dsonar.login="${INPUT_LOGIN}" \
-Dsonar.password="${SONAR_PASSWORD}" \
-Dsonar.sources="${INPUT_PROJECTBASEDIR}" \
-Dsonar.sourceEncoding="${INPUT_ENCODING}"
else
sonar-scanner \
-Dsonar.host.url="${INPUT_HOST}" \
-Dsonar.login="${INPUT_LOGIN}" \
-Dsonar.password="${SONAR_PASSWORD}"
fi