wyre 0.2.16

wyre serialization and deserialization library
Documentation
# Define the paths to Cargo.toml files
$rootCargoTomlPath = "./Cargo.toml"
$deriveCargoTomlPath = "./derive/Cargo.toml"

# Ensure Cargo.toml exists
if (-Not (Test-Path $rootCargoTomlPath)) {
    Write-Output "❌ Cargo.toml not found at path: $rootCargoTomlPath"
    Write-Output "Please ensure the script is run from the root directory of your Rust project."
    exit 1
}

if (-Not (Test-Path $deriveCargoTomlPath)) {
    Write-Output "❌ Cargo.toml not found at path: $deriveCargoTomlPath"
    Write-Output "Please ensure the derive crate exists with a valid Cargo.toml."
    exit 1
}

# Read the Cargo.toml content into a variable
$rootCargoTomlContent = Get-Content -Path $rootCargoTomlPath -Raw
$deriveCargoTomlContent = Get-Content -Path $deriveCargoTomlPath -Raw

# Use a regular expression to find the version line
$matchedRoot = $rootCargoTomlContent -match 'version = "([^"]+)"'
$matchedDerive = $deriveCargoTomlContent -match 'version = "([^"]+)"'

if (-Not $matchedRoot) {
    Write-Output "❌ Version line not found in root Cargo.toml"
    Write-Output "Please ensure the root Cargo.toml file contains a valid version line."
    exit 1
}

if (-Not $matchedDerive) {
    Write-Output "❌ Version line not found in derive Cargo.toml"
    Write-Output "Please ensure the derive Cargo.toml file contains a valid version line."
    exit 1
}

$versionLine = $matches[1]

# Split the version into major, minor, and patch
$versionParts = $versionLine.Split('.')
$major = $versionParts[0]
$minor = $versionParts[1]
$patch = [int]$versionParts[2]

# Increment the patch version
$patch += 1

# Construct the new version string
$newVersion = "$major.$minor.$patch"

# Replace the old version with the new version in both Cargo.toml contents
$newRootCargoTomlContent = $rootCargoTomlContent -replace ('version = "' + [regex]::Escape($versionLine) + '"'), ('version = "' + $newVersion + '"')
$newDeriveCargoTomlContent = $deriveCargoTomlContent -replace ('version = "' + [regex]::Escape($versionLine) + '"'), ('version = "' + $newVersion + '"')

# Write the new Cargo.toml contents back to the files
Set-Content -Path $rootCargoTomlPath -Value $newRootCargoTomlContent
Set-Content -Path $deriveCargoTomlPath -Value $newDeriveCargoTomlContent

Write-Output "✅ Updated version to $newVersion in both Cargo.toml files"

# Update the dependency version in the root Cargo.toml
$newRootCargoTomlContent = $newRootCargoTomlContent -replace 'wyre-derive = { path = "derive", version = "[^"]+" }', ('wyre-derive = { path = "derive", version = "' + $newVersion + '" }')
Set-Content -Path $rootCargoTomlPath -Value $newRootCargoTomlContent

Write-Output "✅ Updated wyre-derive dependency version to $newVersion in root Cargo.toml"

# Get the current date
$publishDate = Get-Date -Format "yyyy-MM-dd"

# Commit messages with publish date
$commitMessage = "🚀 Bump version to $newVersion ($publishDate)"
$releaseMessage = "Release v$newVersion ($publishDate)"

# Add ALL files to git
git add .

# Commit the change with the commit message
git commit -m "$commitMessage"

# Check if the tag already exists
$tagExists = git tag --list "v$newVersion" | Measure-Object | Select-Object -ExpandProperty Count

if ($tagExists -eq 0) {
    # Tag the commit as a release with the release message
    git tag -a "v$newVersion" -m "$releaseMessage"
} else {
    Write-Output "⚠️ Tag 'v$newVersion' already exists. Skipping tag creation."
}

# Push the commit and tag to your repository
Write-Output "🎉 Pushing changes and tags to the repository..."
git push && git push --tags

# Publish the derive package to crates.io
Write-Output "📦 Publishing derive package to crates.io..."
cd derive
cargo publish --allow-dirty

if ($LASTEXITCODE -eq 0) {
    Write-Output "✨ Derive package successfully published to crates.io!"
    cd ..
    # Publish the root package to crates.io
    Write-Output "📦 Publishing root package to crates.io..."
    cargo publish --allow-dirty

    if ($LASTEXITCODE -eq 0) {
        Write-Output "✨ Root package successfully published to crates.io!"
    } else {
        Write-Output "❌ Failed to publish root package to crates.io."
        Write-Output "Please check the output above for more details."
    }
} else {
    Write-Output "❌ Failed to publish derive package to crates.io."
    Write-Output "Please check the output above for more details."
}

Write-Output "🎉 Release v$newVersion completed!"