[DEV-000000] DO NOT MERGE IT - TESTING #22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow ensures that pull requests and commits to the main iOS branches are properly analyzed and tested. | |
# Workflow 'iOS PR Quality Check' runs static code analysis, installs dependencies, and verifies code coverage. | |
# It helps maintain code quality and adherence to best practices before merging into the main branch. | |
# For furthuer information, check: https://trustly.atlassian.net/wiki/spaces/Engineering/pages/71335182425/iOS+PR+Quality+Check | |
name: iOS PR Quality Check | |
on: | |
pull_request: | |
types: [opened, reopened, synchronize] | |
workflow_dispatch: | |
env: | |
PR_NUMBER: ${{ github.event.number }} | |
BRANCH_ORIGIN: ${{ github.head_ref }} | |
BASE_BRANCH: ${{ github.base_ref }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_SECRET }} | |
SONAR_HOST_URL: "https://sonarqube.trustly.one" | |
SONAR_PROJECT_KEY: "trustly-ios" | |
SONAR_PROJECT_NAME: "trustly-ios" | |
jobs: | |
run_tests_and_sonar_analysis: | |
runs-on: macOS-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Get Git Revision (Commit SHA) | |
id: git_revision | |
run: | | |
git fetch origin "${BRANCH_ORIGIN}" | |
GIT_REVISION=$(git rev-parse origin/${BRANCH_ORIGIN}) | |
echo "Git Revision: $GIT_REVISION" | |
echo "GIT_REVISION=$GIT_REVISION" >> $GITHUB_ENV | |
- name: Setup Xcode | |
uses: maxim-lobanov/setup-xcode@v1 | |
with: | |
xcode-version: latest | |
- name: Install dependencies | |
run: | | |
# Update Homebrew | |
# brew update | |
# Install SwiftLint | |
brew install swiftlint | |
# Install Tailor | |
brew install tailor | |
# Install xcpretty | |
sudo gem install -n /usr/local/bin xcpretty | |
# Install Lizard | |
brew install lizard | |
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer | |
sudo xcodebuild -license accept | |
- name: Install CocoaPods | |
run: | | |
gem install cocoapods | |
pod install --project-directory=Example | |
- name: Install sonnar-scanner | |
run: | | |
brew install sonar-scanner | |
- name: Update sonar properties | |
run: | | |
echo "sonar.host.url=${{ env.SONAR_HOST_URL }}" >> sonar-project.properties | |
echo "sonar.projectKey=${{ env.SONAR_PROJECT_KEY }}" >> sonar-project.properties | |
echo "sonar.projectName=${{ env.SONAR_PROJECT_NAME }}" >> sonar-project.properties | |
echo "sonar.login=${{ secrets.SONAR_TOKEN_SECRET }}" >> sonar-project.properties | |
echo "sonar.pullrequest.key=${{ github.event.number }}" >> sonar-project.properties | |
echo "sonar.pullrequest.branch=${{ github.head_ref }}" >> sonar-project.properties | |
echo "sonar.pullrequest.base=${{ github.base_ref }}" >> sonar-project.properties | |
echo "sonar.scm.revision=${{ env.GIT_REVISION }}" >> sonar-project.properties | |
- name: Clean Xcode and Simulator Caches | |
run: | | |
osascript -e 'quit app "Xcode"' | |
osascript -e 'quit app "Simulator"' | |
pkill -9 -f Simulator || true | |
pkill -9 -f com.apple.CoreSimulator || true | |
rm -rf ~/Library/Developer/Xcode/DerivedData | |
rm -rf ~/Library/Caches/com.apple.dt.Xcode | |
rm -rf ~/Library/Developer/CoreSimulator/Caches | |
echo "Xcode caches and simulator processes cleaned up." | |
- name: Install Xcode dependencies | |
run: | | |
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer | |
sudo xcodebuild -runFirstLaunch | |
- name: Run Sonar-Swift Script | |
run: | | |
chmod +x ./run-sonar-swift.sh | |
./run-sonar-swift.sh -v | |
- name: Verify Coverage Report | |
run: | | |
if [ -f "sonar-reports/generic-coverage.xml" ]; then | |
echo "Coverage report generated successfully: sonar-reports/generic-coverage.xml" | |
cat sonar-reports/generic-coverage.xml | |
else | |
echo "Coverage report not found!" && exit 1 | |
fi |