From 2cab33e2b38771b9e83b5463aff7e73fa190fea6 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Thu, 15 Feb 2024 15:09:00 -0800 Subject: [PATCH] Update the language revision in Homebrew on release (#2171) --- tool/grind.dart | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tool/grind.dart b/tool/grind.dart index 92f919deb..fd6792926 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,30 @@ 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); +}