Skip to content

Commit 400830f

Browse files
[CI] Run sonar on push (#745)
1 parent 88c3587 commit 400830f

File tree

7 files changed

+110
-106
lines changed

7 files changed

+110
-106
lines changed

.github/actions/python-cache/action.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/smoke-checks-swiftui.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.

.github/workflows/smoke-checks.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ on:
77
- 'CHANGELOG.md'
88

99
workflow_dispatch:
10+
inputs:
11+
snapshots:
12+
description: 'Should Snapshots be recorded on CI?'
13+
type: boolean
14+
required: false
15+
default: false
1016

1117
concurrency:
1218
group: ${{ github.workflow }}-${{ github.ref }}
@@ -41,6 +47,7 @@ jobs:
4147
automated-code-review:
4248
name: Automated Code Review
4349
runs-on: macos-15
50+
if: ${{ github.event.inputs.snapshots != 'true' }}
4451
env:
4552
XCODE_VERSION: "15.4"
4653
steps:
@@ -59,6 +66,7 @@ jobs:
5966
build-xcode15:
6067
name: Build SDKs (Xcode 15.0)
6168
runs-on: macos-15
69+
if: ${{ github.event.inputs.snapshots != 'true' }}
6270
env:
6371
XCODE_VERSION: "15.4"
6472
steps:
@@ -81,9 +89,52 @@ jobs:
8189
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
8290
APPSTORE_API_KEY: ${{ secrets.APPSTORE_API_KEY }}
8391

92+
test-ui-debug:
93+
name: Test SwiftUI (Debug)
94+
runs-on: macos-15
95+
steps:
96+
- uses: actions/[email protected]
97+
- uses: ./.github/actions/bootstrap
98+
env:
99+
INSTALL_YEETD: true
100+
INSTALL_SONAR: true
101+
- name: Run UI Tests (Debug)
102+
run: bundle exec fastlane test_ui device:"${{ env.IOS_SIMULATOR_DEVICE }}" record:${{ github.event.inputs.snapshots }}
103+
timeout-minutes: 120
104+
env:
105+
GITHUB_TOKEN: ${{ secrets.CI_BOT_GITHUB_TOKEN }} # to open a PR
106+
- name: Run Sonar analysis
107+
if: ${{ github.event.inputs.snapshots != 'true' }}
108+
run: bundle exec fastlane sonar_upload
109+
env:
110+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
111+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
112+
- name: Parse xcresult
113+
if: failure()
114+
run: |
115+
brew install chargepoint/xcparse/xcparse
116+
xcparse logs fastlane/test_output/StreamChatSwiftUI.xcresult fastlane/test_output/logs/
117+
xcparse screenshots fastlane/test_output/StreamChatSwiftUI.xcresult fastlane/test_output/snapshots --test
118+
- uses: actions/upload-artifact@v4
119+
if: failure()
120+
with:
121+
name: Test Data UI
122+
path: |
123+
fastlane/recordings
124+
fastlane/sinatra_log.txt
125+
fastlane/test_output/snapshots
126+
fastlane/test_output/logs/*/Diagnostics/**/*.txt
127+
fastlane/test_output/logs/*/Diagnostics/simctl_diagnostics/DiagnosticReports/*
128+
- name: Upload Test Coverage
129+
uses: actions/upload-artifact@v4
130+
with:
131+
name: test-coverage-${{ github.event.pull_request.number }}
132+
path: reports/sonarqube-generic-coverage.xml
133+
84134
allure_testops_launch:
85135
name: Launch Allure TestOps
86136
runs-on: macos-13
137+
if: ${{ github.event.inputs.snapshots != 'true' }}
87138
needs: build-test-app-and-frameworks
88139
outputs:
89140
launch_id: ${{ steps.get_launch_id.outputs.launch_id }}
@@ -102,6 +153,7 @@ jobs:
102153
test-e2e-debug:
103154
name: Test E2E UI (Debug)
104155
runs-on: macos-15
156+
if: ${{ github.event.inputs.snapshots != 'true' }}
105157
needs:
106158
- allure_testops_launch
107159
- build-test-app-and-frameworks
@@ -156,6 +208,7 @@ jobs:
156208
build-apps:
157209
name: Build Demo App
158210
runs-on: macos-14
211+
if: ${{ github.event.inputs.snapshots != 'true' }}
159212
needs: build-test-app-and-frameworks
160213
steps:
161214
- uses: actions/[email protected]

.github/workflows/sonar.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Sonar
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
env:
13+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14+
15+
jobs:
16+
sonar:
17+
runs-on: macos-15
18+
steps:
19+
- uses: actions/[email protected]
20+
21+
- uses: actions/github-script@v6
22+
id: get_pr_data
23+
with:
24+
script: |
25+
return (
26+
await github.rest.repos.listPullRequestsAssociatedWithCommit({
27+
commit_sha: context.sha,
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
})
31+
).data[0];
32+
33+
- uses: ./.github/actions/bootstrap
34+
env:
35+
INSTALL_SONAR: true
36+
SKIP_MINT_BOOTSTRAP: true
37+
38+
- name: Run Sonar analysis
39+
run: |
40+
ARTIFACT_NAME="test-coverage-${{ fromJson(steps.get_pr_data.outputs.result).number }}"
41+
ARTIFACT=$(gh api repos/${{ github.repository }}/actions/artifacts | jq -r ".artifacts | map(select(.name==\"$ARTIFACT_NAME\")) | first")
42+
if [[ "$ARTIFACT" == null || "$ARTIFACT" == "" ]]; then
43+
echo "Artifact not found. Skipping Sonar analysis."
44+
else
45+
gh run download $(echo $ARTIFACT | jq .workflow_run.id) -n "$ARTIFACT_NAME" -D reports
46+
bundle exec fastlane sonar_upload
47+
fi
48+
env:
49+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
50+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

fastlane/Fastfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ before_all do |lane|
2323
if is_ci
2424
setup_ci
2525
setup_git_config
26-
xcversion(version: xcode_version) unless [:publish_release, :allure_launch, :allure_upload, :copyright, :pod_lint].include?(lane)
26+
xcversion(version: xcode_version) unless [:publish_release, :sonar_upload, :allure_launch, :allure_upload, :copyright, :pod_lint].include?(lane)
2727
end
2828
end
2929

@@ -259,6 +259,8 @@ lane :test_ui do |options|
259259
base_branch: current_branch,
260260
head_branch: "#{current_branch}-snapshots"
261261
)
262+
else
263+
slather
262264
end
263265
end
264266

fastlane/Sonarfile

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,16 @@ desc 'Get code coverage report and run complexity analysis for Sonar'
44
lane :sonar_upload do
55
next unless is_check_required(sources: sources_matrix[:sonar], force_check: @force_check)
66

7-
sonar_args = ''
87
version_number = get_version_number(
98
xcodeproj: 'StreamChatSwiftUI.xcodeproj',
109
target: 'StreamChatSwiftUI'
1110
)[/\d+\.\d+\.\d/]
1211

13-
unless Dir.glob('test_output/*.xcresult').empty?
14-
slather
15-
lizard(
16-
source_folder: './Sources/',
17-
language: 'swift',
18-
export_type: 'xml',
19-
report_file: 'reports/lizard.xml'
20-
)
21-
sonar_args = '-Dsonar.coverageReportPaths="reports/sonarqube-generic-coverage.xml" ' \
22-
'-Dsonar.swift.lizard.report="reports/lizard.xml"'
23-
end
24-
2512
Dir.chdir('..') do
26-
sh("./fastlane/sonar/bin/sonar-scanner -Dsonar.projectVersion=#{version_number} -Dproject.settings=sonar-project.properties #{sonar_args}")
13+
sh("./fastlane/sonar/bin/sonar-scanner " \
14+
"-Dsonar.projectVersion=#{version_number} " \
15+
"-Dproject.settings=sonar-project.properties " \
16+
"-Dsonar.coverageReportPaths='reports/sonarqube-generic-coverage.xml'")
2717
end
2818

2919
next if sonar_args.empty? || ENV['GITHUB_EVENT_NAME'] == 'pull_request' || current_branch !~ /main|develop/

requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)