-
Notifications
You must be signed in to change notification settings - Fork 23
152 lines (117 loc) · 5.23 KB
/
publish-dev.yml
File metadata and controls
152 lines (117 loc) · 5.23 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
name: Publish Dev Build
on:
pull_request:
types: [opened, synchronize, reopened, labeled]
jobs:
publish-dev:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
# Only run if PR has the build:dev label
if: contains(github.event.pull_request.labels.*.name, 'build:dev')
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: ".python-version"
- name: Install dependencies
run: uv sync --all-extras
- name: Replace connection string placeholder
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.APPINS_CONNECTION_STRING }}
- name: Set development version
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$pyprojcontent = Get-Content pyproject.toml -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 pyproject.toml) -replace "version = `"$CURRENT_VERSION`"", "version = `"$DEV_VERSION`"" | Set-Content pyproject.toml
Write-Output "Package version set to $DEV_VERSION"
$startMarker = "<!-- DEV_PACKAGE_START -->"
$endMarker = "<!-- DEV_PACKAGE_END -->"
$dependencyMessage = @"
$startMarker
## Development Package
- Use ``uipath pack --nolock`` to get the latest dev build from this PR (requires version range).
- Add this package as a dependency in your pyproject.toml:
``````toml
[project]
dependencies = [
# Exact version:
"$PROJECT_NAME==$DEV_VERSION",
# Any version from PR
"$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]
$PROJECT_NAME = { index = "testpypi" }
[tool.uv]
override-dependencies = [
"$PROJECT_NAME>=$MIN_VERSION,<$MAX_VERSION",
]
``````
$endMarker
"@
# 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
# Check if markers already exist in the PR description
$markerPattern = "(?s)$([regex]::Escape($startMarker)).*?$([regex]::Escape($endMarker))"
if ($currentBody -match $markerPattern) {
# Replace everything between markers (including markers)
$newBody = $currentBody -replace $markerPattern, $dependencyMessage
} else {
# Append the dependency message to the end of the description
$newBody = if ($currentBody) { "$currentBody`n`n$dependencyMessage" } else { $dependencyMessage }
}
# Update the PR description
$updateBody = @{
body = $newBody
} | ConvertTo-Json
Invoke-RestMethod -Uri $prUri -Method Patch -Headers $headers -Body $updateBody -ContentType "application/json"
Write-Output "Updated PR description with development package information"
- name: Build package
run: uv build
- name: Publish
run: uv publish --index testpypi
env:
UV_PUBLISH_TOKEN: ${{ secrets.TESTPYPI_TOKEN }}