Skip to content

Commit c2272a4

Browse files
authored
ci: test workflows, labelers, other CI related (#8)
* chore: format swift test files, fix RunnerTests.swift * docs: update swift format command to reflect the macOS native tests * ci: check swift format for the plugin native tests and the example Runner * docs: update swift format command to format the example Runner Swift files in README * ci: configure GitHub labelers * ci: add CODEOWNERS and dependabot * docs: add macOS native unit test command, other commands, a TODO in code coverage workflow * ci: add tests GitHub workflow * ci: cache swift-format
1 parent f4f4d21 commit c2272a4

11 files changed

+152
-7
lines changed

.github/CODEOWNERS

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# All requests must be reviewed and approved by:
2+
3+
* @EchoEllet

.github/dependabot.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily
7+
- package-ecosystem: pub
8+
directory: /
9+
schedule:
10+
interval: daily

.github/labeler.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ci:
2+
- changed-files:
3+
- any-glob-to-all-files:
4+
- .github/**
5+
6+
documentation:
7+
- changed-files:
8+
- any-glob-to-all-files:
9+
- CONTRIBUTING.md
10+
- CHANGELOG.md
11+
- README.md
12+
13+
example:
14+
- changed-files:
15+
- any-glob-to-all-files: example/**
16+
17+
test:
18+
- changed-files:
19+
- any-glob-to-all-files:
20+
- test/**
21+
- example/macos/RunnerTests/**/*.swift
22+
- example/macos/RunnerUITests/**/*.swift

.github/workflows/coverage-badge.yml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
run: |
3737
echo "The code coverage percentage is ${{ steps.coverage-extractor.outputs.COVERAGE }}"
3838
39+
# TODO(EchoEllet): Collect Swift coverage too, https://github.com/CompileKernel/native-image-picker-macos/issues/6
3940
# For a detailed guide, refer to: https://bitspittle.dev/blog/2022/kover-badge
4041
- name: Update dynamic badge gist
4142
uses: schneegans/[email protected]

.github/workflows/labeler.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Pull Request Labeler
2+
on: [pull_request_target]
3+
4+
jobs:
5+
labeler:
6+
permissions:
7+
contents: read
8+
pull-requests: write
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/labeler@v5

.github/workflows/swift-format-check.yml

+28-5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ on:
66
branches: [main]
77
paths:
88
- macos/native_image_picker_macos/**/*.swift
9+
- example/macos/Runner/**/*.swift
10+
- example/macos/RunnerTests/**/*.swift
11+
- example/macos/RunnerUITests/**/*.swift
912
- .github/workflows/swift-format-check.yml
1013
pull_request:
1114
paths:
1215
- macos/native_image_picker_macos/**/*.swift
16+
- example/macos/Runner/**/*.swift
17+
- example/macos/RunnerTests/**/*.swift
18+
- example/macos/RunnerUITests/**/*.swift
1319
- .github/workflows/swift-format-check.yml
1420

1521
jobs:
@@ -27,12 +33,29 @@ jobs:
2733
- name: 🛠️ Setup Swift
2834
uses: swift-actions/setup-swift@v2
2935

36+
- name: Cache Swift Format
37+
uses: actions/cache@v4
38+
with:
39+
path: ~/.cache/swift-format
40+
key: swift-format-${{ runner.os }}-${{ env.SWIFT_FORMAT_VERSION }}-${{ hashFiles('**/Package.resolved') }}
41+
restore-keys: |
42+
swift-format-${{ runner.os }}-${{ env.SWIFT_FORMAT_VERSION }}-
43+
3044
- name: 📦 Install Swift Format
3145
run: |
32-
git clone --branch $SWIFT_FORMAT_VERSION --depth 1 https://github.com/swiftlang/swift-format.git
33-
cd swift-format
34-
swift build -c release
35-
sudo mv .build/release/swift-format /usr/local/bin/
46+
if [ -f ~/.cache/swift-format ]; then
47+
echo "Using the cached Swift Format."
48+
sudo cp -f ~/.cache/swift-format /usr/local/bin/swift-format
49+
else
50+
echo "Swift Format is not cached, building and installing..."
51+
git clone --branch $SWIFT_FORMAT_VERSION --depth 1 https://github.com/swiftlang/swift-format.git
52+
cd swift-format
53+
swift build --disable-sandbox -c release
54+
sudo cp -f .build/release/swift-format /usr/local/bin/
55+
56+
echo "Caching the built swift-format"
57+
cp -f .build/release/swift-format ~/.cache/swift-format
58+
fi
3659
3760
- name: 🔍 Verify Swift Format installation
3861
run: swift-format --version
@@ -41,7 +64,7 @@ jobs:
4164
run: swift-format dump-configuration
4265

4366
- name: 🔎 Validate Swift Code Formatting
44-
run: swift-format lint -r macos/native_image_picker_macos/Sources/native_image_picker_macos --strict
67+
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
4568

4669
# SwiftLint: https://github.com/realm/SwiftLint
4770
# - name: 🎨 Verify Swift Code Style with SwiftLint

.github/workflows/tests.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Run tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
dart-unit-tests:
11+
name: Dart unit tests
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Flutter (stable)
18+
uses: subosito/flutter-action@v2
19+
with:
20+
channel: stable
21+
cache: true
22+
23+
- name: Install package dependencies
24+
run: flutter pub get
25+
26+
- name: Run tests
27+
run: flutter test
28+
29+
native-macos-unit-tests:
30+
name: Native macOS unit tests
31+
runs-on: macos-latest
32+
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Set up Flutter (stable)
37+
uses: subosito/flutter-action@v2
38+
with:
39+
channel: stable
40+
cache: true
41+
42+
# To skip installing CocoaPods, ruby and avoid any build failures or compatibility issues.
43+
- name: Enable Flutter Swift Package Manager
44+
run: flutter config --enable-swift-package-manager
45+
46+
- name: Install dependencies
47+
run: flutter pub get
48+
working-directory: example
49+
50+
- name: Set up Xcode
51+
uses: maxim-lobanov/setup-xcode@v1
52+
with:
53+
xcode-version: latest-stable
54+
55+
# macOS 14+ requires UI access to open the app for running tests. To work around this, disable macOS sandboxing.
56+
# For more details, see: https://github.com/flutter/packages/pull/6866
57+
- name: Disable macOS sandboxing
58+
run: |
59+
# Replace <true/> with <false/> for DebugProfile.entitlements
60+
/usr/libexec/PlistBuddy -c "Set :com.apple.security.app-sandbox bool false" DebugProfile.entitlements
61+
62+
# Replace <true/> with <false/> for Release.entitlements
63+
/usr/libexec/PlistBuddy -c "Set :com.apple.security.app-sandbox bool false" Release.entitlements
64+
working-directory: example/macos/Runner
65+
66+
# Native macOS tests are in the example app: https://docs.flutter.dev/testing/testing-plugins#native-unit-tests
67+
- name: Run tests
68+
run: xcodebuild test -workspace Runner.xcworkspace -scheme Runner -configuration Debug -quiet
69+
working-directory: example/macos

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ This package uses [pigeon](https://pub.dev/packages/pigeon) for platform communi
133133
```shell
134134
$ dart run pigeon --input pigeons/messages.dart # To generate the required Dart and host-language code.
135135
$ dart run build_runner build --delete-conflicting-outputs # To generate the mock classes.
136-
$ swift-format format --in-place --recursive macos/native_image_picker_macos/Sources/native_image_picker_macos # To format the Swift code.
136+
$ 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.
137+
$ dart format . # To format the Dart code.
138+
$ (cd example/macos && xcodebuild test -workspace Runner.xcworkspace -scheme Runner -configuration Debug -quiet) # To run the native macOS unit tests.
139+
$ flutter test # To run the Flutter unit tests.
137140
```
138141

139142
### Resources

example/macos/RunnerTests/ImageCompressTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import XCTest
2+
23
@testable import native_image_picker_macos
34

45
final class ImageCompressTests: XCTestCase {

example/macos/RunnerTests/ImageResizeTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import XCTest
2+
23
@testable import native_image_picker_macos
34

45
final class ImageResizeTests: XCTestCase {

example/macos/RunnerTests/RunnerTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import XCTest
2+
23
@testable import native_image_picker_macos
34

45
// TODO(EchoEllet): Lacks native UI tests, https://discord.com/channels/608014603317936148/1300517990957056080/1300518056690188361
@@ -9,7 +10,7 @@ import XCTest
910
final class RunnerTests: XCTestCase {
1011

1112
func testSupportsPHPicker() {
12-
let imagePicker = ImagePickerImpl()
13+
let imagePicker = ImagePickerImpl(view: nil)
1314
if #available(macOS 13.0, *) {
1415
XCTAssertTrue(
1516
imagePicker.supportsPHPicker(),

0 commit comments

Comments
 (0)