So I am pretty new to CI and was wondering if I could please get some help with the script I need to run an analysis on SonarCloud.
- ALM used GitHub
- CI system used GitHub actions
- Languages are Java and TypeScript
I have two projects on sonar cloud to analyse my code:
- The first is to run the maven build which works but I get a 0.0% coverage so I am not sure if it is running my unit tests or not.
name: SonarCloud Backend
on:
push:
branches: [ master, development ]
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: SonarCloud Build & Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze SonarCloud
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
cd backend
mvn --batch-mode --update-snapshots verify -B verify sonar:sonar -Dsonar.projectKey=<proj_key> -Dsonar.organization=<org_key> -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONARCLOUD_TOKEN -Dsonar.tests=src/test/java/tech/app/name
- The second to run the typescript which should be done through Automatic Analysis which it does not seem to find the code as no analysis is done.
name: SonarCloud Frontend
on:
push:
branches: [ master, development ]
pull_request:
types: [opened, synchronize, reopened]
jobs:
sonarcloud:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: SonarCloud Frontend Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: frontend
args: >
-Dsonar.login=${{ secrets.SONAR_TOKEN }}
-Dsonar.organization=<org_key>
-Dsonar.projectKey=<proj_key>
-Dsonar.language=typescript
-Dsonar.tests=src/test.ts
Both run the same code as after some research it seems as if you can’t analyse both ts and java in the same project. If someone can help me or offer some sort of documentation I would be appreciative as I have spent hours trying to google the issue.