9 Commits

Author SHA1 Message Date
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
4 changed files with 79 additions and 48 deletions

View File

@@ -10,11 +10,6 @@ LABEL repository="https://github.com/kitabisa/sonarqube-action"
LABEL homepage="https://kitabisa.github.io" LABEL homepage="https://kitabisa.github.io"
LABEL maintainer="dwisiswant0" LABEL maintainer="dwisiswant0"
ENV NODE_PATH "/usr/lib/node_modules/"
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -8,46 +8,67 @@ SonarQube is an open-source platform developed by SonarSource for continuous ins
## Requirements ## 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 ## Usage
The workflow, usually declared in `.github/workflows/build.yml`, looks like: The workflow, usually declared in `.github/workflows/build.yaml`, looks like:
```yaml ```yaml
on: push on:
name: Main Workflow # 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: jobs:
sonarQubeTrigger: sonarqube:
name: SonarQube Trigger name: SonarQube Trigger
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: 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 - name: SonarQube Scan
uses: kitabisa/sonarqube-action@v1.1.2 uses: kitabisa/sonarqube-action@v1.2.0
with: with:
host: ${{ secrets.SONARQUBE_HOST }} host: ${{ secrets.SONARQUBE_HOST }}
login: ${{ secrets.SONARQUBE_TOKEN }} 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 ```yaml
uses: kitabisa/sonarqube-action@master uses: kitabisa/sonarqube-action@master
with: with:
projectBaseDir: "/path/to/my-custom-project" host: ${{ secrets.SONARQUBE_HOST }}
login: ${{ secrets.SONARQUBE_TOKEN }}
projectBaseDir: "src/"
projectKey: "my-custom-project" projectKey: "my-custom-project"
projectName: "my-custom-project-name"
projectVersion: "v0.0.1"
``` ```
## Secrets ### Inputs
These are some of the supported input parameters of action.
- `host` - **_(Required)_** this is the SonarQube server URL. - `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/). - `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. - `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 that will be displayed on the SonarQube web interface.
- `projectVersion` - The project version.
- `encoding` - Encoding of the source code. Default is UTF-8.
You can set all variable in the "Secrets" settings page of your repository. > **Note**:
> If you're thinking of setting project metadata & other related things in a **`sonar-project.properties`** configuration file _(must be declared in the base directory `projectBaseDir`)_ instead of going through the [input parameters](#inputs), this action supports that!
## License ## License

View File

@@ -1,15 +1,18 @@
name: "SonarQube Scan" name: "SonarQube Scan"
description: "Scan your code with SonarQube Scanner to detect bugs, vulnerabilities and code smells in more than 25 programming languages." description: "Scan your code with SonarQube Scanner to detect bugs, vulnerabilities and code smells in more than 25 programming languages."
author: "Dwi Siswanto" author: "Dwi Siswanto"
branding: branding:
icon: "check" icon: "check"
color: "green" color: "green"
runs: runs:
using: "docker" using: "docker"
image: "Dockerfile" image: "Dockerfile"
inputs: inputs:
host: host:
description: "SonarQube server URL" description: "SonarQube server URL."
required: true required: true
projectKey: projectKey:
description: "The project's unique key. Allowed characters are: letters, numbers, -, _, . and :, with at least one non-digit." 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 required: false
default: "" default: ""
projectBaseDir: projectBaseDir:
description: "Set the sonar.projectBaseDir analysis property" description: "Set the sonar.projectBaseDir analysis property."
required: false required: false
default: "." default: "."
login: login:
description: "Login or authentication token of a SonarQube user" description: "Login or authentication token of a SonarQube user."
required: true required: true
password: password:
description: "Password that goes with the sonar.login username. This should be left blank if an authentication token is being used." 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,36 +2,44 @@
set -e 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
fi
fi
REPOSITORY_NAME=$(basename "${GITHUB_REPOSITORY}") REPOSITORY_NAME=$(basename "${GITHUB_REPOSITORY}")
[[ ! -z ${INPUT_PASSWORD} ]] && SONAR_PASSWORD="${INPUT_PASSWORD}" || SONAR_PASSWORD="" 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
if [[ ! -f "${GITHUB_WORKSPACE}/sonar-project.properties" ]]; then if [[ -f "${INPUT_PROJECTBASEDIR%/}pom.xml" ]]; then
[[ -z ${INPUT_PROJECTKEY} ]] && SONAR_PROJECTKEY="${REPOSITORY_NAME}" || SONAR_PROJECTKEY="${INPUT_PROJECTKEY}" 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."
[[ -z ${INPUT_PROJECTNAME} ]] && SONAR_PROJECTNAME="${REPOSITORY_NAME}" || SONAR_PROJECTNAME="${INPUT_PROJECTNAME}" exit 1
[[ -z ${INPUT_PROJECTVERSION} ]] && SONAR_PROJECTVERSION="" || SONAR_PROJECTVERSION="${INPUT_PROJECTVERSION}" 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
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 \ sonar-scanner \
-Dsonar.host.url=${INPUT_HOST} \ -Dsonar.host.url="${INPUT_HOST}" \
-Dsonar.projectKey=${SONAR_PROJECTKEY} \ -Dsonar.projectKey="${SONAR_PROJECTKEY}" \
-Dsonar.projectName=${SONAR_PROJECTNAME} \ -Dsonar.projectName="${SONAR_PROJECTNAME}" \
-Dsonar.projectVersion=${SONAR_PROJECTVERSION} \ -Dsonar.projectVersion="${SONAR_PROJECTVERSION}" \
-Dsonar.projectBaseDir=${INPUT_PROJECTBASEDIR} \ -Dsonar.projectBaseDir="${INPUT_PROJECTBASEDIR}" \
-Dsonar.login=${INPUT_LOGIN} \ -Dsonar.login="${INPUT_LOGIN}" \
-Dsonar.password=${SONAR_PASSWORD} \ -Dsonar.password="${SONAR_PASSWORD}" \
-Dsonar.sources=. \ -Dsonar.sources="${INPUT_PROJECTBASEDIR}" \
-Dsonar.sourceEncoding=UTF-8 -Dsonar.sourceEncoding="${INPUT_ENCODING}"
else else
sonar-scanner \ sonar-scanner \
-Dsonar.host.url=${INPUT_HOST} \ -Dsonar.host.url="${INPUT_HOST}" \
-Dsonar.projectBaseDir=${INPUT_PROJECTBASEDIR} \ -Dsonar.login="${INPUT_LOGIN}" \
-Dsonar.login=${INPUT_LOGIN} \ -Dsonar.password="${SONAR_PASSWORD}"
-Dsonar.password=${SONAR_PASSWORD}
fi fi