Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Nov 15, 2024
1 parent 7001128 commit 69b9fd7
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 29 deletions.
4 changes: 0 additions & 4 deletions .github/repos.json

This file was deleted.

2 changes: 2 additions & 0 deletions .github/repos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://github.com/mosuem/my_app_old_web
https://github.com/mosuem/my_app_new_web
42 changes: 17 additions & 25 deletions .github/workflows/ecosystem_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
pull_request:
workflow_dispatch:
inputs:
repos_json:
repos_file:
description: 'Path to the file containing the list of repository names'
required: true
default: '.github/repos.json'
default: '.github/repos.txt'
package_name:
description: 'Name of the package to update'
default: 'intl' ##DO-NOT-SUBMIT
Expand All @@ -18,41 +18,33 @@ on:
default: 0.20.0
# required: true
level:
description: 'What to check, resolve, analyze, or test'
description: 'What to check, solve, analyze, or test'

jobs:
update_and_test:
runs-on: ubuntu-latest
strategy:
matrix:
repo: ${{ fromJson(github.event.inputs.repos_json) }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
repository: ${{ matrix.repo }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Update package version in pubspec.yaml
- name: Read repository list
id: repos
run: |
sed -i 's/\(${package_name}:\s*\)\(.*\)/\1${{ github.event.inputs.new_version }}/' pubspec.yaml
- name: Get Flutter SDK Version
run: |
echo "flutter_version=$(grep 'sdk:\s*flutter' pubspec.yaml | awk '{print $2}')" >> $GITHUB_OUTPUT
echo "${{ github.event.inputs.repos_file }}" >> $REPOSITORIES_FILE
- name: Setup Dart
uses: dart-lang/setup-dart@v1
uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
with:
sdk: ${{ steps.get-flutter-version.outputs.flutter_version }}

- name: Install dependencies
run: flutter pub get
sdk: dev

- name: Run tests
if: ${{ github.event.inputs.level == 'analyze' || github.event.inputs.level == 'test' }}
run: flutter analyze
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
channel: main

- name: Run tests
if: ${{ github.event.inputs.level == 'test' }}
run: flutter test
- name: Update package and test
run: |
dart run pkgs/quest/bin/quest.dart ${{ github.event.inputs.package_name }} ${{ github.event.inputs.new_version }} ${{ github.event.inputs.level }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions pkgs/quest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
3 changes: 3 additions & 0 deletions pkgs/quest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial version.
2 changes: 2 additions & 0 deletions pkgs/quest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A sample command-line application with an entrypoint in `bin/`, library code
in `lib/`, and example unit test in `test/`.
5 changes: 5 additions & 0 deletions pkgs/quest/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: package:dart_flutter_team_lints/analysis_options.yaml

linter:
rules:
- prefer_final_locals
143 changes: 143 additions & 0 deletions pkgs/quest/bin/quest.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import 'dart:convert';
import 'dart:io';

Future<void> main(List<String> arguments) async {
final candidatePackage = arguments.first;
final version = arguments[1];
final level = Level.values.firstWhere((l) => l.name == arguments[2]);
final chronicles = await Quest(candidatePackage, version, level).embark();
print(chronicles);
}

enum Level { solve, analyze, test }

class Chronicles {
final String package;
final String version;
final Level level;
final List<Chapter> chapters;

Chronicles(this.package, this.version, this.level, this.chapters);

@override
String toString() {
return '''
Chronicles(package: $package, version: $version, level: $level, chapters: $chapters)''';
}
}

class Chapter {
final String packageName;
final String packageUri;
final Map<Level, bool> successBefore;
final Map<Level, bool> successAfter;

Chapter(
this.packageName,
this.packageUri,
this.successBefore,
this.successAfter,
);

@override
String toString() {
return '''
Chapter(packageName: $packageName, packageUri: $packageUri, successBefore: $successBefore, successAfter: $successAfter)''';
}
}

class Quest {
final String candidatePackage;
final String version;
final Level level;

Quest(this.candidatePackage, this.version, this.level);

Future<Chronicles> embark() async {
final chapters = <Chapter>[];
for (var repository in await getRepositories()) {
final applicationName = await cloneRepo(repository);
print('Cloned $repository');
final processResult = await Process.run('flutter', [
'pub',
'deps',
'--json',
], workingDirectory: applicationName);
final depsListResult = processResult.stdout as String;
final depsJson = jsonDecode(depsListResult) as Map<String, dynamic>;
final depsPackages = depsJson['packages'] as List;
print(depsPackages);
if (depsPackages.any((p) => (p as Map)['name'] == candidatePackage)) {
print('Run checks for vanilla package');
final successBefore = await runChecks(applicationName, level);

print('Clean repo');
await runFlutter(['clean'], applicationName);

print('Rev package:$candidatePackage to version $version $repository');
final revSuccess = await runFlutter([
'pub',
'add',
"$candidatePackage:'$version'",
], applicationName);

print('Run checks for modified package');
final successAfter = await runChecks(applicationName, level);
successAfter.update(
Level.solve,
(value) => value ? revSuccess : value,
ifAbsent: () => revSuccess,
);
chapters.add(
Chapter(applicationName, repository, successBefore, successAfter),
);
} else {
print('No package:$candidatePackage found in $repository');
}
}
return Chronicles(candidatePackage, version, level, chapters);
}

Future<Iterable<String>> getRepositories() async =>
await File(
const String.fromEnvironment('REPOSITORIES_FILE'),
).readAsLines();

Future<String> cloneRepo(String repository) async {
var applicationName = repository.split('/').last;
if (Directory(applicationName).existsSync()) {
applicationName = '${applicationName}_${repository.hashCode}';
}
await Process.run('gh', [
'repo',
'clone',
repository,
'--',
applicationName,
]);
return applicationName;
}

Future<Map<Level, bool>> runChecks(String currentPackage, Level level) async {
final success = <Level, bool>{};
success[Level.solve] = await runFlutter(['pub', 'get'], currentPackage);
if (level.index >= Level.analyze.index) {
success[Level.analyze] = await runFlutter(['analyze'], currentPackage);
}
if (level.index >= Level.test.index) {
success[Level.test] = await runFlutter(['test'], currentPackage);
}
return success;
}

Future<bool> runFlutter(List<String> arguments, String currentPackage) async {
final processResult = await Process.run(
'flutter',
arguments,
workingDirectory: currentPackage,
);
print('${processResult.stdout}');
print('${processResult.stderr}');
return processResult.exitCode == 0;
}
}
14 changes: 14 additions & 0 deletions pkgs/quest/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: quest
description: A sample command-line application.
version: 1.0.0
# repository: https://github.com/my_org/my_repo

environment:
sdk: ^3.7.0-129.0.dev

# Add regular dependencies here.
dependencies:

dev_dependencies:
dart_flutter_team_lints: ^3.0.0
test: ^1.24.0
33 changes: 33 additions & 0 deletions pkgs/quest/test/quest_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:test/test.dart';

import '../bin/quest.dart';

void main() {
test('test name', () async {
final chronicles =
await FakeQuest('intl', '^0.20.0', Level.analyze).embark();
print(chronicles);
}, timeout: const Timeout(Duration(minutes: 5)));
}

class FakeQuest extends Quest {
final locations = {
'https://github.com/mosuem/my_app_old_web':
'/home/mosum/projects/ecosystem_testing/my_app_old_web/',
'https://github.com/mosuem/my_app_new_web':
'/home/mosum/projects/ecosystem_testing/my_app_new_web/',
};

FakeQuest(super.candidatePackage, super.version, super.level);

@override
Future<String> cloneRepo(String repository) async {
return locations[repository]!;
}

@override
Future<Iterable<String>> getRepositories() async => <String>[
'https://github.com/mosuem/my_app_old_web',
'https://github.com/mosuem/my_app_new_web',
];
}

0 comments on commit 69b9fd7

Please sign in to comment.