Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix SonarCloud configuration #25

Merged
merged 7 commits into from
Apr 8, 2024
Merged
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
43 changes: 0 additions & 43 deletions .github/workflows/mobsf.yml

This file was deleted.

77 changes: 26 additions & 51 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,11 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow helps you trigger a SonarCloud analysis of your code and populates
# GitHub Code Scanning alerts with the vulnerabilities found.
# Free for open source project.

# 1. Login to SonarCloud.io using your GitHub account

# 2. Import your project on SonarCloud
# * Add your GitHub organization first, then add your repository as a new project.
# * Please note that many languages are eligible for automatic analysis,
# which means that the analysis will start automatically without the need to set up GitHub Actions.
# * This behavior can be changed in Administration > Analysis Method.
#
# 3. Follow the SonarCloud in-product tutorial
# * a. Copy/paste the Project Key and the Organization Key into the args parameter below
# (You'll find this information in SonarCloud. Click on "Information" at the bottom left)
#
# * b. Generate a new token and add it to your Github repository's secrets using the name SONAR_TOKEN
# (On SonarCloud, click on your avatar on top-right > My account > Security
# or go directly to https://sonarcloud.io/account/security/)

# Feel free to take a look at our documentation (https://docs.sonarcloud.io/getting-started/github/)
# or reach out to our community forum if you need some help (https://community.sonarsource.com/c/help/sc/9)

name: SonarCloud analysis

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
types: ["opened", "synchronize", "reopened"]

permissions:
pull-requests: read # allows SonarCloud to decorate PRs with analysis results
Expand All @@ -43,26 +15,29 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Analyze with SonarCloud

# You can pin the exact commit or the version.
# uses: SonarSource/sonarcloud-github-action@de2e56b42aa84d0b1c5b622644ac17e505c9a049
uses: SonarSource/sonarcloud-github-action@de2e56b42aa84d0b1c5b622644ac17e505c9a049
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Generate a token on Sonarcloud.io, add it to the secrets of this repo with the name SONAR_TOKEN (Settings > Secrets > Actions > add new repository secret)
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Setup Java 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin' # Alternative distribution options are available
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
# Additional arguments for the sonarcloud scanner
args:
# Unique keys of your project and organization. You can find them in SonarCloud > Information (bottom-left menu)
# mandatory
-Dsonar.projectKey=
-Dsonar.organization=
# Comma-separated paths to directories containing main source files.
#-Dsonar.sources= # optional, default is project base directory
# When you need the analysis to take place in a directory other than the one from which it was launched
#-Dsonar.projectBaseDir= # optional, default is .
# Comma-separated paths to directories containing test source files.
#-Dsonar.tests= # optional. For more info about Code Coverage, please refer to https://docs.sonarcloud.io/enriching/test-coverage/overview/
# Adds more detail to both client and server-side analysis logs, activating DEBUG mode for the scanner, and adding client-side environment variables and system properties to the server-side log of analysis report processing.
#-Dsonar.verbose= # optional, default is false
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew build sonar --info
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ opciones, por lo que agregué varias GithubActions para validar algunos concepto
pipeline.

Algunas de ellas nunca he trabajado antes como Codacy, CodeQL, Contrast, Crunch42,
Dependency review, devskim, mobsf, scorecard, semgrep y SooS.
Dependency review, devskim, scorecard, semgrep y SooS.

En el futuro, el repositorio puede sufrir cambios no necesariamente relacionados con la
parte de seguridad, pero la pipeline de CI/CD y el contexto de seguridad permanecerán.
Expand All @@ -82,5 +82,5 @@ El proyecto usa otra [configuración de seguridad de GitHub](https://github.com/
- [ ] Configurar plugin Cotrast Community: Problema con la ruta serif
- [x] Configurar plugin PMD: Problema con propriedad browser_download_url
- [ ] Configurar plugin Snyk Security: Problema con serif
- [ ] Configurar plugin SonarCloud: Añadir variables secreta SONAR_TOKEN
- [x] Configurar plugin SonarCloud: Añadir variables secreta SONAR_TOKEN
- [ ] Configurar plugin SOOS: Añadir variables secreta
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ plugins {

id("io.spring.dependency-management") version "1.1.4"
id("org.openapi.generator") version "7.4.0" apply false
id("org.sonarqube") version "5.0.0.4638" apply false
id("org.springframework.boot") version "3.2.4"
}

apply(from = "plugins/java.gradle")
apply(from = "plugins/openapi.gradle")
apply(from = "plugins/sonarqube.gradle")

group = "com.arthurfnsc"
version = "0.0.1-SNAPSHOT"
Expand Down
18 changes: 18 additions & 0 deletions plugins/sonarqube.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apply plugin: "org.sonarqube"

sonarqube {
properties {
property "sonar.projectKey", "arthurmfnsc_api-first"
property "sonar.organization", "arthurmfnsc"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.projectVersion", rootProject.version
property "sonar.token", System.getenv('SONAR_TOKEN')
property 'sonar.sourceEncoding', 'UTF-8'
property "sonar.scm.provider", "git"
property 'sonar.exclusions', 'build/**, **/*Test.*'
property "sonar.import_unknown_files", true
property 'sonar.core.codeCoveragePlugin', 'jacoco'
// SonarQube 6.2+
property 'sonar.coverage.jacoco.xmlReportPaths', "${project.projectDir}/build/reports/jacoco/test/jacocoTestReport.xml"
}
}
Loading