Merge pull request #13 from sass/cli-pkg

Make better use of cli_pkg
This commit is contained in:
Natalie Weizenbaum 2020-07-22 14:42:35 -07:00 committed by GitHub
commit 04edb5e81c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 65 additions and 102 deletions

View File

@ -26,18 +26,13 @@ before_script:
- pub run grinder protobuf
# Format the generated code or else the formatter task will get upset.
- dartfmt -w --fix lib/src/embedded_sass.pb*
# TODO(nweiz): always compile native when we're running on Dart 2.7.
- if [[ "$TRAVIS_OS_NAME" = windows ]]; then
pub run grinder pkg-compile-snapshot;
else
pub run grinder pkg-compile-native;
fi
- pub run grinder pkg-standalone-dev
jobs:
include:
# Testing
## Testing
- dart: stable
dart_task: test
# TODO(nweiz): Enable this when dart-lang/pub#2545 is fixed.
@ -53,3 +48,61 @@ jobs:
# Static checks
- dart_task: {dartanalyzer: --fatal-warnings ./}
- dart_task: dartfmt
## Deploying
# Deploy Linux releases to GitHub. Mac OS and Windows releases are deployed in
# a later stage so that we can build native snapshots on bots with the same
# operating system.
- stage: deploy 1
name: "GitHub: Linux"
if: &deploy-if
(type IN (push, api)) AND (repo = sass/dart-sass-embedded) AND tag =~ ^\d+\.\d+\.\d+([+-].*)?$
env: &github-env
- GITHUB_USER=sassbot
# GITHUB_TOKEN="..."
#
# Note that this overrides the read-only auth token that's set for all
# builds.
- secure: "l3q6m5Khk+E/UrzZzk2htn9YC6TuUJ3hDR6Ug28zeIf7+bV3/BbjgsOMP556H9p9q+9E3N4mKMeTApdaU5y1TjJZYLaYJETqHiYZDXJ0f1/2IzPOh+5OIqVF3pFhdc6GvmDG/d6b4bBCh9njvKIvWS51ej9VuizRfQI3BMRuApgmjBVkV2MM13HEhQ3dbe5856Gf00LvP6UF9o+bnIRo/udhmpYGQsEHLdrq2JgawiRylyLzW+hIfhS7wJm/JS32wV8sLJo70NCD5W74ZPmDv0zOKkX2VFbFv7y2qBmgUX8f8d8KqNVOzYEu8UTd3kIQASdOenZfg76S74EjW7o7QbLfJB8h0/BVMEhA/yaVuye2vu76ihGELAunSNvx7zlU16Z4TT7z+YSwCni7jvzWJajTiLoQXygHxJLEEjbBN/qF6gyre07g+zbBTXPIBvwm8lMqtyekbbq7sosL7/ctU4sX7qbuYaxhRvMhaZtkzS2clZajp2SFagTZvitbMNT5HE9YJTrNMgoEP7aiELAfmc02xUzNfaZ15x9G3n3RisTmkrwdLD6We2L0aPa+2LiyiBNbxH3QqyfcIMyXbDnymuphkYXq+fL3W7x0G9ZmtjWBB9tUcNe2VlD5hBhPShYbDwZKbKn9EgXHOnmZ/04ARyJbnQGUYKlZR5U2HGon7HU="
script: skip # Don't run tests
deploy:
provider: script
script: pub run grinder pkg-github-release pkg-github-linux
skip_cleanup: true # Don't clean up the Dart SDK.
# This causes the deploy to only be build when a tag is pushed. This
# is because the `tag` attribute in `if:` statements has a different
# understanding of the "current tag" than this, which uses the
# `TRAVIS_TAG` environment variable. `if:` statements check whether a
# tag exists that refers to the current commit, whereas `TRAVIS_TAG`
# checks whether the current build was caused by a tag.
#
# We check `if:` because it avoids unnecessary build steps, and
# `on: {tags: true}` ensures that we only deploy on the build caused
# by pushing a tag, not the build caused by pushing master.
on: {tags: true}
# Deploy to Bazel. This is in a separate deploy stage because it needs to
# install the npm package.
- stage: deploy 2
name: "GitHub: Mac OS"
if: *deploy-if
env: *github-env
script: skip
os: osx
deploy:
provider: script
script: pub run grinder pkg-github-macos
skip_cleanup: true
on: {tags: true}
- name: "GitHub: Windows"
if: *deploy-if
env: *github-env
script: skip
deploy:
provider: script
script: pub run grinder pkg-github-windows
skip_cleanup: true
on: {tags: true}

View File

@ -1,5 +1,5 @@
name: sass_embedded
version: 1.0.0-beta.1
version: 1.0.0-beta.2
description: An implementation of the Sass embedded protocol using Dart Sass.
author: Sass Team
homepage: https://github.com/sass/dart-sass-embedded

View File

@ -7,15 +7,12 @@ import 'dart:convert';
import 'dart:io';
import 'package:async/async.dart';
import 'package:grinder/grinder.dart';
import 'package:path/path.dart' as p;
import 'package:cli_pkg/testing.dart' as pkg;
import 'package:test/test.dart';
import 'package:sass_embedded/src/embedded_sass.pb.dart';
import 'package:sass_embedded/src/util/length_delimited_transformer.dart';
import 'utils.dart';
/// A wrapper for [Process] that provides a convenient API for testing the
/// embedded Sass process.
///
@ -81,12 +78,9 @@ class EmbeddedProcess {
bool includeParentEnvironment = true,
bool runInShell = false,
bool forwardOutput = false}) async {
var scriptOrSnapshot = executablePath;
var process = await Process.start(
executablePath.endsWith(".native")
? p.join(sdkDir.path, "bin", "dartaotruntime")
: Platform.executable,
[scriptOrSnapshot],
pkg.executableRunner("dart-sass-embedded"),
pkg.executableArgs("dart-sass-embedded"),
workingDirectory: workingDirectory,
environment: environment,
includeParentEnvironment: includeParentEnvironment,

View File

@ -16,8 +16,6 @@ final _null = Value()..singleton = Value_Singleton.NULL;
EmbeddedProcess _process;
void main() {
ensureExecutableUpToDate();
setUp(() async {
_process = await EmbeddedProcess.start();
});

View File

@ -12,8 +12,6 @@ import 'embedded_process.dart';
import 'utils.dart';
void main() {
ensureExecutableUpToDate();
EmbeddedProcess process;
setUp(() async {
process = await EmbeddedProcess.start();

View File

@ -13,8 +13,6 @@ import 'embedded_process.dart';
import 'utils.dart';
void main() {
ensureExecutableUpToDate();
EmbeddedProcess process;
setUp(() async {
process = await EmbeddedProcess.start();

View File

@ -2,8 +2,6 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import 'dart:io';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
@ -11,82 +9,6 @@ import 'package:sass_embedded/src/embedded_sass.pb.dart';
import 'embedded_process.dart';
/// Whether [ensureExecutableUpToDate] has been called.
var _ensuredExecutableUpToDate = false;
/// Returns the path to the executable to execute.
///
/// This may be a raw Dart executable, a script snapshot that ends in
/// `.snapshot`, or a native-code snapshot that ends in `.native`.
final String executablePath = () {
expect(_ensuredExecutableUpToDate, isTrue,
reason:
"ensureExecutableUpToDate() must be called at top of the test file.");
var nativeSnapshot = "build/dart_sass_embedded.dart.native";
if (File(nativeSnapshot).existsSync()) return nativeSnapshot;
var bytecodeSnapshot = "build/dart_sass_embedded.dart.snapshot";
if (File(bytecodeSnapshot).existsSync()) return bytecodeSnapshot;
return "bin/dart_sass_embedded.dart";
}();
/// Creates a [setUpAll] that verifies that the compiled form of the migrator
/// executable is up-to-date, if necessary.
///
/// This should always be called before [runMigrator].
void ensureExecutableUpToDate() {
setUpAll(() {
_ensuredExecutableUpToDate = true;
if (!executablePath.endsWith(".dart")) {
_ensureUpToDate(
executablePath,
"pub run grinder protobuf "
"pkg-compile-${Platform.isWindows ? 'snapshot' : 'native'}");
}
});
}
/// Ensures that [path] (usually a compilation artifact) has been modified more
/// recently than all this package's source files.
///
/// If [path] isn't up-to-date, this throws an error encouraging the user to run
/// [commandToRun].
void _ensureUpToDate(String path, String commandToRun) {
// Ensure path is relative so the error messages are more readable.
path = p.relative(path);
if (!File(path).existsSync()) {
throw "$path does not exist. Run $commandToRun.";
}
var lastModified = File(path).lastModifiedSync();
var entriesToCheck = Directory("lib").listSync(recursive: true).toList();
// If we have a dependency override, "pub run" will touch the lockfile to mark
// it as newer than the pubspec, which makes it unsuitable to use for
// freshness checking.
if (File("pubspec.yaml")
.readAsStringSync()
.contains("dependency_overrides")) {
entriesToCheck.add(File("pubspec.yaml"));
} else {
entriesToCheck.add(File("pubspec.lock"));
}
for (var entry in entriesToCheck) {
if (entry is File) {
var entryLastModified = entry.lastModifiedSync();
if (lastModified.isBefore(entryLastModified)) {
throw "${entry.path} was modified after ${p.prettyUri(p.toUri(path))} "
"was generated.\n"
"Run $commandToRun.";
}
}
}
}
/// Returns a [InboundMessage] that compiles the given plain CSS
/// string.
InboundMessage compileString(String css,