Skip to content

[CI] Fix Sonar issue on develop (#862) #106

[CI] Fix Sonar issue on develop (#862)

[CI] Fix Sonar issue on develop (#862) #106

Workflow file for this run

name: Sonar
on:
push:
branches:
- develop
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
sonar:
runs-on: macos-15
steps:
- uses: actions/[email protected]
- uses: actions/github-script@v6
id: get_pr_number
with:
script: |
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo,
});
return prs.data[0]?.number || '';
- name: Run Sonar analysis
run: |
if [[ -z "${{ steps.get_pr_number.outputs.result }}" ]]; then
echo "No PR found. Skipping Sonar analysis."
exit 0
fi
ARTIFACT_NAME="test-coverage-${{ steps.get_pr_number.outputs.result }}"
ARTIFACT=$(gh api repos/${{ github.repository }}/actions/artifacts | jq -r ".artifacts | map(select(.name==\"$ARTIFACT_NAME\")) | first")
if [[ "$ARTIFACT" == null || "$ARTIFACT" == "" ]]; then
echo "Artifact not found. Skipping Sonar analysis."
else
gh run download $(echo $ARTIFACT | jq .workflow_run.id) -n "$ARTIFACT_NAME" -D reports
bundle exec fastlane sonar_upload
fi
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}