Skip to content

ci: update ci

ci: update ci #2381

Workflow file for this run

name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: macos-12
env:
DERIVED_DATA: ${{ github.workspace }}/.DerivedData
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install sonar-scanner
uses: yolomao/sonarcloud-github-c-cpp@main
- name: Cache cocoapods
uses: actions/cache@v4
with:
save-always: true
path: ./Example/Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-
- name: Pod Install
run: cd Example && pod install && cd ..
- name: Run tests to generate coverage statistics # https://sonarsource.atlassian.net/browse/CPP-3987
run: |
set -euo pipefail
mkdir -p ${{ env.DERIVED_DATA }}
xcodebuild test -workspace Example/GrowingAnalytics.xcworkspace \
-scheme GrowingAnalyticsTests \
-testPlan GrowingAnalyticsTests \
-destination 'platform=iOS Simulator,name=iPhone 14' \
-enableCodeCoverage YES \
-derivedDataPath ${{ env.DERIVED_DATA }} \
OTHER_CFLAGS="\$(inherited) -gen-cdb-fragment-path ${{ env.DERIVED_DATA }}/compilation-database" \
| xcbeautify --renderer github-actions
pushd ${{ env.DERIVED_DATA }}/compilation-database
sed -e '1s/^/[\'$'\n''/' -e '$s/,$/\'$'\n'']/' *.json > ${{ env.DERIVED_DATA }}/compile_commands.json
popd
- name: Brew Install Xcresultparser
run: |
brew tap a7ex/homebrew-formulae
brew install [email protected]
- name: Parse xcresult to Cobertura xml
run: |
xcresultparser -o cobertura ${{ env.DERIVED_DATA }}/Logs/Test/*.xcresult/ \
> ${{ env.DERIVED_DATA }}/cobertura-coverage.xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
fail_ci_if_error: true
files: ./.DerivedData/cobertura-coverage.xml
directory: ${{ github.workspace }}
verbose: true
- name: Parse xcresult to Sonarqube xml
run: |
xcresultparser -c -o xml ${{ env.DERIVED_DATA }}/Logs/Test/*.xcresult/ \
> ${{ env.DERIVED_DATA }}/sonar-coverage.xml
- name: Run sonar-scanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner \
-Dsonar.cfamily.compile-commands="${{ env.DERIVED_DATA }}/compile_commands.json" \
-Dsonar.coverageReportPaths="${{ env.DERIVED_DATA }}/sonar-coverage.xml"
# https://github.com/sonarsource-cfamily-examples/macos-xcode-coverage-gh-actions-sc/blob/main/.github/workflows/build.yml
# https://github.com/SonarSource/sonarcloud-github-c-cpp