Add GitHub Actions CI/CD pipelines #2
Workflow file for this run
This file contains hidden or 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
name: Code Quality | |
on: | |
push: | |
branches: [ main, develop ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
swiftformat: | |
name: SwiftFormat Check | |
runs-on: macos-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install SwiftFormat | |
run: brew install swiftformat | |
- name: Check code formatting | |
run: | | |
swiftformat --version | |
swiftformat . --lint --verbose | |
continue-on-error: true | |
- name: Generate format diff | |
if: failure() | |
run: | | |
swiftformat . --dryrun > format-diff.txt | |
cat format-diff.txt | |
- name: Upload format diff | |
if: failure() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: format-diff | |
path: format-diff.txt | |
code-coverage: | |
name: Code Coverage | |
runs-on: macos-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Select Xcode version | |
run: sudo xcode-select -s /Applications/Xcode_15.4.app/Contents/Developer | |
- name: Install xcpretty | |
run: gem install xcpretty | |
- name: Build and test with coverage | |
run: | | |
xcodebuild test \ | |
-project V2er.xcodeproj \ | |
-scheme V2er \ | |
-sdk iphonesimulator \ | |
-destination 'platform=iOS Simulator,name=iPhone 15' \ | |
-enableCodeCoverage YES \ | |
-derivedDataPath build/DerivedData \ | |
CODE_SIGN_IDENTITY="" \ | |
CODE_SIGNING_REQUIRED=NO | xcpretty | |
- name: Generate coverage report | |
run: | | |
cd build/DerivedData | |
xcrun xccov view --report --json Build/Logs/Test/*.xcresult > coverage.json | |
# Extract coverage percentage | |
COVERAGE=$(cat coverage.json | jq '.lineCoverage' | awk '{printf "%.2f", $1 * 100}') | |
echo "Code coverage: ${COVERAGE}%" | |
echo "coverage=${COVERAGE}" >> $GITHUB_ENV | |
- name: Create coverage badge | |
uses: schneegans/[email protected] | |
with: | |
auth: ${{ secrets.GIST_SECRET }} | |
gistID: YOUR_GIST_ID | |
filename: v2er-ios-coverage.json | |
label: Coverage | |
message: ${{ env.coverage }}% | |
color: ${{ env.coverage > 80 && 'success' || env.coverage > 60 && 'yellow' || 'critical' }} | |
- name: Comment PR with coverage | |
if: github.event_name == 'pull_request' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const coverage = '${{ env.coverage }}'; | |
const emoji = coverage > 80 ? '✅' : coverage > 60 ? '⚠️' : '❌'; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `## Code Coverage Report ${emoji}\n\nCurrent coverage: **${coverage}%**` | |
}); |