Skip to content

Commit

Permalink
Add a CI workflow to check the tool/builder package (#25)
Browse files Browse the repository at this point in the history
* add a CI workflow to check the tool/builder package

* correct the builder workflow setup action

* check formatting on stable
  • Loading branch information
devoncarew authored Apr 24, 2024
1 parent 6a4dd57 commit 6d9c37a
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 20 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Dependabot configuration file.
# See https://docs.github.com/en/code-security/dependabot/dependabot-version-updates

version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
38 changes: 38 additions & 0 deletions .github/workflows/builder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: builder

# Declare default permissions as read only.
permissions: read-all

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
schedule:
- cron: '0 0 * * 0' # weekly

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: tool/builder
strategy:
fail-fast: false
matrix:
sdk: [stable]
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}

- run: dart pub get

- run: dart analyze --fatal-infos

- run: dart format --output=none --set-exit-if-changed .
if: ${{ matrix.sdk == 'stable' }}

# Ensure the tool can run without errors.
- run: dart bin/main.dart -h
5 changes: 2 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ name: Main Branch CI
permissions: read-all

on:
push:
branches: [main]
pull_request:
branches: [ main ]
push:
branches: [main, ffi-wrapper, ffi-wrapper-text-pkg]
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # Every day at midnight

Expand Down
12 changes: 12 additions & 0 deletions tool/builder/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@ include: package:lints/recommended.yaml
analyzer:
errors:
todo: ignore

linter:
rules:
- always_declare_return_types
- avoid_dynamic_calls
- comment_references
- directives_ordering
- library_annotations
- only_throw_errors
- prefer_relative_imports
- prefer_single_quotes
- sort_pub_dependencies
2 changes: 1 addition & 1 deletion tool/builder/bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:builder/sync_headers.dart';
final runner = CommandRunner(
'build',
'Performs build operations for google/flutter-mediapipe that '
'depend on contents in this repository',
'depend on contents in this repository.',
)
..addCommand(DownloadModelCommand())
..addCommand(SdksFinderCommand())
Expand Down
6 changes: 4 additions & 2 deletions tool/builder/lib/download_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// found in the LICENSE file.

import 'dart:io' as io;

import 'package:args/command_runner.dart';
import 'package:builder/repo_finder.dart';
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;

import 'repo_finder.dart';

final _log = Logger('DownloadModelCommand');

enum Model {
Expand Down Expand Up @@ -86,7 +88,7 @@ class DownloadModelCommand extends Command with RepoFinderMixin {
Model get model {
final value = Model.values.asNameMap()[argResults!['model']];
if (value == null) {
throw ('Unexpected Model value ${argResults!['model']}');
throw Exception('Unexpected Model value ${argResults!['model']}');
}
return value;
}
Expand Down
4 changes: 4 additions & 0 deletions tool/builder/lib/extensions.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:convert';
import 'dart:io';

Expand Down
3 changes: 2 additions & 1 deletion tool/builder/lib/repo_finder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
// found in the LICENSE file.

import 'dart:io' as io;

import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:io/ansi.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:io/ansi.dart';

/// Mixin to help [Command] subclasses locate both `google/mediapipe` and
/// the root of `google/flutter-mediapipe` (this repository).
Expand Down
15 changes: 10 additions & 5 deletions tool/builder/lib/sdks_finder.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// Copyright 2024 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:convert';
import 'dart:io';
import 'dart:io' as io;
import 'dart:io';

import 'package:args/command_runner.dart';
import 'package:builder/extensions.dart';
import 'package:builder/repo_finder.dart';
import 'package:io/ansi.dart';
import 'package:logging/logging.dart';
import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:path/path.dart' as path;

import 'extensions.dart';
import 'repo_finder.dart';

final _log = Logger('SDKsFinder');

/// Structure of flattened build locations suitable for JSON serialization.
Expand Down Expand Up @@ -71,7 +76,7 @@ class SdksFinderCommand extends Command with RepoFinderMixin {
}
@override
String description =
'Updates MediaPipe SDK manifest files for the current build target';
'Updates MediaPipe SDK manifest files for the current build target.';

@override
String name = 'sdks';
Expand Down Expand Up @@ -257,7 +262,7 @@ class _OsFinder {
);
}

/// Receives a [Path] like ".../[os_folder]/release/[build_number]/[date]/"
/// Receives a path like `".../[os_folder]/release/[build_number]/[date]/"`
/// and yields all matching architecture folders within.
Stream<String> _getArchitectectures(String path) async* {
final pathsWithinBuild = <String>[];
Expand Down
8 changes: 5 additions & 3 deletions tool/builder/lib/sync_headers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import 'dart:convert';
import 'dart:io' as io;

import 'package:args/command_runner.dart';
import 'package:builder/extensions.dart';
import 'package:builder/repo_finder.dart';
import 'package:io/ansi.dart';
import 'package:path/path.dart' as path;
import 'package:process/process.dart';

import 'extensions.dart';
import 'repo_finder.dart';

/// Relative header paths (in both repositories)
final containers = 'mediapipe/tasks/c/components/containers';
final processors = 'mediapipe/tasks/c/components/processors';
Expand Down Expand Up @@ -49,7 +51,7 @@ List<(String, String, String, Function(io.File)?)> headerPaths = [
/// disrupted by the move.
class SyncHeadersCommand extends Command with RepoFinderMixin {
@override
String description = 'Syncs header files to google/flutter-mediapipe';
String description = 'Syncs header files to google/flutter-mediapipe.';
@override
String name = 'headers';

Expand Down
9 changes: 4 additions & 5 deletions tool/builder/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: builder
description: Performs build operations for google/flutter-mediapipe that depend
on contents in this repository.
version: 1.0.0
# repository: https://github.com/my_org/my_repo
description: Performs build operations for google/flutter-mediapipe.

publish_to: none

environment:
sdk: ^3.1.5

# Add regular dependencies here.
dependencies:
args: ^2.4.2
http: ^1.1.0
Expand Down

0 comments on commit 6d9c37a

Please sign in to comment.