mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 06:40:47 +00:00
Increment beta version (#3470)
This commit is contained in:
parent
123544deb7
commit
8271760498
100
xtask/src/lib.rs
100
xtask/src/lib.rs
@ -3,10 +3,11 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Context, Result, anyhow};
|
use anyhow::{Context, Result, anyhow, bail};
|
||||||
use cargo::CargoAction;
|
use cargo::CargoAction;
|
||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
use esp_metadata::{Chip, Config};
|
use esp_metadata::{Chip, Config};
|
||||||
|
use semver::Prerelease;
|
||||||
use strum::{Display, EnumIter, IntoEnumIterator as _};
|
use strum::{Display, EnumIter, IntoEnumIterator as _};
|
||||||
|
|
||||||
use crate::{cargo::CargoArgsBuilder, firmware::Metadata};
|
use crate::{cargo::CargoArgsBuilder, firmware::Metadata};
|
||||||
@ -325,8 +326,60 @@ pub fn execute_app(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn do_version_bump(
|
||||||
|
version: &str,
|
||||||
|
package: Package,
|
||||||
|
amount: Version,
|
||||||
|
pre: Option<&str>,
|
||||||
|
) -> Result<semver::Version> {
|
||||||
|
fn bump_version_number(version: &mut semver::Version, amount: Version) {
|
||||||
|
match amount {
|
||||||
|
Version::Major => {
|
||||||
|
version.major += 1;
|
||||||
|
version.minor = 0;
|
||||||
|
version.patch = 0;
|
||||||
|
}
|
||||||
|
Version::Minor => {
|
||||||
|
version.minor += 1;
|
||||||
|
version.patch = 0;
|
||||||
|
}
|
||||||
|
Version::Patch => {
|
||||||
|
version.patch += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut version = semver::Version::parse(version)?;
|
||||||
|
|
||||||
|
if let Some(pre) = pre {
|
||||||
|
if let Some(pre_version) = version.pre.as_str().strip_prefix(&format!("{pre}.")) {
|
||||||
|
let pre_version = pre_version.parse::<u32>()?;
|
||||||
|
version.pre = Prerelease::new(&format!("{pre}.{}", pre_version + 1)).unwrap();
|
||||||
|
} else if version.pre.as_str().is_empty() {
|
||||||
|
// Start a new pre-release
|
||||||
|
bump_version_number(&mut version, amount);
|
||||||
|
version.pre = Prerelease::new(&format!("{pre}.0")).unwrap();
|
||||||
|
} else {
|
||||||
|
bail!(
|
||||||
|
"Unexpected pre-release version format found for {package}: {}",
|
||||||
|
version.pre.as_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if !version.pre.is_empty() {
|
||||||
|
version.pre = Prerelease::EMPTY;
|
||||||
|
} else {
|
||||||
|
bump_version_number(&mut version, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(version)
|
||||||
|
}
|
||||||
|
|
||||||
/// Bump the version of the specified package by the specified amount.
|
/// Bump the version of the specified package by the specified amount.
|
||||||
pub fn bump_version(workspace: &Path, package: Package, amount: Version) -> Result<()> {
|
pub fn bump_version(
|
||||||
|
workspace: &Path,
|
||||||
|
package: Package,
|
||||||
|
amount: Version,
|
||||||
|
pre: Option<&str>,
|
||||||
|
) -> Result<()> {
|
||||||
let manifest_path = workspace.join(package.to_string()).join("Cargo.toml");
|
let manifest_path = workspace.join(package.to_string()).join("Cargo.toml");
|
||||||
let manifest = fs::read_to_string(&manifest_path)
|
let manifest = fs::read_to_string(&manifest_path)
|
||||||
.with_context(|| format!("Could not read {}", manifest_path.display()))?;
|
.with_context(|| format!("Could not read {}", manifest_path.display()))?;
|
||||||
@ -340,21 +393,7 @@ pub fn bump_version(workspace: &Path, package: Package, amount: Version) -> Resu
|
|||||||
.to_string();
|
.to_string();
|
||||||
let prev_version = &version;
|
let prev_version = &version;
|
||||||
|
|
||||||
let mut version = semver::Version::parse(&version)?;
|
let version = do_version_bump(&version, package, amount, pre)?;
|
||||||
match amount {
|
|
||||||
Version::Major => {
|
|
||||||
version.major += 1;
|
|
||||||
version.minor = 0;
|
|
||||||
version.patch = 0;
|
|
||||||
}
|
|
||||||
Version::Minor => {
|
|
||||||
version.minor += 1;
|
|
||||||
version.patch = 0;
|
|
||||||
}
|
|
||||||
Version::Patch => {
|
|
||||||
version.patch += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log::info!("Bumping version for package: {package} ({prev_version} -> {version})");
|
log::info!("Bumping version for package: {package} ({prev_version} -> {version})");
|
||||||
|
|
||||||
@ -454,3 +493,30 @@ pub fn package_version(workspace: &Path, package: Package) -> Result<semver::Ver
|
|||||||
pub fn windows_safe_path(path: &Path) -> PathBuf {
|
pub fn windows_safe_path(path: &Path) -> PathBuf {
|
||||||
PathBuf::from(path.to_str().unwrap().to_string().replace("\\\\?\\", ""))
|
PathBuf::from(path.to_str().unwrap().to_string().replace("\\\\?\\", ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_version_bump() {
|
||||||
|
let test_cases = vec![
|
||||||
|
("0.1.0", Version::Patch, None, "0.1.1"),
|
||||||
|
("0.1.0", Version::Minor, None, "0.2.0"),
|
||||||
|
("0.1.0", Version::Major, None, "1.0.0"),
|
||||||
|
("0.1.0", Version::Patch, Some("alpha"), "0.1.1-alpha.0"),
|
||||||
|
("0.1.0", Version::Minor, Some("alpha"), "0.2.0-alpha.0"),
|
||||||
|
("0.1.0", Version::Major, Some("alpha"), "1.0.0-alpha.0"),
|
||||||
|
// amount is ignored, assuming same release cycle
|
||||||
|
("0.1.0-beta.0", Version::Minor, None, "0.1.0"),
|
||||||
|
("0.1.0-beta.0", Version::Major, None, "0.1.0"),
|
||||||
|
("0.1.0-beta.0", Version::Minor, Some("beta"), "0.1.0-beta.1"),
|
||||||
|
("0.1.0-beta.0", Version::Major, Some("beta"), "0.1.0-beta.1"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (version, amount, pre, expected) in test_cases {
|
||||||
|
let new_version = do_version_bump(version, Package::EspHal, amount, pre).unwrap();
|
||||||
|
assert_eq!(new_version.to_string(), expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -46,8 +46,18 @@ enum Cli {
|
|||||||
#[derive(Debug, Args)]
|
#[derive(Debug, Args)]
|
||||||
struct BumpVersionArgs {
|
struct BumpVersionArgs {
|
||||||
/// How much to bump the version by.
|
/// How much to bump the version by.
|
||||||
|
///
|
||||||
|
/// If the version is a pre-release, this will just remove the pre-release
|
||||||
|
/// version tag.
|
||||||
#[arg(value_enum)]
|
#[arg(value_enum)]
|
||||||
amount: Version,
|
amount: Version,
|
||||||
|
/// Pre-release version to append to the version.
|
||||||
|
///
|
||||||
|
/// If the package is already a pre-release, this will ignore `amount`. If
|
||||||
|
/// the package is not a pre-release, this will bump the version by
|
||||||
|
/// `amount` and append the pre-release version as `<pre>.0`.
|
||||||
|
#[arg(long)]
|
||||||
|
pre: Option<String>,
|
||||||
/// Package(s) to target.
|
/// Package(s) to target.
|
||||||
#[arg(value_enum, default_values_t = Package::iter())]
|
#[arg(value_enum, default_values_t = Package::iter())]
|
||||||
packages: Vec<Package>,
|
packages: Vec<Package>,
|
||||||
@ -157,7 +167,7 @@ fn main() -> Result<()> {
|
|||||||
fn bump_version(workspace: &Path, args: BumpVersionArgs) -> Result<()> {
|
fn bump_version(workspace: &Path, args: BumpVersionArgs) -> Result<()> {
|
||||||
// Bump the version by the specified amount for each given package:
|
// Bump the version by the specified amount for each given package:
|
||||||
for package in args.packages {
|
for package in args.packages {
|
||||||
xtask::bump_version(workspace, package, args.amount)?;
|
xtask::bump_version(workspace, package, args.amount, args.pre.as_deref())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user