From b9db8ab0dfeb680be5ba7b88a09f9c97ac11bcc5 Mon Sep 17 00:00:00 2001 From: Jonas Termansen Date: Wed, 21 Feb 2024 15:56:41 +0100 Subject: [PATCH] Fix beta version field becoming stuck when stable is promoted to beta. Loosen the regular expression to match any versions and uniquely tag the lines that are being search and replaced. Fixes: b/326219296 Change-Id: I91d4c9bca3359416f01a3d455f449d3c4b8811b5 Reviewed-on: https://dart-review.googlesource.com/c/homebrew-dart/+/353460 Auto-Submit: Jonas Termansen Reviewed-by: William Hesse Commit-Queue: William Hesse --- Formula/dart-beta.rb | 2 +- Formula/dart.rb | 2 +- lib/src/formula.dart | 12 +++++------- test/formula_test.dart | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Formula/dart-beta.rb b/Formula/dart-beta.rb index 78791da..bdc29d3 100644 --- a/Formula/dart-beta.rb +++ b/Formula/dart-beta.rb @@ -4,7 +4,7 @@ class DartBeta < Formula desc "Beta SDK" homepage "https://dart.dev" - version "3.1.0" + version "3.3.0" # beta conflicts_with "dart", because: "dart ships the same binaries" if OS.mac? && Hardware::CPU.intel? diff --git a/Formula/dart.rb b/Formula/dart.rb index 1a749ce..159d954 100644 --- a/Formula/dart.rb +++ b/Formula/dart.rb @@ -6,7 +6,7 @@ class Dart < Formula homepage "https://dart.dev" head do - version "3.4.0-154.0.dev" + version "3.4.0-154.0.dev" # dev if OS.mac? && Hardware::CPU.intel? url "https://storage.googleapis.com/dart-archive/channels/dev/release/3.4.0-154.0.dev/sdk/dartsdk-macos-x64-release.zip" sha256 "cc1392b79b7fa5fe210b75669558970ac250ecf72fa20bb0128e6e14ee6aa7de" diff --git a/lib/src/formula.dart b/lib/src/formula.dart index f692f80..1c31211 100644 --- a/lib/src/formula.dart +++ b/lib/src/formula.dart @@ -7,21 +7,19 @@ String updateFormula(String channel, String contents, String version, // Replace the version identifier. Formulas with stable and pre-release // versions have multiple identifiers and only the right one should be // updated. - var versionId = channel == 'stable' - ? RegExp(r'version \"\d+\.\d+.\d+\"') - : RegExp(r'version \"\d+\.\d+.\d+\-.+\"'); - contents = contents.replaceAll(versionId, 'version "$version"'); + final versionId = RegExp(r'version \"\d+\.\d+.\d+(-[^"]+)?\" # ' + channel); + contents = contents.replaceAll(versionId, 'version "$version" # $channel'); // Extract files and hashes that are stored in the formula in this format: // url "//release//sdk/.zip" // sha256 "" - var filesAndHashes = RegExp( + final filesAndHashes = RegExp( 'channels/$channel/release' r'/\d[\w\d\-\.]*/sdk/([\w\d\-\.]+)\"\n(\s+)sha256 \"[\da-f]+\"', multiLine: true); return contents.replaceAllMapped(filesAndHashes, (m) { - var artifact = m.group(1); - var indent = m.group(2); + final artifact = m.group(1); + final indent = m.group(2); return 'channels/$channel/release/$version/sdk/$artifact"\n' '${indent}sha256 "${hashes[artifact]}"'; }); diff --git a/test/formula_test.dart b/test/formula_test.dart index 26d1b67..a3d2f12 100644 --- a/test/formula_test.dart +++ b/test/formula_test.dart @@ -7,7 +7,7 @@ import 'package:update_homebrew/src/formula.dart'; const _devFormula = ''' head do - version "2.15.0-65.0.dev" + version "2.15.0-65.0.dev" # dev if OS.mac? && Hardware::CPU.intel? url "https://storage.googleapis.com/dart-archive/channels/dev/release/2.15.0-65.0.dev/sdk/dartsdk-macos-x64-release.zip" sha256 "9c71429a806dd2ac7968542771764dd5d1b7c71fd03851c6870eb5c3f687fb1b" @@ -36,7 +36,7 @@ const _devFormula = ''' const _devFormulaExpected = ''' head do - version "2.16.0-76.0.dev" + version "2.16.0-76.0.dev" # dev if OS.mac? && Hardware::CPU.intel? url "https://storage.googleapis.com/dart-archive/channels/dev/release/2.16.0-76.0.dev/sdk/dartsdk-macos-x64-release.zip" sha256 "bbb"