-
Notifications
You must be signed in to change notification settings - Fork 27
263 lines (220 loc) · 10.6 KB
/
Copy pathpublish-dev.yml
File metadata and controls
263 lines (220 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: Publish Dev Build
on:
pull_request:
types: [opened, synchronize, reopened, labeled]
paths:
- 'packages/**'
- '.github/workflows/publish-dev.yml'
- '.github/scripts/detect_changed_packages.py'
permissions:
contents: read
pull-requests: write
jobs:
detect-changed-packages:
if: contains(github.event.pull_request.labels.*.name, 'build:dev')
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.detect.outputs.packages }}
count: ${{ steps.detect.outputs.count }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Detect changed packages
id: detect
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: python .github/scripts/detect_changed_packages.py
publish-dev:
name: Publish Dev Build - ${{ matrix.package }}
needs: detect-changed-packages
if: contains(github.event.pull_request.labels.*.name, 'build:dev') && needs.detect-changed-packages.outputs.count > 0
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/${{ matrix.package }}
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.detect-changed-packages.outputs.packages) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version-file: "packages/${{ matrix.package }}/.python-version"
- name: Install dependencies
run: uv sync --all-extras
- name: Replace connection string placeholder
if: matrix.package == 'uipath'
run: |
originalfile="src/uipath/telemetry/_constants.py"
tmpfile=$(mktemp)
trap 'rm -f "$tmpfile"' EXIT
rsync -a --no-whole-file --ignore-existing "$originalfile" "$tmpfile"
envsubst '$CONNECTION_STRING' < "$originalfile" > "$tmpfile" && mv "$tmpfile" "$originalfile"
env:
CONNECTION_STRING: ${{ secrets.APPLICATIONINSIGHTS_CONNECTION_STRING }}
- name: Set development version
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$pyprojPath = "pyproject.toml"
$pyprojcontent = Get-Content $pyprojPath -Raw
$PROJECT_NAME = ($pyprojcontent | Select-String -Pattern '(?m)^\[(project|tool\.poetry)\][^\[]*?name\s*=\s*"([^"]*)"' -AllMatches).Matches[0].Groups[2].Value
$CURRENT_VERSION = ($pyprojcontent | Select-String -Pattern '(?m)^\[(project|tool\.poetry)\][^\[]*?version\s*=\s*"([^"]*)"' -AllMatches).Matches[0].Groups[2].Value
# Get PR number and run number with proper padding
$PR_NUM = [int]"${{ github.event.pull_request.number }}"
$PADDED_PR = "{0:D5}" -f [int]"${{ github.event.pull_request.number }}"
$PADDED_RUN = "{0:D4}" -f [int]"${{ github.run_number }}"
$PADDED_NEXT_PR = "{0:D5}" -f ($PR_NUM + 1)
# Create version range strings for PR
$MIN_VERSION = "$CURRENT_VERSION.dev1$PADDED_PR" + "0000"
$MAX_VERSION = "$CURRENT_VERSION.dev1$PADDED_NEXT_PR" + "0000"
# Create unique dev version with PR number and run ID
$DEV_VERSION = "$CURRENT_VERSION.dev1$PADDED_PR$PADDED_RUN"
# Update version in pyproject.toml
(Get-Content $pyprojPath) -replace "version = `"$CURRENT_VERSION`"", "version = `"$DEV_VERSION`"" | Set-Content $pyprojPath
Write-Output "Package $PROJECT_NAME version set to $DEV_VERSION"
# Shared dev suffix for every package built in this run (same PR + run number)
$DEV_SUFFIX = "dev1$PADDED_PR$PADDED_RUN"
# Intra-repo dependencies per package. A dev build of these is < the package's
# base version (PEP 440 pre-release), so it falls outside the published ">=base"
# constraint and must be forced in via [tool.uv] override-dependencies.
$internalDepsMap = @{
"uipath" = @("uipath-platform", "uipath-core")
"uipath-platform" = @("uipath-core")
"uipath-core" = @()
}
# Packages also published in this run (their dev builds exist on testpypi)
$changedPackages = '${{ needs.detect-changed-packages.outputs.packages }}' | ConvertFrom-Json
$overrideDeps = @()
foreach ($dep in $internalDepsMap[$PROJECT_NAME]) {
if ($changedPackages -contains $dep) {
$depPyproj = Get-Content "../$dep/pyproject.toml" -Raw
$depBaseVersion = ($depPyproj | Select-String -Pattern '(?m)^\[(project|tool\.poetry)\][^\[]*?version\s*=\s*"([^"]*)"' -AllMatches).Matches[0].Groups[2].Value
$overrideDeps += [PSCustomObject]@{ Name = $dep; Version = "$depBaseVersion.$DEV_SUFFIX" }
}
}
# [tool.uv.sources]: the package itself plus every overridden dep point at testpypi
$sourcesLines = @("$PROJECT_NAME = { index = `"testpypi`" }")
foreach ($d in $overrideDeps) { $sourcesLines += "$($d.Name) = { index = `"testpypi`" }" }
$sourcesBlock = $sourcesLines -join "`n"
# Optional [tool.uv] override block (omitted when no intra-repo dep was published)
$overrideBlock = ""
if ($overrideDeps.Count -gt 0) {
$overrideItems = ($overrideDeps | ForEach-Object { "`"$($_.Name)==$($_.Version)`"" }) -join ", "
$overrideBlock = "`n[tool.uv]`noverride-dependencies = [$overrideItems]`n"
}
$dependencyMessage = @"
### $PROJECT_NAME
``````toml
[project]
dependencies = [
# Exact version (copy-paste ready):
"$PROJECT_NAME==$DEV_VERSION",
# Any version from this PR (uncomment to use a range instead):
# "$PROJECT_NAME>=$MIN_VERSION,<$MAX_VERSION",
]
[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
publish-url = "https://test.pypi.org/legacy/"
explicit = true
[tool.uv.sources]
$sourcesBlock
$overrideBlock``````
"@
# Get the owner and repo from the GitHub repository
$owner = "${{ github.repository_owner }}"
$repo = "${{ github.repository }}".Split('/')[1]
$prNumber = $PR_NUM
# Get the current PR description
$prUri = "https://api.github.com/repos/$owner/$repo/pulls/$prNumber"
$headers = @{
Authorization = "token $env:GITHUB_TOKEN"
Accept = "application/vnd.github.v3+json"
}
$pr = Invoke-RestMethod -Uri $prUri -Method Get -Headers $headers
$currentBody = $pr.body
# Define regex patterns for matching package sections
$devPackagesHeader = "## Development Packages"
$packageHeaderPattern = "### $PROJECT_NAME\s*\n"
# Find if the package section exists using multiline regex
$packageSectionRegex = "(?ms)### $PROJECT_NAME\s*\n``````toml.*?``````"
if ($currentBody -match $devPackagesHeader) {
# Development Packages section exists
if ($currentBody -match $packageSectionRegex) {
# Replace existing package section
Write-Output "Updating existing $PROJECT_NAME section"
$newBody = $currentBody -replace $packageSectionRegex, $dependencyMessage.Trim()
} else {
# Append new package section after the Development Packages header
Write-Output "Adding new $PROJECT_NAME section"
$insertPoint = $currentBody.IndexOf($devPackagesHeader) + $devPackagesHeader.Length
$newBody = $currentBody.Insert($insertPoint, "`n`n$dependencyMessage")
}
} else {
# Create the Development Packages section
Write-Output "Creating Development Packages section with $PROJECT_NAME"
$packageSection = @"
## Development Packages
$dependencyMessage
"@
$newBody = if ($currentBody) { "$currentBody`n`n$packageSection" } else { $packageSection }
}
# Update the PR description with retry logic
$maxRetries = 3
$retryCount = 0
$success = $false
while (-not $success -and $retryCount -lt $maxRetries) {
try {
$updateBody = @{
body = $newBody
} | ConvertTo-Json
Invoke-RestMethod -Uri $prUri -Method Patch -Headers $headers -Body $updateBody -ContentType "application/json" | Out-Null
$success = $true
Write-Output "Successfully updated PR description with $PROJECT_NAME information"
} catch {
$retryCount++
if ($retryCount -lt $maxRetries) {
Write-Output "Failed to update PR description, retrying ($retryCount/$maxRetries)..."
Start-Sleep -Seconds 2
# Re-fetch PR body in case another job updated it
$pr = Invoke-RestMethod -Uri $prUri -Method Get -Headers $headers
$currentBody = $pr.body
# Recompute newBody with fresh data
if ($currentBody -match $packageSectionRegex) {
$newBody = $currentBody -replace $packageSectionRegex, $dependencyMessage.Trim()
} elseif ($currentBody -match $devPackagesHeader) {
$insertPoint = $currentBody.IndexOf($devPackagesHeader) + $devPackagesHeader.Length
$newBody = $currentBody.Insert($insertPoint, "`n`n$dependencyMessage")
} else {
$packageSection = "$devPackagesHeader`n`n$dependencyMessage"
$newBody = if ($currentBody) { "$currentBody`n`n$packageSection" } else { $packageSection }
}
} else {
Write-Output "Failed to update PR description after $maxRetries attempts"
throw
}
}
}
- name: Build package
run: uv build --no-sources --package ${{ matrix.package }}
- name: Publish
run: uv publish --index testpypi
env:
UV_PUBLISH_TOKEN: ${{ matrix.package == 'uipath' && secrets.TESTPYPI_TOKEN || matrix.package == 'uipath-platform' && secrets.TESTPYPI_TOKEN_PLATFORM || secrets.TESTPYPI_TOKEN_CORE }}