| 16 | } |
| 17 | |
| 18 | const parseDbVersionInner = (versionStr: string): DbVersion | null => { |
| 19 | const parsed = versionStr.match( |
| 20 | /* |
| 21 | Matches version strings like "v0.1.2 (abc123)" or "v0.1.2 (abc123, helm chart: 1.2.3)" |
| 22 | ^v - Start of string, must start with 'v' |
| 23 | (?<crateVersion> - Named capture group for the crate version |
| 24 | [^() ]*) - Any chars except parens or space, zero or more times |
| 25 | \( |
| 26 | (?<sha>[0-9a-fA-F]*) - Named capture group for the git SHA |
| 27 | (?: - Non-capturing group for optional helm chart version |
| 28 | , helm chart: - Literal text |
| 29 | (?<helmChartVersion>[^() ]*) - Named capture group for helm chart version |
| 30 | )? - End optional group |
| 31 | \)$ |
| 32 | */ |
| 33 | /^v(?<crateVersion>[^() ]*) \((?<sha>[0-9a-fA-F]*)(?:, helm chart: (?<helmChartVersion>[^() ]*))?\)$/, |
| 34 | ); |
| 35 | |
| 36 | if (parsed?.groups) { |
| 37 | const { crateVersion, sha, helmChartVersion } = parsed.groups; |
| 38 | |
| 39 | const crateVersionParsed = semverParse(crateVersion); |
| 40 | |
| 41 | const helmChartVersionParsed = helmChartVersion |
| 42 | ? semverParse(helmChartVersion) |
| 43 | : undefined; |
| 44 | |
| 45 | if (!crateVersionParsed) { |
| 46 | return null; |
| 47 | } |
| 48 | return { |
| 49 | crateVersion: crateVersionParsed, |
| 50 | sha, |
| 51 | helmChartVersion: helmChartVersionParsed ?? undefined, |
| 52 | }; |
| 53 | } |
| 54 | return null; |
| 55 | }; |
| 56 | |
| 57 | /** Parses a string returned by `mz_version()`, |
| 58 | * which is of the form "v<crate-version> (<sha>)`, |