Hi everyone,
- Dev Platform: GitHub Enterprise
- Sonarqube Scanner: Enterprise Edition Version 9.9 (build 65466)
- Project type: iOS App (Swift & Objective-C)
What are you trying to achieve?
Migrate Sonarqube yml Pipeline from Azure to GitHub, so basically, I already have Sonarqube dashboard.
what have you tried so far to achieve this?
- Open GitHub
- Go to Code Scanning and search for Sonarqube plugin
- Press on “Configure” and start with default template
- In Sonarqube dashboard I set up in the DevOps settings GitHub and tried the configuration (Configuration valid)
- Created in GitHub the token secrets and host URL
- Tried to run and upload the code to my two branches on Sonar Dashboard
- I have a main branch and development branch in the app and I want to upload to Sonar Dashboard (I already have these branches created in the past when I used Azure Pipeline)
Default Template:
# 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 SonarQube analysis of your code and populates
# GitHub Code Scanning alerts with the vulnerabilities found.
# (this feature is available starting from SonarQube 9.7, Developer Edition and above)
# 1. Make sure you add a valid GitHub configuration to your SonarQube (Administration > DevOps platforms > GitHub)
# 2. Import your project on SonarQube
# * Add your repository as a new project by clicking "Create project" from your homepage.
#
# 3. Select GitHub Actions as your CI and follow the tutorial
# * a. Generate a new token and add it to your GitHub repository's secrets using the name SONAR_TOKEN
# (On SonarQube, click on your avatar on top-right > My account > Security or ask your administrator)
#
# * b. Copy/paste your SonarQube host URL to your GitHub repository's secrets using the name SONAR_HOST_URL
#
# * c. Copy/paste the project Key into the args parameter below
# (You'll find this information in SonarQube by following the tutorial or by clicking on Project Information at the top-right of your project's homepage)
# Feel free to take a look at our documentation (https://docs.sonarqube.org/latest/analysis/github-integration/)
# or reach out to our community forum if you need some help (https://community.sonarsource.com/c/sq/10)
name: SonarQube analysis
on:
push:
branches: [ "development", "main"]
pull_request:
branches: [ "development" ]
workflow_dispatch:
permissions:
pull-requests: read # allows SonarQube to decorate PRs with analysis results
jobs:
Analysis:
runs-on: ubuntu-latest
steps:
- name: Analyze with SonarQube
# You can pin the exact commit or the version.
# uses: SonarSource/sonarqube-scan-action@v1.1.0
uses: SonarSource/sonarqube-scan-action@7295e71c9583053f5bf40e9d4068a0c974603ec8
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Generate a token on SonarQube, add it to the secrets of this repo with the name SONAR_TOKEN (Settings > Secrets > Actions > add new repository secret)
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} # add the URL of your instance to the secrets of this repo with the name SONAR_HOST_URL (Settings > Secrets > Actions > add new repository secret)
with:
# Additional arguments for the sonarcloud scanner
args:
# Unique key of your project. You can find it in SonarQube > [my project] > Project Information (top-right menu)
# mandatory
-Dsonar.projectKey=
# 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
I changed it with required and mandatory field, but first of all I cannot run on macOS-latest because
SonarSource/sonarqube-scan-action@7295e71c9583053f5bf40e9d4068a0c974603ec8
got me this error:
Run SonarSource/sonarqube-scan-action@master
Error: Container action is only supported on Linux
It’s tough to implement (migrate) from Azure to GitHub.
My actual yml is this one (I’ll change some sensitive data)
# 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 SonarQube analysis of your code and populates
# GitHub Code Scanning alerts with the vulnerabilities found.
# (this feature is available starting from SonarQube 9.7, Developer Edition and above)
# 1. Make sure you add a valid GitHub configuration to your SonarQube (Administration > DevOps platforms > GitHub)
# 2. Import your project on SonarQube
# * Add your repository as a new project by clicking "Create project" from your homepage.
#
# 3. Select GitHub Actions as your CI and follow the tutorial
# * a. Generate a new token and add it to your GitHub repository's secrets using the name SONAR_TOKEN
# (On SonarQube, click on your avatar on top-right > My account > Security or ask your administrator)
#
# * b. Copy/paste your SonarQube host URL to your GitHub repository's secrets using the name SONAR_HOST_URL
#
# * c. Copy/paste the project Key into the args parameter below
# (You'll find this information in SonarQube by following the tutorial or by clicking on Project Information at the top-right of your project's homepage)
# Feel free to take a look at our documentation (https://docs.sonarqube.org/latest/analysis/github-integration/)
# or reach out to our community forum if you need some help (https://community.sonarsource.com/c/sq/10)
name: SonarQube Scan
on:
workflow_dispatch:
jobs:
AnalysisMacOS:
runs-on: macos-latest
steps:
- name: Install sonar-scanner with brew and print the version
run: |
echo "Install sonar-scanner with brew and print the version"
brew install sonar-scanner
sonar-scanner --version
shell: bash
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
ref: development
AnalysisUbuntu:
runs-on: ubuntu-latest
steps:
- name: Analyze with SonarQube
uses: SonarSource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
with:
args: >
-Dsonar.verbose=true
-Dsonar.projectKey= -> pasted from Sonar settings
-Dsonar.projectName= -> same here
-Dsonar.tests=MyAppTests,**/*.swift
-Dsonar.coverage.exclusions=**/*.xml,Pods/**/*,Reports/**/*,DerivedData/**/*,**/*.html,**
-Dsonar.swift.simulator=platform=iOS Simulator,name=iPhone 14,OS=16.2
-Dsonar.swift.project=MyApp.xcodeproj
-Dsonar.swift.appName=MyAppName
-Dsonar.swift.appScheme=MyAppName
-Dsonar.swift.appConfiguration=Debug
-Dsonar.sourceEncoding=UTF-8
-Dsonar.swift.excludePathsFromCoverage=build,DerivedData,fastlane,Pods,reports,xcov_output
-Dsonar.swift.excludedPathsFromCoverage=.*Tests.*
-Dsonar.c.file.suffixes=-
-Dsonar.objc.file.suffixes=.h,.m
-Dsonar.cfamily.build-wrapper-output=build_wrapper_output_directory
-Dsonar.swift.swiftlint.reportPaths=DerivedData/swiftlint.json
-Dsonar.coverageReportPaths=DerivedData/sonarqube-converted.xml
-Dsonar.cfamily.threads=4
-Dsonar.branch.name=SonarBranchName
-Dsonar.projectVersion= Get from Fastlane
AnalysisMacOS_step2:
runs-on: ${{ vars.CLOUDMACOSVERSION}}
steps:
- name: SwiftLint JSON for SonarQube
run: |
echo -e ">>> installing swiftlint <<<"
brew install swiftlint
echo -e ">>> entering source directory <<<"
cd ${{ github.workspace }}
echo -e ">>> creating swiftlint json file <<<"
touch DerivedData/swiftlint.json
echo -e ">>> running swiftlint with stock config <<<"
swiftlint --config ${{ github.workspace }}/.swiftlint.yml --reporter json > DerivedData/swiftlint.json
echo -e ">>> listing folder <<<"
ls
shell: bash
- name: Set Up Fastlane - Xcode Build with SonarQube Wrapper
run: |
fastlane xcodeSonarQubeEnterpriseBuild
shell: bash
- name: SonarQube Coverage (cococo) - No ObjC
run: |
echo -e "copying cococo command line into /usr/local/bin"
cp cococo /usr/local/bin
echo -e "generating code coverage without .h .m files for SonarQube"
cococo DerivedData/Logs/Test/*.xcresult --excluded .h .m > DerivedData/sonarqube-converted.xml
shell: bash
-
-Dsonar.swift.simulator=platform=iOS Simulator,name=iPhone 14,OS=16.2
Not work I got this error →ERROR: Unrecognized option: Simulator,name=iPhone
-
${{ github.workspace }}
Not such file or directory
-
SwiftLint Installation
To reinstall 0.53.0, run:
brew reinstall swiftlint
>>> entering source directory <<<
>>> creating swiftlint json file <<<
touch: DerivedData/swiftlint.json: No such file or directory
Error: Process completed with exit code 1.```
- uses: SonarSource/sonarqube-scan-action@master
Run SonarSource/sonarqube-scan-action@master
Error: Container action is only supported on Linux
- This fastlane
xcodeSonarQubeEnterpriseBuild
lane :xcodeSonarQubeEnterpriseBuild do
xcode_select("/Applications/Xcode_15.0.1.app")
Dir.chdir("../") do
begin
sh("./fastlane/build-wrapper-macosx-x86 --out-dir build_wrapper_output_directory xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -derivedDataPath DerivedData/ -enableCodeCoverage YES -destination 'platform=iOS Simulator,name=iPhone SE (3rd generation) (17.0)' clean build test")
rescue => exception
puts ""
end
end
end
And this is some of errors. I also tried a lot of stuff to split in 3 Analisys
, but not work.
Is there any “easy” way to implement it for iOS App with the above parameters?
thanks