Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[infra] script to change deps to path dependencies #817

Merged
merged 5 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HosseinYousefi Would this be useful for package:jnigen and package:jni as well? So that jnigen is both tested against the published package:jni and against the package:jni in the repo?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we release both of the versions together, expecting users to use the latests of both, so I don't think it's necessary.

'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