Skip to content

Commit

Permalink
Normalize, sort, and validate SDK configurations
Browse files Browse the repository at this point in the history
Towards #303
  • Loading branch information
kevmoo committed Feb 11, 2021
1 parent 22d3d52 commit f90a204
Show file tree
Hide file tree
Showing 10 changed files with 347 additions and 217 deletions.
50 changes: 25 additions & 25 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,22 @@ jobs:
working-directory: mono_repo
run: dartanalyzer .
job_004:
name: "smoke_test; linux; Dart edge; PKG: test_pkg; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
name: "smoke_test; linux; Dart 2.10.4; PKG: test_pkg; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v2
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;dart:main;packages:test_pkg;commands:dartfmt-dartanalyzer_0"
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.10.4;packages:test_pkg;commands:dartfmt-dartanalyzer_0"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;dart:main;packages:test_pkg
os:ubuntu-latest;pub-cache-hosted;dart:main
os:ubuntu-latest;pub-cache-hosted;dart:2.10.4;packages:test_pkg
os:ubuntu-latest;pub-cache-hosted;dart:2.10.4
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/[email protected]
with:
sdk: main
sdk: "2.10.4"
- id: checkout
uses: actions/checkout@v2
- id: test_pkg_pub_upgrade
Expand Down Expand Up @@ -181,22 +181,22 @@ jobs:
working-directory: test_pkg
run: dartanalyzer --fatal-infos .
job_006:
name: "smoke_test; linux; Dart beta; PKG: test_pkg; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
name: "smoke_test; linux; Dart 2.12.0-29.10.beta; PKG: test_pkg; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v2
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:test_pkg;commands:dartfmt-dartanalyzer_0"
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0-29.10.beta;packages:test_pkg;commands:dartfmt-dartanalyzer_0"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:test_pkg
os:ubuntu-latest;pub-cache-hosted;dart:beta
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0-29.10.beta;packages:test_pkg
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0-29.10.beta
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/[email protected]
with:
sdk: beta
sdk: "2.12.0-29.10.beta"
- id: checkout
uses: actions/checkout@v2
- id: test_pkg_pub_upgrade
Expand All @@ -213,22 +213,22 @@ jobs:
working-directory: test_pkg
run: dartanalyzer --fatal-infos .
job_007:
name: "smoke_test; linux; Dart 2.12.0-29.10.beta; PKG: test_pkg; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
name: "smoke_test; linux; Dart beta; PKG: test_pkg; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v2
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0-29.10.beta;packages:test_pkg;commands:dartfmt-dartanalyzer_0"
key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:test_pkg;commands:dartfmt-dartanalyzer_0"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0-29.10.beta;packages:test_pkg
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0-29.10.beta
os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:test_pkg
os:ubuntu-latest;pub-cache-hosted;dart:beta
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/[email protected]
with:
sdk: "2.12.0-29.10.beta"
sdk: beta
- id: checkout
uses: actions/checkout@v2
- id: test_pkg_pub_upgrade
Expand All @@ -245,22 +245,22 @@ jobs:
working-directory: test_pkg
run: dartanalyzer --fatal-infos .
job_008:
name: "smoke_test; linux; Dart stable; PKG: test_pkg; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
name: "smoke_test; linux; Dart main; PKG: test_pkg; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v2
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:test_pkg;commands:dartfmt-dartanalyzer_0"
key: "os:ubuntu-latest;pub-cache-hosted;dart:main;packages:test_pkg;commands:dartfmt-dartanalyzer_0"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:test_pkg
os:ubuntu-latest;pub-cache-hosted;dart:stable
os:ubuntu-latest;pub-cache-hosted;dart:main;packages:test_pkg
os:ubuntu-latest;pub-cache-hosted;dart:main
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/[email protected]
with:
sdk: stable
sdk: main
- id: checkout
uses: actions/checkout@v2
- id: test_pkg_pub_upgrade
Expand All @@ -277,22 +277,22 @@ jobs:
working-directory: test_pkg
run: dartanalyzer --fatal-infos .
job_009:
name: "smoke_test; linux; Dart 2.10.4; PKG: test_pkg; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
name: "smoke_test; linux; Dart stable; PKG: test_pkg; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v2
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.10.4;packages:test_pkg;commands:dartfmt-dartanalyzer_0"
key: "os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:test_pkg;commands:dartfmt-dartanalyzer_0"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;dart:2.10.4;packages:test_pkg
os:ubuntu-latest;pub-cache-hosted;dart:2.10.4
os:ubuntu-latest;pub-cache-hosted;dart:stable;packages:test_pkg
os:ubuntu-latest;pub-cache-hosted;dart:stable
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/[email protected]
with:
sdk: "2.10.4"
sdk: stable
- id: checkout
uses: actions/checkout@v2
- id: test_pkg_pub_upgrade
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
env: PKGS="test_pkg"
script: tool/ci.sh dartfmt dartanalyzer_0
- stage: smoke_test
name: "Dart edge; PKG: test_pkg; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
name: "Dart main; PKG: test_pkg; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
dart: be/raw/latest
os: linux
env: PKGS="test_pkg"
Expand Down
2 changes: 2 additions & 0 deletions mono_repo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 3.4.7-dev

- Use the latest `dart-lang/[email protected]`.
- Normalize Dart SDK configurations. Throw on duplicate SDKs. Sort SDKs to
maintain stable output.

## 3.4.6

Expand Down
52 changes: 7 additions & 45 deletions mono_repo/lib/src/commands/github/github_yaml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:meta/meta.dart';
import 'package:pub_semver/pub_semver.dart';

import '../../ci_shared.dart';
import '../../github_config.dart';
Expand Down Expand Up @@ -278,7 +277,7 @@ extension on CIJobEntry {
includeStage: true,
),
_githubJobOs,
job.githubSdk,
job.sdk,
commandEntries,
additionalCacheKeys: {
'packages': packages.join('-'),
Expand All @@ -299,48 +298,6 @@ extension on CIJobEntry {
}
}

Map<String, dynamic> _createDartSetup(String sdk) {
Version realVersion;

try {
realVersion = Version.parse(sdk);
} on FormatException {
// noop
}

@alwaysThrows
void unsupported() => throw UserException(
'Unsupported Dart SDK configuration: `$sdk`.',
details: "We are currently limited by what's supported by "
'https://github.com/marketplace/actions/setup-dart-action',
);

Map<String, String> withMap;
if (realVersion != null) {
withMap = {
'sdk': sdk,
};
} else if (const {
'beta',
'dev',
'stable',
CIJob.githubSetupMainSdk,
}.contains(sdk)) {
withMap = {
'sdk': sdk,
};
} else {
unsupported();
}

final map = {
'uses': 'dart-lang/[email protected]',
'with': withMap,
};

return map;
}

/// Returns the content of a Github Action Job.
///
/// See https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobs
Expand Down Expand Up @@ -377,7 +334,12 @@ Map<String, dynamic> _githubJobYaml(
if (additionalCacheKeys != null) ...additionalCacheKeys,
},
),
_createDartSetup(dartVersion),
{
'uses': 'dart-lang/[email protected]',
'with': {
'sdk': dartVersion,
},
},
{
'id': 'checkout',
'uses': 'actions/checkout@v2',
Expand Down
47 changes: 21 additions & 26 deletions mono_repo/lib/src/package_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:yaml/yaml.dart';

import 'raw_config.dart';
import 'utilities.dart';
import 'yaml.dart';

part 'package_config.g.dart';
Expand Down Expand Up @@ -38,7 +39,11 @@ class PackageConfig {
this.cacheDirectories,
this.dartSdkConfigUsed,
this.osConfigUsed,
);
) : assert(() {
if (sdks == null) return true;
sortNormalizeVerifySdksList(sdks, (m) => AssertionError(m));
return true;
}());

factory PackageConfig.parse(
String relativePath,
Expand Down Expand Up @@ -83,11 +88,15 @@ class PackageConfig {
var jobSdks = rawConfig.sdks;
if (job is Map && job.containsKey('dart')) {
final jobValue = job['dart'];
if (jobValue is List) {
jobSdks = jobValue.cast<String>();
} else {
jobSdks = [jobValue as String];
}

jobSdks = (jobValue is List)
? jobSdks = [...jobValue.cast<String>()]
: [jobValue as String];

sortNormalizeVerifySdksList(
jobSdks,
(m) => CheckedFromJsonException(job, 'dart', 'RawConfig', m),
);
} else if (jobSdks == null || jobSdks.isEmpty) {
if (monoPkgYaml.containsKey('dart')) {
throw CheckedFromJsonException(
Expand Down Expand Up @@ -164,11 +173,6 @@ abstract class HasStageName {

@JsonSerializable(explicitToJson: true)
class CIJob implements HasStageName {
static const _edgeSdk = 'edge';
static const _travisEdgeSdk = 'be/raw/latest';
static const githubSetupMainSdk = 'main';
static const _supportedSdkLiterals = {_edgeSdk, 'dev', 'beta', 'stable'};

@JsonKey(includeIfNull: false)
final String description;

Expand All @@ -192,9 +196,7 @@ class CIJob implements HasStageName {
String get name => description ?? _taskCommandsTickQuoted.join(', ');

/// Same as [sdk] except it handles Travis-specific naming for the edge SDK.
String get travisSdk => sdk == _edgeSdk ? _travisEdgeSdk : sdk;

String get githubSdk => sdk == _edgeSdk ? githubSetupMainSdk : sdk;
String get travisSdk => sdk == githubSetupMainSdk ? travisEdgeSdk : sdk;

CIJob(
this.os,
Expand All @@ -203,17 +205,10 @@ class CIJob implements HasStageName {
this.stageName,
this.tasks, {
this.description,
}) {
if (explicitSdkVersion == null && !_supportedSdkLiterals.contains(sdk)) {
final literalsPretty =
_supportedSdkLiterals.map((e) => '"$e"').join(', ');
throw ArgumentError.value(
sdk,
'sdk',
'If `sdk` is not a version string, it must be one of $literalsPretty.',
);
}
}
}) : assert(
errorForSdkConfig(sdk) == null,
'Should have caught bad sdk value `$sdk` before here!',
);

factory CIJob.fromJson(Map<String, dynamic> json) => _$CIJobFromJson(json);

Expand All @@ -236,7 +231,7 @@ class CIJob implements HasStageName {
return CIJob(
os,
package,
{_travisEdgeSdk, githubSetupMainSdk}.contains(sdk) ? _edgeSdk : sdk,
sdk,
stageName,
tasks,
description: description,
Expand Down
12 changes: 11 additions & 1 deletion mono_repo/lib/src/raw_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import 'package:json_annotation/json_annotation.dart';

import 'utilities.dart';

part 'raw_config.g.dart';

@JsonSerializable(createToJson: false, disallowUnrecognizedKeys: true)
Expand All @@ -22,7 +24,15 @@ class RawConfig {
: stages = stages ??
[
RawStage('unit_test', ['test'])
];
] {
if (sdks != null) {
sortNormalizeVerifySdksList(
sdks,
(m) => ArgumentError.value(sdks, 'sdks', m),
);
}
if (oses != null) oses.sort();
}

factory RawConfig.fromJson(Map json) {
final config = _$RawConfigFromJson(json);
Expand Down
Loading

0 comments on commit f90a204

Please sign in to comment.