Skip to content

Commit

Permalink
Add test-orchestrator so unit tests start before static analysis is f…
Browse files Browse the repository at this point in the history
…inished. Move danger files into their own folder. Add CodeCov. Fix static analysis reporting.
  • Loading branch information
brandonpage committed Nov 4, 2024
1 parent c9ace33 commit 623204d
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 166 deletions.
127 changes: 0 additions & 127 deletions .circleci/fastlane/Fastfile

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
require 'plist'

# Determine which libs were midified by this PR
modifed_libs = Set[]
for file in (git.modified_files + git.added_files);
# Add the library name for each modified file
modifed_libs.add(file.split("libs/").last.split("/").first)
end

# If we are modifiing any CI files run all tests.
if modifed_libs.inclues?(".github")
modifed_libs = ['SalesforceSDKCommon', 'SalesforceAnalytics', 'SalesforceSDKCore', 'SmartStore', 'MobileSync']
end

# Set Github Job output so we know which tests to run
json_libs = modifed_libs.map { |l| "'#{l}'"}.join(", ")
`echo "libs=[#{json_libs}]" >> $GITHUB_OUTPUT`

# Markdown table character length without any issues
MAKRDOWN_LENGTH = 138
LIBS = ['SalesforceSDKCommon', 'SalesforceAnalytics', 'SalesforceSDKCore', 'SmartStore', 'MobileSync']

# Get all static analysis report files
files = Set[]
for lib in modifed_libs;
files.merge(Dir["../libs/SalesforceAnalytics/clangReport/StaticAnalyzer/#{lib}/#{lib}/normal/**/*.plist"])
for lib in LIBS;
files.merge(Dir["../../libs/#{lib}/clangReport/StaticAnalyzer/#{lib}/#{lib}/normal/**/*.plist"])
end
print "Found #{files.count} classes with static analysis files.\n"

modified_file_names = git.modified_files.map { |file| File.basename(file, File.extname(file)) }
added_file_names = git.added_files.map { |file| File.basename(file, File.extname(file)) }
Expand All @@ -37,14 +22,14 @@
for file in files;
report = Plist.parse_xml(file)
report_file_name = File.basename(file, File.extname(file))
print "file name: #{report_file_name}\n"
print "File with clang report: #{report_file_name}\n"

if modified_file_names.include?(report_file_name) || added_file_names.include?(report_file_name)
print "file match! #{file}"
issues = report['diagnostics']
print "File modified in PR: #{file}, has #{issue.count} issues.\n"
for i in 0..issues.count-1
unless issues[i].nil?
message << "#{file_path.split('/').last} | #{issues[i]['type']} | #{issues[i]['category']} | #{issues[i]['description']} | #{issues[i]['location']['line']} | #{issues[i]['location']['col']}\n"
message << "#{report_file_name} | #{issues[i]['type']} | #{issues[i]['category']} | #{issues[i]['description']} | #{issues[i]['location']['line']} | #{issues[i]['location']['col']}\n"
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions .github/DangerFiles/TestOrchestrator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# List of supported xcode schemes for testing
SCHEMES = ['SalesforceSDKCommon', 'SalesforceAnalytics', 'SalesforceSDKCore', 'SmartStore', 'MobileSync']

modifed_libs = Set[]
for file in (git.modified_files + git.added_files);
scheme = file.split("libs/").last.split("/").first
print "lib: #{scheme}\n"
if scheme == '.github'
# If CI files are modified, run all tests
modifed_libs.merge(SCHEMES)
elsif SCHEMES.include?(scheme)
modifed_libs.add(scheme)
end
end

# Set Github Job output so we know which tests to run
json_libs = modifed_libs.map { |l| "'#{l}'"}.join(", ")
`echo "libs=[#{json_libs}]" >> $GITHUB_OUTPUT`
3 changes: 3 additions & 0 deletions .github/DangerFiles/TestResults.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
xcode_summary.ignores_warnings = true
xcode_summary.inline_mode = true
xcode_summary.report '../../test.xcresult'
2 changes: 0 additions & 2 deletions .github/DangerTestResults.rb

This file was deleted.

39 changes: 28 additions & 11 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ on:
jobs:
static-analysis:
runs-on: macos-latest
outputs:
libs: ${{ steps.danger.outputs.libs }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -19,24 +17,43 @@ jobs:
run: |
npm install [email protected]
./install.sh
- name: Static Analysis and Danger
if: ${{ github.event_name == 'pull_request' }} && (success() || failure())
id: danger
- name: Run Static Analysis
# It would be nice to use xcbeaufity here but all the warnings and errors get annotated onto the PR, including
# files not mofified in the PR which is annoying.
run: xcodebuild analyze -workspace SalesforceMobileSDK.xcworkspace -scheme MobileSync -sdk 'iphonesimulator' \
CLANG_ANALYZER_OUTPUT=plist-html CLANG_ANALYZER_OUTPUT_DIR=./clangReport RUN_CLANG_STATIC_ANALYZER=YES
- name: Report Static Analysis
env:
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd .github/DangerFiles
bundle update && bundle install
bundle exec danger --dangerfile=StaticAnalysis.rb --danger_id=StaticAnalysis
test-orchestrator:
runs-on: macos-latest
outputs:
libs: ${{ steps.test-orchestrator.outputs.libs }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 100
- name: Determine Tests to Run
id: test-orchestrator
env:
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
xcodebuild analyze -workspace SalesforceMobileSDK.xcworkspace -scheme MobileSync -sdk 'iphonesimulator' \
CLANG_ANALYZER_OUTPUT=plist-html CLANG_ANALYZER_OUTPUT_DIR=./clangReport RUN_CLANG_STATIC_ANALYZER=YES | xcbeautify
cd .github
cd .github/DangerFiles
bundle update && bundle install
bundle exec danger --dangerfile=DangerStaticAnalysis.rb
bundle exec danger --dangerfile=TestOrchestrator.rb
ios-pr:
needs: [static-analysis]
needs: [test-orchestrator]
strategy:
fail-fast: false
matrix:
lib: ${{ fromJson(needs.static-analysis.outputs.libs) }}
lib: ${{ fromJson(needs.test-orchestrator.outputs.libs) }}
uses: ./.github/workflows/reusable-workflow.yaml
with:
lib: ${{ matrix.lib }}
17 changes: 13 additions & 4 deletions .github/workflows/reusable-workflow.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
on:
workflow_dispatch:
workflow_call:
inputs:
lib:
Expand All @@ -21,10 +22,12 @@ jobs:
with:
fetch-depth: 100
- name: Install Dependencies
env:
TEST_CREDENTIALS: ${{ secrets.TEST_CREDENTIALS }}
run: |
npm install [email protected]
./install.sh
echo ${{ secrets.TEST_CREDENTIALS }} > ./shared/test/test_credentials.json
echo $TEST_CREDENTIALS > ./shared/test/test_credentials.json
- uses: mxcl/xcodebuild@v3
with:
xcode: ${{ inputs.xcode }}
Expand All @@ -35,10 +38,16 @@ jobs:
code-coverage: ${{ github.event_name == 'pull_request' }}
upload-logs: always
- name: Danger Test Results
if: ${{ github.event_name == 'pull_request' }} && (success() || failure())
if: (github.event_name == 'pull_request') && failure()
env:
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd .github
cd .github/DangerFiles
bundle update && bundle install
bundle exec danger --dangerfile=DangerTestResults.rb --danger_id=${{ inputs.lib }}
bundle exec danger --dangerfile=TestResults.rb --danger_id=${{ inputs.lib }}
- uses: codecov/codecov-action@v4
with:
flags: ${{ inputs.lib }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
if: success() || failure()

0 comments on commit 623204d

Please sign in to comment.