Skip to content

Commit

Permalink
[infra] script to change deps to path dependencies (#817)
Browse files Browse the repository at this point in the history
This PR adds a script that rewrites pubspecs to use path dependencies between the `native_*` packages in this repo.

This might be too strict if we ever need to breaking changes across multiple packages, in that case we can temporarily disable this.

Closes: #80
  • Loading branch information
dcharkes authored Nov 21, 2023
1 parent 893433e commit 6c6a3d6
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 3 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/native.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ on:
- "pkgs/native_assets_builder/**"
- "pkgs/native_assets_cli/**"
- "pkgs/native_toolchain_c/**"
- "tools/**"
push:
branches: [main]
paths:
- ".github/workflows/native.yaml"
- "pkgs/native_assets_builder/**"
- "pkgs/native_assets_cli/**"
- "pkgs/native_toolchain_c/**"
- "tools/**"
schedule:
- cron: "0 0 * * 0" # weekly

Expand All @@ -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:
Expand All @@ -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

Expand All @@ -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/
Expand Down Expand Up @@ -114,19 +126,19 @@ 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
with:
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]
Expand Down
9 changes: 9 additions & 0 deletions tools/.gitignore
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions tools/bin/change_dependencies.dart
Original file line number Diff line number Diff line change
@@ -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<String> args) {
final root = Platform.script.resolve('../../');
final glob = Glob('**pubspec.yaml');
final files = glob.listSync(root: root.toFilePath()).whereType<File>();
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',
};
14 changes: 14 additions & 0 deletions tools/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6c6a3d6

Please sign in to comment.