From 3b7413fc0968016df1d553633ed38f5e155ba4e2 Mon Sep 17 00:00:00 2001 From: EyreFree Date: Sat, 2 Aug 2025 22:59:03 +0800 Subject: [PATCH] ci: codecov --- .github/workflows/codecov.yml | 76 ++++++++++++++++++++++++++++++ EFQRCode.xcodeproj/project.pbxproj | 6 +++ Tests/Tests.swift | 8 ++-- 3 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/codecov.yml diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 00000000..d6f75f08 --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,76 @@ +name: Code Coverage + +# Only run on pushes to main branch +on: + push: + branches: [ main ] + +# Cancel any in-progress workflow runs for the same branch +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + DEVELOPER_DIR: /Applications/Xcode.app/Contents/Developer + +jobs: + # Test Coverage + test-coverage: + name: Test Coverage + runs-on: macos-latest + strategy: + matrix: + platform: + - { name: "iOS", scheme: "iOS Example", destination: "platform=iOS Simulator,name=iPhone 15,OS=latest" } + - { name: "macOS", scheme: "macOS Example", destination: "platform=macOS" } + - { name: "tvOS", scheme: "tvOS Example", destination: "platform=tvOS Simulator,name=Apple TV,OS=latest" } + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup Xcode + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: latest + + - name: Run Tests with Coverage + run: | + xcodebuild test \ + -workspace EFQRCode.xcworkspace \ + -scheme "${{ matrix.platform.scheme }}" \ + -destination "${{ matrix.platform.destination }}" \ + -enableCodeCoverage YES \ + -derivedDataPath ./DerivedData-${{ matrix.platform.name }} \ + CODE_SIGN_IDENTITY="" \ + CODE_SIGNING_REQUIRED=NO + + - name: Generate Coverage Report + run: | + xcrun xccov view --report --json ./DerivedData-${{ matrix.platform.name }}/Logs/Test/*.xcresult > coverage-${{ matrix.platform.name }}.json + + - name: Upload Coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage-${{ matrix.platform.name }}.json + flags: unittests,${{ matrix.platform.name }} + name: codecov-${{ matrix.platform.name }} + fail_ci_if_error: true + + # Status Check + status-check: + name: Coverage Status Check + runs-on: macos-latest + needs: [test-coverage] + if: always() + + steps: + - name: Check Results + run: | + if [[ "${{ needs.test-coverage.result }}" != "success" ]]; then + echo "❌ Code coverage collection failed" + exit 1 + fi + + echo "✅ Code coverage successfully uploaded to Codecov!" \ No newline at end of file diff --git a/EFQRCode.xcodeproj/project.pbxproj b/EFQRCode.xcodeproj/project.pbxproj index 055b1b69..db96452a 100755 --- a/EFQRCode.xcodeproj/project.pbxproj +++ b/EFQRCode.xcodeproj/project.pbxproj @@ -999,6 +999,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; SWIFT_VERSION = 5.0; + TVOS_DEPLOYMENT_TARGET = 13; }; name = Debug; }; @@ -1019,6 +1020,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; SWIFT_VERSION = 5.0; + TVOS_DEPLOYMENT_TARGET = 13; }; name = Release; }; @@ -1348,6 +1350,7 @@ "$(inherited)", ); INFOPLIST_FILE = Tests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -1367,6 +1370,7 @@ DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = Tests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -1401,6 +1405,7 @@ "@executable_path/../Frameworks", "@loader_path/../Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = 10.15; PRODUCT_BUNDLE_IDENTIFIER = "org.eyrefree.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1429,6 +1434,7 @@ "@executable_path/../Frameworks", "@loader_path/../Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = 10.15; PRODUCT_BUNDLE_IDENTIFIER = "org.eyrefree.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 55ddb160..bcc90483 100755 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -52,7 +52,7 @@ class Tests: XCTestCase { // This is an example of EFQRCodeGenerator test case. let content = "https://github.com/EFPrefix/EFQRCode" let generator = try? EFQRCode.Generator(content, style: .basic(params: .init())) - let testResult = try? generator?.toImage(width: 256).cgImage + let testResult = try? generator?.toImage(width: 256).cgImage() XCTAssertNotNil(testResult, "testResult is nil!") // This is an example of EFQRCodeRecognizer test case. @@ -65,7 +65,7 @@ class Tests: XCTestCase { // This is an example of EFQRCodeGenerator test case. let content = "" let generator = try? EFQRCode.Generator(content, style: .bubble(params: .init())) - let testResult = try? generator?.toImage(width: 180).cgImage + let testResult = try? generator?.toImage(width: 180).cgImage() XCTAssertNotNil(testResult, "testResult is nil!") // This is an example of EFQRCodeRecognizer test case. @@ -78,7 +78,7 @@ class Tests: XCTestCase { // This is an example of EFQRCodeGenerator test case. let content = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989" let generator = try? EFQRCode.Generator(content, style: .bubble(params: .init())) - let testResult = try? generator?.toImage(width: 180).cgImage + let testResult = try? generator?.toImage(width: 1200).cgImage() XCTAssertNotNil(testResult, "testResult is nil!") // This is an example of EFQRCodeRecognizer test case. @@ -96,7 +96,7 @@ class Tests: XCTestCase { image: .init(image: .static(image: getImage()), allowTransparent: true)) ) ) - let testResult = try? generator?.toImage(width: 180).cgImage + let testResult = try? generator?.toImage(width: 180).cgImage() XCTAssertNotNil(testResult, "testResult is nil!") }