Skip to content

Commit 2cab33e

Browse files
authored
Update the language revision in Homebrew on release (#2171)
1 parent 84ededd commit 2cab33e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tool/grind.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void main(List<String> args) {
2929
pkg.chocolateyNuspec.value = _nuspec;
3030
pkg.homebrewRepo.value = "sass/homebrew-sass";
3131
pkg.homebrewFormula.value = "Formula/sass.rb";
32+
pkg.homebrewEditFormula.value = _updateHomebrewLanguageRevision;
3233
pkg.jsRequires.value = [
3334
pkg.JSRequire("immutable", target: pkg.JSRequireTarget.all),
3435
pkg.JSRequire("chokidar", target: pkg.JSRequireTarget.cli),
@@ -292,3 +293,30 @@ function defaultExportDeprecation() {
292293

293294
File("build/npm/sass.node.mjs").writeAsStringSync(buffer.toString());
294295
}
296+
297+
/// A regular expression to locate the language repo revision in the Dart Sass
298+
/// Homebrew formula.
299+
final _homebrewLanguageRegExp = RegExp(
300+
r'resource "language" do$'
301+
r'(?:(?! end$).)+'
302+
r'revision: "([a-f0-9]{40})"',
303+
dotAll: true,
304+
multiLine: true);
305+
306+
/// Updates the Homebrew [formula] to change the revision of the language repo
307+
/// to the latest revision.
308+
String _updateHomebrewLanguageRevision(String formula) {
309+
var languageRepoRevision = run("git",
310+
arguments: ["ls-remote", "https://github.com/sass/sass"], quiet: true)
311+
.split("\t")
312+
.first;
313+
314+
var match = _homebrewLanguageRegExp.firstMatch(formula);
315+
if (match == null) {
316+
fail("Couldn't find a language repo revision in the Homebrew formula.");
317+
}
318+
319+
return formula.substring(0, match.start) +
320+
match.group(0)!.replaceFirst(match.group(1)!, languageRepoRevision) +
321+
formula.substring(match.end);
322+
}

0 commit comments

Comments
 (0)