From 0a11177ede2f052db42e9f425f3692558c849793 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Mon, 12 Feb 2024 15:54:17 -0800 Subject: [PATCH 1/2] Update the language revision in Homebrew on release --- pubspec.yaml | 2 +- tool/grind.dart | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 296270dfc..33a7c8c66 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: args: ^2.0.0 async: ^2.5.0 charcode: ^1.2.0 - cli_pkg: ^2.7.1 + cli_pkg: ^2.8.0 cli_repl: ^0.2.1 collection: ^1.16.0 http: "^1.1.0" diff --git a/tool/grind.dart b/tool/grind.dart index 92f919deb..e5705747a 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -29,6 +29,7 @@ void main(List args) { pkg.chocolateyNuspec.value = _nuspec; pkg.homebrewRepo.value = "sass/homebrew-sass"; pkg.homebrewFormula.value = "Formula/sass.rb"; + pkg.homebrewEditFormula.value = _updateHomebrewLanguageRevision; pkg.jsRequires.value = [ pkg.JSRequire("immutable", target: pkg.JSRequireTarget.all), pkg.JSRequire("chokidar", target: pkg.JSRequireTarget.cli), @@ -292,3 +293,31 @@ function defaultExportDeprecation() { File("build/npm/sass.node.mjs").writeAsStringSync(buffer.toString()); } + +/// A regular expression to locate the language repo revision in the Dart Sass +/// Homebrew formula. +final _homebrewLanguageRegExp = RegExp( + r'resource "language" do$' + r'(?:(?! end$).)+' + r'revision: "([a-f0-9]{40})"', + dotAll: true, + multiLine: true); + +/// Updates the Homebrew [formula] to change the revision of the language repo +/// to the latest revision. +String _updateHomebrewLanguageRevision(String formula) { + var languageRepoRevision = run("git", + arguments: ["ls-remote", "https://github.com/sass/sass"], + quiet: true) + .split("\t") + .first; + + var match = _homebrewLanguageRegExp.firstMatch(formula); + if (match == null) { + fail("Couldn't find a language repo revision in the Homebrew formula."); + } + + return formula.substring(0, match.start) + + match.group(0)!.replaceFirst(match.group(1)!, languageRepoRevision) + + formula.substring(match.end); +} From 3f6792e5e6102079e5782c2b28280ee6ecffd026 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Mon, 12 Feb 2024 15:58:15 -0800 Subject: [PATCH 2/2] Reformat --- tool/grind.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tool/grind.dart b/tool/grind.dart index e5705747a..fd6792926 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -307,8 +307,7 @@ final _homebrewLanguageRegExp = RegExp( /// to the latest revision. String _updateHomebrewLanguageRevision(String formula) { var languageRepoRevision = run("git", - arguments: ["ls-remote", "https://github.com/sass/sass"], - quiet: true) + arguments: ["ls-remote", "https://github.com/sass/sass"], quiet: true) .split("\t") .first;