unicode

Branch: main

Switch branches or tags

Branch: main
Go to file t

413 files indexed

History
Code

tools/release/release.mbt
1///|2const ReleaseVersionPattern : Regex = re"^(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)$"34///|5#derive(Debug, Eq)6suberror ReleaseError {7  ReleaseError(String)8}910///|11priv struct ReleaseModule {12  name : String13  directory : String14  requires_published_dependencies : Bool15}1617///|18// TODO: Derive this topological order from workspace manifests and reject dependency cycles.19let published_modules : Array[ReleaseModule] = [20  {21    name: "unicode-data",22    directory: "ucd",23    requires_published_dependencies: false,24  },25  {26    name: "punycode",27    directory: "punycode",28    requires_published_dependencies: false,29  },30  {31    name: "unicode-bidi",32    directory: "bidi",33    requires_published_dependencies: false,34  },35  {36    name: "unicode-segmentation",37    directory: "segmentation",38    requires_published_dependencies: true,39  },40  {41    name: "unicode-normalization",42    directory: "normalization",43    requires_published_dependencies: true,44  },45  {46    name: "unicode-casefold",47    directory: "casefold",48    requires_published_dependencies: true,49  },50  {51    name: "unicode-idna",52    directory: "idna",53    requires_published_dependencies: true,54  },55  {56    name: "unicode",57    directory: "unicode",58    requires_published_dependencies: true,59  },60]6162///|63fn ReleaseModule::manifest_path(self : ReleaseModule) -> String {64  "\{self.directory}/moon.mod"65}6667///|68fn validate_release_version(version : String) -> Unit raise ReleaseError {69  guard version =~ ReleaseVersionPattern else {70    raise ReleaseError(71      "Invalid release version '\{version}'; expected MAJOR.MINOR.PATCH without a prerelease suffix",72    )73  }74}7576///|77fn publish_dry_run_succeeded(78  status : Int32,79  output : StringView,80  package_name : StringView,81  version : StringView,82) -> Bool {83  if status == 0 {84    true85  } else {86    // `moon publish --dry-run` currently exits -1 after a successful 202;87    // process APIs expose that as 255 on Unix and -1 on Windows.88    let known_false_failure = status == 255 || status == -189    let accepted = "Server status: 202 Accepted, detail: Dry run completed successfully. No changes were made. The dry-run was made for package \{package_name} version \{version}."90    // The captured stdout and stderr are concatenated rather than91    // interleaved, so match the reported failure anywhere instead of relying92    // on it being the last line the process printed.93    known_false_failure &&94    output.contains(accepted) &&95    output.contains("Error: `moon publish` failed")96  }97}9899///|100fn release_version_from_manifests(101  versions : ArrayView[(String, String)],102) -> String raise ReleaseError {103  let mut root_version : String? = None104  for manifest in versions {105    let (path, version) = manifest106    if path == "unicode/moon.mod" {107      guard root_version is None else {108        raise ReleaseError(109          "Published manifests contain more than one umbrella manifest (unicode/moon.mod)",110        )111      }112      root_version = Some(version)113    }114  }115  guard root_version is Some(expected_version) else {116    raise ReleaseError(117      "Published manifests do not contain the umbrella manifest unicode/moon.mod",118    )119  }120  validate_release_version(expected_version)121  for manifest in versions {122    let (path, actual_version) = manifest123    guard actual_version == expected_version else {124      raise ReleaseError(125        "Published module versions are inconsistent: \{path} has \{actual_version}, expected \{expected_version} from unicode/moon.mod",126      )127    }128  }129  expected_version130}131132///|133fn manifest_version_and_line(134  source : String,135  path : String,136) -> (String, String) raise ReleaseError {137  let mut found : (String, String)? = None138  for line in source.split("\n") {139    let manifest_line = line.trim_end(chars="\r")140    if manifest_line.split_once("version = \"") is Some(("", rest)) &&141      rest.rev_split_once("\"") is Some((version, "")) {142      if found is Some(_) {143        raise ReleaseError(144          "\{path} contains more than one top-level version declaration",145        )146      }147      found = Some((manifest_line.to_owned(), version.to_owned()))148    }149  }150  guard found is Some(result) else {151    raise ReleaseError(152      "\{path} does not contain a top-level version = \"...\" declaration",153    )154  }155  result156}157158///|159fn manifest_version(160  source : String,161  path : String,162) -> String raise ReleaseError {163  let (_, version) = manifest_version_and_line(source, path)164  version165}166167///|168fn replace_manifest_version(169  source : String,170  path : String,171  version : String,172) -> String raise ReleaseError {173  let (line, _) = manifest_version_and_line(source, path)174  source.replace(old=line, new="version = \"\{version}\"")175}176177///|178/// The published modules whose archives can be validated against the registry179/// before any of this release is published: the ones that do not depend on180/// same-release packages. Every other module can only be dry-run once its181/// dependencies exist on the registry, which is why `publish_release` checks182/// those one at a time, immediately before publishing each of them.183fn preflight_modules() -> Array[ReleaseModule] {184  let result : Array[ReleaseModule] = []185  for release_module in published_modules {186    if !release_module.requires_published_dependencies {187      result.push(release_module)188    }189  }190  result191}192