From a8b2350705db2065b0950f7f89b89f5d8cc3b06e Mon Sep 17 00:00:00 2001 From: liuyuxin Date: Wed, 25 Oct 2023 23:15:53 +0800 Subject: [PATCH] feat(dart): Add build check for Dart (#886) * feat(dart): Add build check for Dart * feat(dart): Add dart analyze to check * fix(dart): remove dart analyze * feat(dart): Ignore unused variable and add dart analyze --- .github/workflows/dart.yml | 36 +++++++++++++++++ codes/dart/build.dart | 39 +++++++++++++++++++ .../chapter_array_and_linkedlist/array.dart | 2 + .../chapter_array_and_linkedlist/list.dart | 2 + .../space_complexity.dart | 2 + .../time_complexity.dart | 2 + 6 files changed, 83 insertions(+) create mode 100644 .github/workflows/dart.yml create mode 100644 codes/dart/build.dart diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml new file mode 100644 index 0000000000..4db3e5b8eb --- /dev/null +++ b/.github/workflows/dart.yml @@ -0,0 +1,36 @@ +# This workflow will install Dart SDK, run format and build with Dart + +name: Dart + +on: + push: + branches: ["main"] + paths: ["codes/dart/**/*.dart"] + pull_request: + branches: ["main"] + paths: ["codes/dart/**/*.dart"] + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + name: Dart ${{ matrix.dart-sdk }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + dart-sdk: [stable, beta, dev] + steps: + - uses: actions/checkout@v3 + - name: Set up Dart ${{ matrix.dart-sdk }} + uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ matrix.dart-sdk}} + - name: Run format + run: dart format codes/dart + - name: Run analyze + run: dart analyze codes/dart + - name: Run build + run: dart codes/dart/build.dart diff --git a/codes/dart/build.dart b/codes/dart/build.dart new file mode 100644 index 0000000000..7bd5b51a14 --- /dev/null +++ b/codes/dart/build.dart @@ -0,0 +1,39 @@ +import 'dart:io'; + +void main() { + Directory foldPath = Directory('codes/dart/'); + List files = foldPath.listSync(); + int totalCount = 0; + int errorCount = 0; + for (var file in files) { + if (file.path.endsWith('build.dart')) continue; + if (file is File && file.path.endsWith('.dart')) { + totalCount++; + try { + Process.runSync('dart', [file.path]); + } catch (e) { + errorCount++; + print('Error: $e'); + print('File: ${file.path}'); + } + } else if (file is Directory) { + List subFiles = file.listSync(); + for (var subFile in subFiles) { + if (subFile is File && subFile.path.endsWith('.dart')) { + totalCount++; + try { + Process.runSync('dart', [subFile.path]); + } catch (e) { + errorCount++; + print('Error: $e'); + print('File: ${file.path}'); + } + } + } + } + } + + print('===== Build Complete ====='); + print('Total: $totalCount'); + print('Error: $errorCount'); +} diff --git a/codes/dart/chapter_array_and_linkedlist/array.dart b/codes/dart/chapter_array_and_linkedlist/array.dart index da2cc3ea5e..9309d64f4d 100644 --- a/codes/dart/chapter_array_and_linkedlist/array.dart +++ b/codes/dart/chapter_array_and_linkedlist/array.dart @@ -4,6 +4,8 @@ * Author: Jefferson (JeffersonHuang77@gmail.com) */ +// ignore_for_file: unused_local_variable + import 'dart:math'; /* 随机访问元素 */ diff --git a/codes/dart/chapter_array_and_linkedlist/list.dart b/codes/dart/chapter_array_and_linkedlist/list.dart index f0837fe5d1..f0b2e83cfb 100644 --- a/codes/dart/chapter_array_and_linkedlist/list.dart +++ b/codes/dart/chapter_array_and_linkedlist/list.dart @@ -4,6 +4,8 @@ * Author: Jefferson (JeffersonHuang77@gmail.com) */ +// ignore_for_file: unused_local_variable + /* Driver Code */ void main() { /* 初始化列表 */ diff --git a/codes/dart/chapter_computational_complexity/space_complexity.dart b/codes/dart/chapter_computational_complexity/space_complexity.dart index b6b83fc1ed..2155ea2ca1 100644 --- a/codes/dart/chapter_computational_complexity/space_complexity.dart +++ b/codes/dart/chapter_computational_complexity/space_complexity.dart @@ -4,6 +4,8 @@ * Author: Jefferson (JeffersonHuang77@gmail.com) */ +// ignore_for_file: unused_local_variable + import 'dart:collection'; import '../utils/list_node.dart'; import '../utils/print_util.dart'; diff --git a/codes/dart/chapter_computational_complexity/time_complexity.dart b/codes/dart/chapter_computational_complexity/time_complexity.dart index fc9f64ee09..2e6c62c495 100644 --- a/codes/dart/chapter_computational_complexity/time_complexity.dart +++ b/codes/dart/chapter_computational_complexity/time_complexity.dart @@ -4,6 +4,8 @@ * Author: Jefferson (JeffersonHuang77@gmail.com) */ +// ignore_for_file: unused_local_variable + /* 常数阶 */ int constant(int n) { int count = 0;