diff --git a/.github/workflows/native.yaml b/.github/workflows/native.yaml index 4a3c3eeb2..c954eba6b 100644 --- a/.github/workflows/native.yaml +++ b/.github/workflows/native.yaml @@ -13,6 +13,7 @@ on: - "pkgs/native_assets_builder/**" - "pkgs/native_assets_cli/**" - "pkgs/native_toolchain_c/**" + - "tools/**" push: branches: [main] paths: @@ -20,6 +21,7 @@ on: - "pkgs/native_assets_builder/**" - "pkgs/native_assets_cli/**" - "pkgs/native_toolchain_c/**" + - "tools/**" schedule: - cron: "0 0 * * 0" # weekly @@ -30,6 +32,7 @@ jobs: os: [ubuntu, macos, windows] sdk: [stable, dev] package: [native_assets_builder, native_assets_cli, native_toolchain_c] + dependencies: [published, path] # Breaking changes temporarily break the example run on the Dart SDK until native_assets_builder is rolled into the Dart SDK dev build. breaking-change: [false] exclude: @@ -38,6 +41,9 @@ jobs: sdk: dev - os: windows sdk: dev + # Only run path deps on dev + - sdk: stable + dependencies: published runs-on: ${{ matrix.os }}-latest @@ -57,6 +63,12 @@ jobs: ndk-version: r26b if: ${{ matrix.sdk == 'stable' }} + - run: dart pub get -C ../../tools/ + if: ${{ matrix.dependencies == 'path' }} + + - run: dart ../../tools/bin/change_dependencies.dart + if: ${{ matrix.dependencies == 'path' }} + - run: dart pub get - run: dart pub get -C test/data/dart_app/ @@ -114,11 +126,11 @@ jobs: - name: Install coverage run: dart pub global activate coverage - if: ${{ matrix.sdk == 'stable' }} + if: ${{ matrix.sdk == 'stable' && matrix.dependencies == 'published' }} - name: Collect coverage run: dart pub global run coverage:test_with_coverage - if: ${{ matrix.sdk == 'stable' }} + if: ${{ matrix.sdk == 'stable' && matrix.dependencies == 'published' }} - name: Upload coverage uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 @@ -126,7 +138,7 @@ jobs: flag-name: ${{ matrix.package }}_${{ matrix.os }} github-token: ${{ secrets.GITHUB_TOKEN }} parallel: true - if: ${{ matrix.sdk == 'stable' }} + if: ${{ matrix.sdk == 'stable' && matrix.dependencies == 'published' }} coverage-finished: needs: [build] diff --git a/tools/.gitignore b/tools/.gitignore new file mode 100644 index 000000000..0b3e7bc22 --- /dev/null +++ b/tools/.gitignore @@ -0,0 +1,9 @@ +# Please keep consistent with .pubignore. + +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/tools/bin/change_dependencies.dart b/tools/bin/change_dependencies.dart new file mode 100644 index 000000000..dd7b93ee4 --- /dev/null +++ b/tools/bin/change_dependencies.dart @@ -0,0 +1,52 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. 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:io'; + +import 'package:glob/glob.dart'; +import 'package:glob/list_local_fs.dart'; +import 'package:yaml_edit/yaml_edit.dart'; +import 'package:yaml/yaml.dart'; + +void main(List args) { + final root = Platform.script.resolve('../../'); + final glob = Glob('**pubspec.yaml'); + final files = glob.listSync(root: root.toFilePath()).whereType(); + for (final file in files) { + final yamlEditor = YamlEditor(file.readAsStringSync()); + final yaml = yamlEditor.parseAt([]); + if (yaml is! YamlMap) { + continue; + } + final dependencies = yaml['dependencies']; + if (dependencies is! YamlMap) { + continue; + } + for (final package in dependencies.keys) { + if (!packagesToPin.contains(package)) { + continue; + } + yamlEditor.update( + ['dependencies', package], + { + // Some packages contain full test projects that are copied in unit + // tests. So, use absolute paths. + 'path': + root.resolve('pkgs/$package/').toFilePath().replaceAll(r'\', '/'), + }, + ); + } + if (yamlEditor.edits.isEmpty) { + continue; + } + yamlEditor.update(['publish_to'], 'none'); + file.writeAsStringSync(yamlEditor.toString()); + } +} + +const packagesToPin = { + 'native_assets_builder', + 'native_assets_cli', + 'native_toolchain_c', +}; diff --git a/tools/pubspec.yaml b/tools/pubspec.yaml new file mode 100644 index 000000000..396d15afe --- /dev/null +++ b/tools/pubspec.yaml @@ -0,0 +1,14 @@ +name: tools_for_dart_lang_native +description: >- + Some helper scripts for https://github.com/dart-lang/native. +version: 0.1.0 +repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_builder + +publish_to: none + +environment: + sdk: '>=3.0.0 <4.0.0' + +dependencies: + glob: ^2.1.2 + yaml_edit: ^2.1.1