Github Pull request summary from XCode Cloud

Template for a good new topic, formatted with Markdown:

  • ALM used - GitHub
  • CI system used - XCode Cloud
  • Languages of the repository - Swift
  • Error observed - No pull request summary
  • Steps to reproduce - Build, test and sonar analyze in XCode Cloud environment (as a post build phase - Apple Developer Documentation). Analysis is uploaded to SonarCloud successfully with Pull request reference, it is shown in SonarCloud dashboard. But report summary is not posted to Github Pull Request. It was working with Github Actions before, but stopped after migrating to XCode Cloud.
  • Potential workaround - Not found

hey Karim, are you doing code coverage? do you mind to share your post build script?

Hi @kerimovscreations,

Welcome to the community!

Does your analysis show up in SonarCloud as a PR analysis or as a branch/main?

 
Ann

Yeah, I have succeeded to integrate Sonar with XCode Cloud. Only missing part is summary report comment in the PR

ci_post_xcodebuild.sh

#!/bin/sh

if [[ "$CI_WORKFLOW" == "Analyze branch" ]];
then

(./run_sonar_analysis_branch.sh)

elif [[ "$CI_WORKFLOW" == "Build and test" ]];
then

(./run_sonar_analysis_pr.sh)

else

echo "No test coverage analyze"

fi

run_sonar_analysis_pr.sh

#!/bin/sh

if which fastlane >/dev/null; then
    cd $CI_WORKSPACE

    fastlane ios testpr \
        sonar_login:$SONAR_TOKEN \
        workspace:$CI_WORKSPACE \
        derived_data_path:$CI_DERIVED_DATA_PATH \
        app_scheme:"YOUR_SCHEME" \
        target_branch:$CI_PULL_REQUEST_TARGET_BRANCH \
        source_branch:$CI_PULL_REQUEST_SOURCE_BRANCH \
        pr_number:$CI_PULL_REQUEST_NUMBER
fi

run_sonar_analysis_branch.sh

#!/bin/sh

if which fastlane >/dev/null; then
    cd $CI_WORKSPACE

    fastlane ios testbranch \
        sonar_login:$SONAR_TOKEN \
        workspace:$CI_WORKSPACE \
        derived_data_path:$CI_DERIVED_DATA_PATH \
        app_scheme:"YOUR_SCHEME" \
        branch_name:$CI_BRANCH
fi

SONAR_TOKEN - is an environment variable setup at XCode cloud workflow config

Pull request info is fetched at post clone phase

fetch_pr_info.sh

#!/bin/sh

git -C $CI_WORKSPACE checkout -b temp
git -C $CI_WORKSPACE branch -d $CI_PULL_REQUEST_TARGET_BRANCH

git -C $CI_WORKSPACE config remote.origin.fetch \
"+refs/heads/$CI_PULL_REQUEST_SOURCE_BRANCH:refs/remotes/origin/$CI_PULL_REQUEST_SOURCE_BRANCH"
git -C $CI_WORKSPACE config remote.origin.fetch \
"+refs/heads/$CI_PULL_REQUEST_TARGET_BRANCH:refs/remotes/origin/$CI_PULL_REQUEST_TARGET_BRANCH"
git -C $CI_WORKSPACE fetch

Hi Ann,

This analysis is shown as a PR analysis.

Hi,

Are there any analysis warnings in the UI? Did you originally import the project into SonarCloud via the in-app wizards?

 
Ann

Hi,

I didn’t see any warnings in the UI, except 1 warning in the top right “Shallow clone detected during the analysis. Some files will miss SCM information. This will affect features like auto-assignment of issues. Please configure your build to disable shallow clone.”.

Project is imported long before me, I don’t know which method is applied. I guess this was imported by website sonarcloud. Organization is still bound to the Github. We have 600+ repos and the rest are working fine. Only XCode Cloud integration does not comment anything.

I guess this is related to the GITHUB_TOKEN environment variable, so it is not present in the XCode Cloud server’s environment.

Karim

Hi Karim,

I doubt it. That would prevent analysis from running. I’ve flagged this for more expert attention.

 
Ann

1 Like

The issue was fixed by bounding project to Sonar dashboard. Project was displaying “not bound” to the Github repo, I have removed and imported as a fresh sonar project. Then the issue was resolved

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.