Skip to content

Commit 4fc7dda

Browse files
Bump version for deploy
1 parent 8d8f063 commit 4fc7dda

File tree

2 files changed

+217
-1
lines changed

2 files changed

+217
-1
lines changed

build_and_deploy.ps1

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
# Function to update version in a file
2+
function Update-VersionInFile {
3+
param (
4+
[string]$Version,
5+
[string]$FilePath,
6+
[bool]$DryRun = $false
7+
)
8+
# Read the file content
9+
$content = Get-Content $FilePath
10+
$updated = $false
11+
$oldVersion = ""
12+
13+
# Process each line to only update the main package version in [tool.poetry] section
14+
$inPoetrySection = $false
15+
for ($i = 0; $i -lt $content.Length; $i++) {
16+
$line = $content[$i]
17+
18+
# Check if we're entering the [tool.poetry] section
19+
if ($line -match '^\[tool\.poetry\]') {
20+
$inPoetrySection = $true
21+
}
22+
# Check if we're entering a different section
23+
elseif ($line -match '^\[.*\]' -and $line -notmatch '^\[tool\.poetry\]') {
24+
$inPoetrySection = $false
25+
}
26+
# Update version only if we're in the [tool.poetry] section and it's the main version line
27+
elseif ($inPoetrySection -and $line -match '^version = "(.+)"$') {
28+
$oldVersion = $matches[1]
29+
if (-not $DryRun) {
30+
$content[$i] = $line -replace 'version = ".*"', "version = `"$Version`""
31+
}
32+
$updated = $true
33+
break
34+
}
35+
}
36+
37+
if ($updated) {
38+
if ($DryRun) {
39+
Write-Host "[DRY RUN] Would update main package version in $FilePath from $oldVersion to $Version"
40+
} else {
41+
Set-Content $FilePath $content
42+
Write-Host "Updated main package version in $FilePath to $Version"
43+
}
44+
} else {
45+
Write-Host "Warning: Could not find main package version to update in $FilePath"
46+
}
47+
}
48+
49+
# Function to update (increment) version
50+
function Update-Version {
51+
param (
52+
[string]$Version,
53+
[string]$ReleaseType
54+
)
55+
56+
$versionParts = $Version -split '\.'
57+
$major = [int]$versionParts[0]
58+
$minor = [int]$versionParts[1]
59+
$patch = [int]$versionParts[2]
60+
61+
switch ($ReleaseType) {
62+
"major" {
63+
$major++
64+
$minor = 0
65+
$patch = 0
66+
}
67+
"minor" {
68+
$minor++
69+
$patch = 0
70+
}
71+
"patch" {
72+
$patch++
73+
}
74+
default {
75+
Write-Host "Invalid release type. Use 'major', 'minor', or 'patch'."
76+
exit 1
77+
}
78+
}
79+
80+
return "$major.$minor.$patch"
81+
}
82+
83+
# Function to set PyPI token
84+
function Set-PyPIToken {
85+
param (
86+
[bool]$DryRun = $false
87+
)
88+
if (-not $env:PYPI_TOKEN) {
89+
Write-Host "Error: PYPI_TOKEN environment variable is not set."
90+
if (-not $DryRun) {
91+
exit 1
92+
}
93+
}
94+
if ($DryRun) {
95+
Write-Host "[DRY RUN] Would configure PyPI token"
96+
} else {
97+
poetry config pypi-token.pypi $env:PYPI_TOKEN
98+
Write-Host "PyPI token configured successfully."
99+
}
100+
}
101+
102+
# Add this function at the beginning of the script
103+
function Import-EnvFile {
104+
$envFile = ".env"
105+
if (Test-Path $envFile) {
106+
Get-Content $envFile | ForEach-Object {
107+
if ($_ -match '^([^=]+)=(.*)$') {
108+
$name = $matches[1]
109+
$value = $matches[2]
110+
Set-Item -Path "env:$name" -Value $value
111+
}
112+
}
113+
Write-Host "Environment variables loaded from .env file."
114+
}
115+
else {
116+
Write-Host "Warning: .env file not found."
117+
}
118+
}
119+
120+
# Call this function before any other operations in the script
121+
Import-EnvFile
122+
123+
# Parse arguments
124+
$releaseType = ""
125+
$dryRun = $false
126+
127+
foreach ($arg in $args) {
128+
if ($arg -eq "--dry" -or $arg -eq "--dry-run") {
129+
$dryRun = $true
130+
}
131+
elseif ($arg -in @("major", "minor", "patch")) {
132+
$releaseType = $arg
133+
}
134+
else {
135+
Write-Host "Unknown argument: $arg"
136+
Write-Host "Usage: .\build_and_deploy.ps1 <major|minor|patch> [--dry]"
137+
exit 1
138+
}
139+
}
140+
141+
# Check if release type is provided
142+
if (-not $releaseType) {
143+
Write-Host "Please specify a release type (major, minor, or patch)"
144+
Write-Host "Usage: .\build_and_deploy.ps1 <major|minor|patch> [--dry]"
145+
exit 1
146+
}
147+
148+
# Validate release type
149+
if ($releaseType -notin @("major", "minor", "patch")) {
150+
Write-Host "Invalid release type. Use 'major', 'minor', or 'patch'."
151+
exit 1
152+
}
153+
154+
# Get current version from pyproject.toml (specifically from [tool.poetry] section)
155+
$pyprojectContent = Get-Content "pyproject.toml"
156+
$currentVersion = ""
157+
$inPoetrySection = $false
158+
159+
foreach ($line in $pyprojectContent) {
160+
if ($line -match '^\[tool\.poetry\]') {
161+
$inPoetrySection = $true
162+
}
163+
elseif ($line -match '^\[.*\]' -and $line -notmatch '^\[tool\.poetry\]') {
164+
$inPoetrySection = $false
165+
}
166+
elseif ($inPoetrySection -and $line -match '^version = "(.+)"$') {
167+
$currentVersion = $matches[1]
168+
break
169+
}
170+
}
171+
172+
if (-not $currentVersion) {
173+
Write-Host "Error: Could not find current version in pyproject.toml [tool.poetry] section"
174+
exit 1
175+
}
176+
177+
# Calculate new version
178+
$newVersion = Update-Version -Version $currentVersion -ReleaseType $releaseType
179+
180+
if ($dryRun) {
181+
Write-Host "[DRY RUN] Would update version from $currentVersion to $newVersion"
182+
} else {
183+
Write-Host "Updating version from $currentVersion to $newVersion"
184+
}
185+
186+
# Update version in files
187+
Update-VersionInFile -Version $newVersion -FilePath "pyproject.toml" -DryRun $dryRun
188+
189+
if ($dryRun) {
190+
Write-Host "[DRY RUN] Would perform the following actions:"
191+
Write-Host "[DRY RUN] - Build consolidated atomic-agents package"
192+
Write-Host "[DRY RUN] - Install dependencies with poetry install"
193+
Write-Host "[DRY RUN] - Build package with poetry build"
194+
Write-Host "[DRY RUN] - Configure PyPI token"
195+
Write-Host "[DRY RUN] - Upload to PyPI with poetry publish"
196+
Write-Host "[DRY RUN] Dry run completed - no actual changes made!"
197+
exit 0
198+
}
199+
200+
# Build the consolidated package
201+
Write-Host "Building consolidated atomic-agents package..."
202+
203+
# Create a new virtualenv in the project directory and install dependencies
204+
poetry install
205+
206+
# Build the package
207+
poetry build
208+
209+
# Before publishing, set the PyPI token
210+
Set-PyPIToken -DryRun $dryRun
211+
212+
# Upload to PyPI
213+
Write-Host "Uploading atomic-agents to PyPI..."
214+
poetry publish
215+
216+
Write-Host "Build and deploy process completed successfully!"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "atomic-agents"
7-
version = "2.2.0"
7+
version = "2.2.1"
88
description = "A versatile framework for creating and managing intelligent agents."
99
authors = ["Kenny Vaneetvelde <[email protected]>"]
1010
readme = "README.md"

0 commit comments

Comments
 (0)