|
| 1 | +// Copyright 2019 Google Inc. Use of this source code is governed by an |
| 2 | +// MIT-style license that can be found in the LICENSE file or at |
| 3 | +// https://opensource.org/licenses/MIT. |
| 4 | + |
| 5 | +import 'dart:io'; |
| 6 | +import 'dart:convert'; |
| 7 | + |
| 8 | +import 'package:crypto/crypto.dart'; |
| 9 | +import 'package:grinder/grinder.dart'; |
| 10 | +import 'package:path/path.dart' as p; |
| 11 | + |
| 12 | +import 'utils.dart'; |
| 13 | + |
| 14 | +/// A regular expression for locating the URL and SHA256 hash of the Sass |
| 15 | +/// archive in the `homebrew-sass` formula. |
| 16 | +final _homebrewRegExp = RegExp(r'\n( *)url "[^"]+"' |
| 17 | + r'\n *sha256 "[^"]+"'); |
| 18 | + |
| 19 | +@Task('Update the Homebrew formula for the current version.') |
| 20 | +updateHomebrew() async { |
| 21 | + ensureBuild(); |
| 22 | + |
| 23 | + var process = await Process.start("git", |
| 24 | + ["archive", "--prefix=migrator-$version/", "--format=tar.gz", version]); |
| 25 | + var digest = await sha256.bind(process.stdout).first; |
| 26 | + var stderr = await utf8.decodeStream(process.stderr); |
| 27 | + if ((await process.exitCode) != 0) { |
| 28 | + fail('git archive "$version" failed:\n$stderr'); |
| 29 | + } |
| 30 | + |
| 31 | + var repo = await cloneOrPull("https://github.com/sass/homebrew-sass.git"); |
| 32 | + |
| 33 | + var formula = File(p.join(repo, "migrator.rb")); |
| 34 | + log("updating ${formula.path}"); |
| 35 | + formula.writeAsStringSync(formula.readAsStringSync().replaceFirstMapped( |
| 36 | + _homebrewRegExp, |
| 37 | + (match) => '\n${match[1]}url ' |
| 38 | + '"https://github.com/sass/migrator/archive/$version.tar.gz"' |
| 39 | + '\n${match[1]}sha256 "$digest"')); |
| 40 | + |
| 41 | + run("git", |
| 42 | + arguments: [ |
| 43 | + "commit", |
| 44 | + "--all", |
| 45 | + "--message", |
| 46 | + "Update the Sass migrator to $version" |
| 47 | + ], |
| 48 | + workingDirectory: repo, |
| 49 | + runOptions: sassBotEnvironment); |
| 50 | + |
| 51 | + var username = environment('GITHUB_USER'); |
| 52 | + var password = environment('GITHUB_AUTH'); |
| 53 | + await runAsync("git", |
| 54 | + arguments: [ |
| 55 | + "push", |
| 56 | + "https://$username:$password@github.com/sass/homebrew-sass.git", |
| 57 | + "HEAD:master" |
| 58 | + ], |
| 59 | + workingDirectory: repo); |
| 60 | +} |
0 commit comments