Skip to content

Commit

Permalink
use latest script
Browse files Browse the repository at this point in the history
  • Loading branch information
semirp committed Apr 23, 2024
1 parent e7030e6 commit bf9fc0a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 39 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/build_test_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,18 @@ jobs:
MATCH_KEYCHAIN_PASSWORD: ${{ secrets.MATCH_KEYCHAIN_PASSWORD }}
SOURCE_BRANCH: ${{ github.head_ref }}
- name: Prepare coverage reports
run: >
bash Scripts/xccov-to-sonarqube-generic.sh
./fastlane/test_output/PrimerSDKTests.xcresult/ >
coverage.xml
run: |
bash Scripts/xccov-to-sonarqube-generic.sh ./fastlane/test_output/PrimerSDKTests.xcresult/ > coverage.xml
sed "s#$PWD/##g" coverage.xml > coverage_cleaned.xml
- name: Install Sonar-Scanner
run: |
brew install sonar-scanner
- name: Run Sonar scanner
run: |
sonar-scanner -Dsonar.token=${{ secrets.SONAR_TOKEN }} -Dsonar.coverageReportPaths=coverage.xml
git fetch --unshallow --no-tags
sonar-scanner -Dsonar.token=${{ secrets.SONAR_TOKEN }} -Dsonar.coverageReportPaths=coverage_cleaned.xml
cat coverage_cleaned.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-upload-to-appetize:
Expand Down
65 changes: 31 additions & 34 deletions Scripts/xccov-to-sonarqube-generic.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
#!/usr/bin/env bash
set -euo pipefail

function convert_xccov_to_xml {
sed -n \
-e '/:$/s/&/\&amp;/g;s/^\(.*\):$/ <file path="\1">/p' \
-e 's/^ *\([0-9][0-9]*\): 0.*$/ <lineToCover lineNumber="\1" covered="false"\/>/p' \
-e 's/^ *\([0-9][0-9]*\): [1-9].*$/ <lineToCover lineNumber="\1" covered="true"\/>/p' \
-e 's/^$/ <\/file>/p'
function convert_file {
local xccovarchive_file="$1"
local file_name="$2"
local xccov_options="$3"
echo " <file path=\"$file_name\">"
xcrun xccov view $xccov_options --file "$file_name" "$xccovarchive_file" | \
sed -n '
s/^ *\([0-9][0-9]*\): 0.*$/ <lineToCover lineNumber="\1" covered="false"\/>/p;
s/^ *\([0-9][0-9]*\): [1-9].*$/ <lineToCover lineNumber="\1" covered="true"\/>/p
'
echo ' </file>'
}

function xccov_to_generic {
local xcresult="$1"

echo '<coverage version="1">'
xcrun xccov view --archive "$xcresult" | convert_xccov_to_xml
for xccovarchive_file in "$@"; do
if [[ ! -d $xccovarchive_file ]]
then
echo "Coverage FILE NOT FOUND AT PATH: $xccovarchive_file" 1>&2;
exit 1
fi

local xccov_options=""
if [[ $xccovarchive_file == *".xcresult"* ]]; then
xccov_options="--archive"
fi
xcrun xccov view $xccov_options --file-list "$xccovarchive_file" | while read -r file_name; do
convert_file "$xccovarchive_file" "$file_name" "$xccov_options"
done
done
echo '</coverage>'
}

function check_xcode_version() {
local major=${1:-0} minor=${2:-0}
return $(( (major >= 14) || (major == 13 && minor >= 3) ))
function cleanup_tmp_files {
rm -rf tmp.json
rm -rf tmp.xccovarchive
}

if ! xcode_version="$(xcodebuild -version | sed -n '1s/^Xcode \([0-9.]*\)$/\1/p')"; then
echo 'Failed to get Xcode version' 1>&2
exit 1
elif check_xcode_version ${xcode_version//./ }; then
echo "Xcode version '$xcode_version' not supported, version 13.3 or above is required" 1>&2;
exit 1
fi

xcresult="$1"
if [[ $# -ne 1 ]]; then
echo "Invalid number of arguments. Expecting 1 path matching '*.xcresult'"
exit 1
elif [[ ! -d $xcresult ]]; then
echo "Path not found: $xcresult" 1>&2;
exit 1
elif [[ $xcresult != *".xcresult"* ]]; then
echo "Expecting input to match '*.xcresult', got: $xcresult" 1>&2;
exit 1
fi

xccov_to_generic "$xcresult"
xccov_to_generic "$@"
cleanup_tmp_files

0 comments on commit bf9fc0a

Please sign in to comment.