diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..00184d1 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,3 @@ +# All requests must be reviewed and approved by: + +* @EchoEllet diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..281b8a0 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: daily + - package-ecosystem: pub + directory: / + schedule: + interval: daily diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000..7390760 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,22 @@ +ci: + - changed-files: + - any-glob-to-all-files: + - .github/** + +documentation: + - changed-files: + - any-glob-to-all-files: + - CONTRIBUTING.md + - CHANGELOG.md + - README.md + +example: + - changed-files: + - any-glob-to-all-files: example/** + +test: + - changed-files: + - any-glob-to-all-files: + - test/** + - example/macos/RunnerTests/**/*.swift + - example/macos/RunnerUITests/**/*.swift diff --git a/.github/workflows/coverage-badge.yml b/.github/workflows/coverage-badge.yml index 0cb4595..de0cf03 100644 --- a/.github/workflows/coverage-badge.yml +++ b/.github/workflows/coverage-badge.yml @@ -36,6 +36,7 @@ jobs: run: | echo "The code coverage percentage is ${{ steps.coverage-extractor.outputs.COVERAGE }}" + # TODO(EchoEllet): Collect Swift coverage too, https://github.com/CompileKernel/native-image-picker-macos/issues/6 # For a detailed guide, refer to: https://bitspittle.dev/blog/2022/kover-badge - name: Update dynamic badge gist uses: schneegans/dynamic-badges-action@v1.7.0 diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 0000000..b44b9db --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,11 @@ +name: Pull Request Labeler +on: [pull_request_target] + +jobs: + labeler: + permissions: + contents: read + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v5 diff --git a/.github/workflows/swift-format-check.yml b/.github/workflows/swift-format-check.yml index a87c1ec..093a2b8 100644 --- a/.github/workflows/swift-format-check.yml +++ b/.github/workflows/swift-format-check.yml @@ -6,10 +6,16 @@ on: branches: [main] paths: - macos/native_image_picker_macos/**/*.swift + - example/macos/Runner/**/*.swift + - example/macos/RunnerTests/**/*.swift + - example/macos/RunnerUITests/**/*.swift - .github/workflows/swift-format-check.yml pull_request: paths: - macos/native_image_picker_macos/**/*.swift + - example/macos/Runner/**/*.swift + - example/macos/RunnerTests/**/*.swift + - example/macos/RunnerUITests/**/*.swift - .github/workflows/swift-format-check.yml jobs: @@ -27,12 +33,29 @@ jobs: - name: 🛠️ Setup Swift uses: swift-actions/setup-swift@v2 + - name: Cache Swift Format + uses: actions/cache@v4 + with: + path: ~/.cache/swift-format + key: swift-format-${{ runner.os }}-${{ env.SWIFT_FORMAT_VERSION }}-${{ hashFiles('**/Package.resolved') }} + restore-keys: | + swift-format-${{ runner.os }}-${{ env.SWIFT_FORMAT_VERSION }}- + - name: 📦 Install Swift Format run: | - git clone --branch $SWIFT_FORMAT_VERSION --depth 1 https://github.com/swiftlang/swift-format.git - cd swift-format - swift build -c release - sudo mv .build/release/swift-format /usr/local/bin/ + if [ -f ~/.cache/swift-format ]; then + echo "Using the cached Swift Format." + sudo cp -f ~/.cache/swift-format /usr/local/bin/swift-format + else + echo "Swift Format is not cached, building and installing..." + git clone --branch $SWIFT_FORMAT_VERSION --depth 1 https://github.com/swiftlang/swift-format.git + cd swift-format + swift build --disable-sandbox -c release + sudo cp -f .build/release/swift-format /usr/local/bin/ + + echo "Caching the built swift-format" + cp -f .build/release/swift-format ~/.cache/swift-format + fi - name: 🔍 Verify Swift Format installation run: swift-format --version @@ -41,7 +64,7 @@ jobs: run: swift-format dump-configuration - name: 🔎 Validate Swift Code Formatting - run: swift-format lint -r macos/native_image_picker_macos/Sources/native_image_picker_macos --strict + run: swift-format lint --strict -r macos/native_image_picker_macos/Sources/native_image_picker_macos example/macos/Runner example/macos/RunnerTests example/macos/RunnerUITests # SwiftLint: https://github.com/realm/SwiftLint # - name: 🎨 Verify Swift Code Style with SwiftLint diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..ff0c768 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,69 @@ +name: Run tests + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + dart-unit-tests: + name: Dart unit tests + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Flutter (stable) + uses: subosito/flutter-action@v2 + with: + channel: stable + cache: true + + - name: Install package dependencies + run: flutter pub get + + - name: Run tests + run: flutter test + + native-macos-unit-tests: + name: Native macOS unit tests + runs-on: macos-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Flutter (stable) + uses: subosito/flutter-action@v2 + with: + channel: stable + cache: true + + # To skip installing CocoaPods, ruby and avoid any build failures or compatibility issues. + - name: Enable Flutter Swift Package Manager + run: flutter config --enable-swift-package-manager + + - name: Install dependencies + run: flutter pub get + working-directory: example + + - name: Set up Xcode + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: latest-stable + + # macOS 14+ requires UI access to open the app for running tests. To work around this, disable macOS sandboxing. + # For more details, see: https://github.com/flutter/packages/pull/6866 + - name: Disable macOS sandboxing + run: | + # Replace with for DebugProfile.entitlements + /usr/libexec/PlistBuddy -c "Set :com.apple.security.app-sandbox bool false" DebugProfile.entitlements + + # Replace with for Release.entitlements + /usr/libexec/PlistBuddy -c "Set :com.apple.security.app-sandbox bool false" Release.entitlements + working-directory: example/macos/Runner + + # Native macOS tests are in the example app: https://docs.flutter.dev/testing/testing-plugins#native-unit-tests + - name: Run tests + run: xcodebuild test -workspace Runner.xcworkspace -scheme Runner -configuration Debug -quiet + working-directory: example/macos diff --git a/README.md b/README.md index 8f7c7d4..307b394 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,10 @@ This package uses [pigeon](https://pub.dev/packages/pigeon) for platform communi ```shell $ dart run pigeon --input pigeons/messages.dart # To generate the required Dart and host-language code. $ dart run build_runner build --delete-conflicting-outputs # To generate the mock classes. -$ swift-format format --in-place --recursive macos/native_image_picker_macos/Sources/native_image_picker_macos # To format the Swift code. +$ swift-format format --in-place --recursive macos/native_image_picker_macos/Sources/native_image_picker_macos example/macos/Runner example/macos/RunnerTests example/macos/RunnerUITests # To format the Swift code. +$ dart format . # To format the Dart code. +$ (cd example/macos && xcodebuild test -workspace Runner.xcworkspace -scheme Runner -configuration Debug -quiet) # To run the native macOS unit tests. +$ flutter test # To run the Flutter unit tests. ``` ### Resources diff --git a/example/macos/RunnerTests/ImageCompressTests.swift b/example/macos/RunnerTests/ImageCompressTests.swift index 9fd2e4d..fa8aa9e 100644 --- a/example/macos/RunnerTests/ImageCompressTests.swift +++ b/example/macos/RunnerTests/ImageCompressTests.swift @@ -1,4 +1,5 @@ import XCTest + @testable import native_image_picker_macos final class ImageCompressTests: XCTestCase { diff --git a/example/macos/RunnerTests/ImageResizeTests.swift b/example/macos/RunnerTests/ImageResizeTests.swift index 082d4d2..8d05d8e 100644 --- a/example/macos/RunnerTests/ImageResizeTests.swift +++ b/example/macos/RunnerTests/ImageResizeTests.swift @@ -1,4 +1,5 @@ import XCTest + @testable import native_image_picker_macos final class ImageResizeTests: XCTestCase { diff --git a/example/macos/RunnerTests/RunnerTests.swift b/example/macos/RunnerTests/RunnerTests.swift index cac6461..d6dd34e 100644 --- a/example/macos/RunnerTests/RunnerTests.swift +++ b/example/macos/RunnerTests/RunnerTests.swift @@ -1,4 +1,5 @@ import XCTest + @testable import native_image_picker_macos // TODO(EchoEllet): Lacks native UI tests, https://discord.com/channels/608014603317936148/1300517990957056080/1300518056690188361 @@ -9,7 +10,7 @@ import XCTest final class RunnerTests: XCTestCase { func testSupportsPHPicker() { - let imagePicker = ImagePickerImpl() + let imagePicker = ImagePickerImpl(view: nil) if #available(macOS 13.0, *) { XCTAssertTrue( imagePicker.supportsPHPicker(),