Compare commits

...

18 Commits

Author SHA1 Message Date
Claire Villard
53c3e3207f This repository is owned by the Analysis Experience squad 2024-03-28 09:50:07 +01:00
Claire Villard
9ad16418d1 SQSCANGHA-18 Improve the SonarQube intro in README.md 2024-03-19 16:12:46 +01:00
ALX99
74e7b4f998 docs: use actions/checkout@v4 as an example (#96) 2024-03-18 16:48:50 +01:00
David Cho-Lerat
1b9d398800 Update README.md with Clean Code link (#86)
https://docs.google.com/document/d/1XhLeIhXWOzyWGJlJYp9OqYbkP5KQ-Gvx1a0O5JHTQsY/edit
2023-10-18 16:31:00 +02:00
dependabot[bot]
ccaf9efb11 NO-JIRA Bump actions/checkout from 3 to 4 2023-09-14 13:02:51 +02:00
Matteo Mara
69c1a75940 SQSCANGHA-13 Update base image 2023-08-29 14:12:34 +02:00
Matteo Mara
4b0bfc149f SQSCANGHA-11 Correct label with new major version 2023-07-27 16:23:28 +02:00
Matteo Mara
9cc4f58b79 SQSCANGHA-11 Update base image 2023-07-27 16:10:21 +02:00
tomverin
5829c57497 BUILD-3102 Enable dependabot (#75)
---------

Co-authored-by: Ambroise C <ambroise.christea@sonarsource.com>
2023-06-20 18:13:48 +02:00
K.B.Dharun Krishna
d57dba2a10 CI: bump actions version (#74)
* qa.yml: bump actions/checkout to v3

* Update madhead/semver-utils to latest
2023-06-09 11:17:33 +02:00
Christian Oliff
427bad7016 use latest version of actions/checkout in README example 2023-01-24 22:54:59 +01:00
Jacek
a6ba0aafc2 SQSCANGHA-8 Update base image 2022-12-29 11:24:27 +01:00
Sylvain
1db0a52e3c Update README.md Yaml file snippet
Users unfamiliar with GitHub actions just copy the pipeline snippets and wonder why the analysis does not trigger. Let's make sure it does by adding "main" and "develop" branch names by default.
2022-12-14 15:23:43 +01:00
Bart Riepe
50d5d98163 SQSCANGHA-6 Add ability to pass custom PEM certificate to action (#37) 2022-09-26 16:47:58 +02:00
Michal Dvořák
26fe7d6b0e SQSCANGHA-4 Publish MAJOR and MAJOR.MINOR tags in addition to MAJOR.MINOR.PATCH (#35) 2022-07-05 16:29:32 +02:00
Benjamin Svobodny
fd8151470c SQSCANGHA-3 Permission cleanup doesn't run if the scanner exits with a non-0 code (#33) 2022-07-05 15:15:01 +02:00
Tobias Trabelsi
bdba66714e SONAR-16068 made SONAR_TOKEN optional
SONAR-16067 fixed file permissions
2022-03-01 10:34:32 +01:00
Julien Carsique
72def085d4 fix(BUILD-1378): sonarqube-team ownership 2022-02-24 09:58:06 +01:00
10 changed files with 111 additions and 19 deletions

2
.github/CODEOWNERS vendored
View File

@@ -1 +1 @@
* @sonarsource/sonarqube-team .github/CODEOWNERS @sonarsource/analysis-experience-squad

16
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,16 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
timezone: "CET"
open-pull-requests-limit: 100
commit-message:
prefix: "NO-JIRA "

View File

@@ -1,12 +1,12 @@
name: QA name: QA
on: push on: [push, pull_request]
jobs: jobs:
run_qa: run_qa:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v4
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- run: ./test/run-qa.sh - run: ./test/run-qa.sh

32
.github/workflows/update-tags.yml vendored Normal file
View File

@@ -0,0 +1,32 @@
name: Update Tags
on:
push:
tags:
- v*.*.*
jobs:
generate:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Parse semver
uses: madhead/semver-utils@latest
id: version
with:
version: ${{ github.ref_name }}
- name: Update tags
run: |
TAGS='v${{ steps.version.outputs.major }} v${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}'
for t in $TAGS; do
git tag -f "$t"
git push origin ":$t" 2>/dev/null || true
git push origin "$t"
done

View File

@@ -1,6 +1,6 @@
FROM sonarsource/sonar-scanner-cli:4.7 FROM sonarsource/sonar-scanner-cli:5.0.1
LABEL version="1.1.0" \ LABEL version="2.0.1" \
repository="https://github.com/sonarsource/sonarqube-scan-action" \ repository="https://github.com/sonarsource/sonarqube-scan-action" \
homepage="https://github.com/sonarsource/sonarqube-scan-action" \ homepage="https://github.com/sonarsource/sonarqube-scan-action" \
maintainer="SonarSource" \ maintainer="SonarSource" \
@@ -9,9 +9,9 @@ LABEL version="1.1.0" \
com.github.actions.icon="check" \ com.github.actions.icon="check" \
com.github.actions.color="green" com.github.actions.color="green"
# https://help.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions#user
USER root
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh RUN chmod +x /entrypoint.sh
COPY cleanup.sh /cleanup.sh
RUN chmod +x /cleanup.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -1,10 +1,13 @@
# Scan your code with SonarQube [![QA](https://github.com/SonarSource/sonarqube-scan-action/actions/workflows/qa.yml/badge.svg)](https://github.com/SonarSource/sonarqube-scan-action/actions/workflows/qa.yml) # Scan your code with SonarQube [![QA](https://github.com/SonarSource/sonarqube-scan-action/actions/workflows/qa.yml/badge.svg)](https://github.com/SonarSource/sonarqube-scan-action/actions/workflows/qa.yml)
Using this GitHub Action, scan your code with [SonarQube](https://www.sonarqube.org/) to detects Bugs, Vulnerabilities and Code Smells in up to 27 programming languages! This SonarSource project, available as a GitHub Action, scans your projects with SonarQube, and helps developers produce
[Clean Code](https://www.sonarsource.com/solutions/clean-code/?utm_medium=referral&utm_source=github&utm_campaign=clean-code&utm_content=sonarqube-scan-action).
<img src="./images/SonarQube-72px.png"> <img src="./images/SonarQube-72px.png">
SonarQube is the leading product for Continuous Code Quality & Code Security. It supports most popular programming languages, including Java, JavaScript, TypeScript, C#, Python, C, C++, and many more. [SonarQube](https://www.sonarsource.com/products/sonarqube/) is a widely used static analysis solution for continuous code quality and security inspection.
It helps developers identify and fix issues in their code that could lead to bugs, vulnerabilities, or decreased development velocity.
SonarQube supports the most popular programming languages, including Java, JavaScript, TypeScript, C#, Python, C, C++, and [many more](https://www.sonarsource.com/knowledge/languages/).
## Requirements ## Requirements
@@ -20,7 +23,7 @@ Project metadata, including the location to the sources to be analyzed, must be
sonar.projectKey=<replace with the key generated when setting up the project on SonarQube> sonar.projectKey=<replace with the key generated when setting up the project on SonarQube>
# relative paths to source directories. More details and properties are described # relative paths to source directories. More details and properties are described
# in https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/ # at https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/
sonar.sources=. sonar.sources=.
``` ```
@@ -28,11 +31,13 @@ The workflow YAML file will usually look something like this:
```yaml ```yaml
on: on:
# Trigger analysis when pushing in master or pull requests, and when creating # Trigger analysis when pushing to your main branches, and when creating a pull request.
# a pull request.
push: push:
branches: branches:
- main
- master - master
- develop
- 'releases/**'
pull_request: pull_request:
types: [opened, synchronize, reopened] types: [opened, synchronize, reopened]
@@ -41,9 +46,9 @@ jobs:
sonarqube: sonarqube:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v4
with: with:
# Disabling shallow clone is recommended for improving relevancy of reporting # Disabling shallow clones is recommended for improving the relevancy of reporting
fetch-depth: 0 fetch-depth: 0
- name: SonarQube Scan - name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master uses: sonarsource/sonarqube-scan-action@master
@@ -63,6 +68,17 @@ If your source code file names contain special characters that are not covered b
LC_ALL: "ru_RU.UTF-8" LC_ALL: "ru_RU.UTF-8"
``` ```
If your SonarQube server uses a self-signed certificate, you can pass a root certificate (in PEM format) to the Java certificate store:
```yaml
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_ROOT_CERT: ${{ secrets.SONAR_ROOT_CERT }}
```
You can change the analysis base directory by using the optional input `projectBaseDir` like this: You can change the analysis base directory by using the optional input `projectBaseDir` like this:
```yaml ```yaml
@@ -91,6 +107,7 @@ More information about possible analysis parameters can be found in [the documen
- `SONAR_TOKEN` **Required** this is the token used to authenticate access to SonarQube. You can read more about security tokens [here](https://docs.sonarqube.org/latest/user-guide/user-token/). You can set the `SONAR_TOKEN` environment variable in the "Secrets" settings page of your repository, or you can add them at the level of your GitHub organization (recommended). - `SONAR_TOKEN` **Required** this is the token used to authenticate access to SonarQube. You can read more about security tokens [here](https://docs.sonarqube.org/latest/user-guide/user-token/). You can set the `SONAR_TOKEN` environment variable in the "Secrets" settings page of your repository, or you can add them at the level of your GitHub organization (recommended).
- `SONAR_HOST_URL` **Required** this tells the scanner where SonarQube is hosted. You can set the `SONAR_HOST_URL` environment variable in the "Secrets" settings page of your repository, or you can add them at the level of your GitHub organization (recommended). - `SONAR_HOST_URL` **Required** this tells the scanner where SonarQube is hosted. You can set the `SONAR_HOST_URL` environment variable in the "Secrets" settings page of your repository, or you can add them at the level of your GitHub organization (recommended).
- `SONAR_ROOT_CERT` Holds an additional root certificate (in PEM format) that is used to validate the SonarQube server certificate. You can set the `SONAR_ROOT_CERT` environment variable in the "Secrets" settings page of your repository, or you can add them at the level of your GitHub organization (recommended).
## Alternatives for Java, .NET, and C/C++ projects ## Alternatives for Java, .NET, and C/C++ projects
@@ -101,7 +118,7 @@ This GitHub Action will not work for all technologies. If you are in one of the
* You want to analyze a .NET solution. Read the documentation about our [Scanner for .NET](https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html). * You want to analyze a .NET solution. Read the documentation about our [Scanner for .NET](https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html).
* You want to analyze C/C++ code. Read the documentation on [analyzing C/C++ code](https://docs.sonarqube.org/latest/analysis/languages/cfamily/). * You want to analyze C/C++ code. Read the documentation on [analyzing C/C++ code](https://docs.sonarqube.org/latest/analysis/languages/cfamily/).
## Have question or feedback? ## Have questions or feedback?
To provide feedback (requesting a feature or reporting a bug) please post on the [SonarSource Community Forum](https://community.sonarsource.com/tags/c/help/sq/github-actions). To provide feedback (requesting a feature or reporting a bug) please post on the [SonarSource Community Forum](https://community.sonarsource.com/tags/c/help/sq/github-actions).
@@ -109,4 +126,4 @@ To provide feedback (requesting a feature or reporting a bug) please post on the
The Dockerfile and associated scripts and documentation in this project are released under the LGPLv3 License. The Dockerfile and associated scripts and documentation in this project are released under the LGPLv3 License.
Container images built with this project include third party materials. Container images built with this project include third-party materials.

View File

@@ -7,6 +7,8 @@ branding:
runs: runs:
using: docker using: docker
image: Dockerfile image: Dockerfile
entrypoint: "/entrypoint.sh"
post-entrypoint: "/cleanup.sh"
inputs: inputs:
args: args:
description: Additional arguments to the sonar-scanner description: Additional arguments to the sonar-scanner

8
cleanup.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
set -e
_tmp_file=$(ls "${INPUT_PROJECTBASEDIR}/" | head -1)
PERM=$(stat -c "%u:%g" "${INPUT_PROJECTBASEDIR}/$_tmp_file")
chown -R $PERM "${INPUT_PROJECTBASEDIR}/"

View File

@@ -3,8 +3,9 @@
set -e set -e
if [[ -z "${SONAR_TOKEN}" ]]; then if [[ -z "${SONAR_TOKEN}" ]]; then
echo "This GitHub Action requires the SONAR_TOKEN env variable." echo "============================ WARNING ============================"
exit 1 echo "Running this GitHub Action without SONAR_TOKEN is not recommended"
echo "============================ WARNING ============================"
fi fi
if [[ -z "${SONAR_HOST_URL}" ]]; then if [[ -z "${SONAR_HOST_URL}" ]]; then
@@ -12,6 +13,13 @@ if [[ -z "${SONAR_HOST_URL}" ]]; then
exit 1 exit 1
fi fi
if [[ -n "${SONAR_ROOT_CERT}" ]]; then
echo "Adding custom root certificate to java certificate store"
rm -f /tmp/tmpcert.pem
echo "${SONAR_ROOT_CERT}" > /tmp/tmpcert.pem
keytool -keystore /etc/ssl/certs/java/cacerts -storepass changeit -noprompt -trustcacerts -importcert -alias sonarqube -file /tmp/tmpcert.pem
fi
if [[ -f "${INPUT_PROJECTBASEDIR%/}pom.xml" ]]; then if [[ -f "${INPUT_PROJECTBASEDIR%/}pom.xml" ]]; then
echo "Maven project detected. You should run the goal 'org.sonarsource.scanner.maven:sonar' during build rather than using this GitHub Action." echo "Maven project detected. You should run the goal 'org.sonarsource.scanner.maven:sonar' during build rather than using this GitHub Action."
exit 1 exit 1
@@ -25,3 +33,4 @@ fi
unset JAVA_HOME unset JAVA_HOME
sonar-scanner -Dsonar.projectBaseDir=${INPUT_PROJECTBASEDIR} ${INPUT_ARGS} sonar-scanner -Dsonar.projectBaseDir=${INPUT_PROJECTBASEDIR} ${INPUT_ARGS}

View File

@@ -16,6 +16,8 @@ check_sq_is_up() {
echo $status; echo $status;
} }
_current_perm=$(stat -c "%u:%g" $(pwd))
info "Build scanner action..." info "Build scanner action..."
docker build --no-cache -t sonarsource/sonarqube-scan-action . docker build --no-cache -t sonarsource/sonarqube-scan-action .
if [[ ! $? -eq 0 ]]; then if [[ ! $? -eq 0 ]]; then
@@ -88,13 +90,19 @@ success "Correctly failed fast."
info "Analyze project..." info "Analyze project..."
cd test/example-project/ cd test/example-project/
docker run -v `pwd`:/github/workspace/ --workdir /github/workspace --network $network --env SONAR_TOKEN=$token --env SONAR_HOST_URL='http://sonarqube:9000' sonarsource/sonarqube-scan-action docker run -v `pwd`:/github/workspace/ --workdir /github/workspace --network $network --env INPUT_PROJECTBASEDIR=/github/workspace --env SONAR_TOKEN=$token --env SONAR_HOST_URL='http://sonarqube:9000' sonarsource/sonarqube-scan-action
docker run -v `pwd`:/github/workspace/ --workdir /github/workspace --network $network --env INPUT_PROJECTBASEDIR=/github/workspace --entrypoint /cleanup.sh sonarsource/sonarqube-scan-action
if [[ ! $? -eq 0 ]]; then if [[ ! $? -eq 0 ]]; then
error "Couldn't run the analysis." error "Couldn't run the analysis."
exit 1 exit 1
elif [[ ! -f ".scannerwork/report-task.txt" ]]; then elif [[ ! -f ".scannerwork/report-task.txt" ]]; then
error "Couldn't find the report task file. Analysis failed." error "Couldn't find the report task file. Analysis failed."
exit 1 exit 1
elif [ ! "$(stat -c "%u:%g" ".scannerwork/report-task.txt")" == "$_current_perm" ]; then
error "File permissions differ from desired once"
error "desired: $_current_perm"
error "actual: $(stat -c "%u:%g" ".scannerwork/report-task.txt")"
exit 1
fi fi
success "Analysis successful." success "Analysis successful."