Skip to content

ci: test workflows, labelers, other CI related #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# All requests must be reviewed and approved by:

* @EchoEllet
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
- package-ecosystem: pub
directory: /
schedule:
interval: daily
22 changes: 22 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .github/workflows/coverage-badge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 28 additions & 5 deletions .github/workflows/swift-format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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 <true/> with <false/> for DebugProfile.entitlements
/usr/libexec/PlistBuddy -c "Set :com.apple.security.app-sandbox bool false" DebugProfile.entitlements

# Replace <true/> with <false/> 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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions example/macos/RunnerTests/ImageCompressTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import XCTest

@testable import native_image_picker_macos

final class ImageCompressTests: XCTestCase {
Expand Down
1 change: 1 addition & 0 deletions example/macos/RunnerTests/ImageResizeTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import XCTest

@testable import native_image_picker_macos

final class ImageResizeTests: XCTestCase {
Expand Down
3 changes: 2 additions & 1 deletion example/macos/RunnerTests/RunnerTests.swift
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(),
Expand Down
Loading