1- name : Publish Dev Build
2-
3- on :
4- pull_request :
5- types : [opened, synchronize, reopened, labeled]
6-
7- jobs :
8- publish-dev :
9- runs-on : ubuntu-latest
10- permissions :
11- contents : read
12- pull-requests : write
13-
14- # Only run if PR has the build:dev label
15- # if: contains(github.event.pull_request.labels.*.name, 'build:dev')
16-
17- steps :
18- - name : Checkout
19- uses : actions/checkout@v4
20-
21- - name : Setup uv
22- uses : astral-sh/setup-uv@v5
23- with :
24- enable-cache : true
25-
26- - name : Setup Python
27- uses : actions/setup-python@v5
28- with :
29- python-version-file : " .python-version"
30-
31- - name : Install dependencies
32- run : uv sync --all-extras
33-
34- - name : Set development version
35- shell : pwsh
36- env :
37- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
38- run : |
39- $pyprojcontent = Get-Content pyproject.toml -Raw
40-
41- $PROJECT_NAME = ($pyprojcontent | Select-String -Pattern '(?m)^\[(project|tool\.poetry)\][^\[]*?name\s*=\s*"([^"]*)"' -AllMatches).Matches[0].Groups[2].Value
42- $CURRENT_VERSION = ($pyprojcontent | Select-String -Pattern '(?m)^\[(project|tool\.poetry)\][^\[]*?version\s*=\s*"([^"]*)"' -AllMatches).Matches[0].Groups[2].Value
43-
44- # Get PR number and run number with proper padding
45- $PR_NUM = [int]"${{ github.event.pull_request.number }}"
46- $PADDED_PR = "{0:D5}" -f [int]"${{ github.event.pull_request.number }}"
47- $PADDED_RUN = "{0:D4}" -f [int]"${{ github.run_number }}"
48- $PADDED_NEXT_PR = "{0:D5}" -f ($PR_NUM + 1)
49-
50- # Create version range strings for PR
51- $MIN_VERSION = "$CURRENT_VERSION.dev1$PADDED_PR" + "0000"
52- $MAX_VERSION = "$CURRENT_VERSION.dev1$PADDED_NEXT_PR" + "0000"
53-
54- # Create unique dev version with PR number and run ID
55- $DEV_VERSION = "$CURRENT_VERSION.dev1$PADDED_PR$PADDED_RUN"
56-
57- # Update version in pyproject.toml
58- (Get-Content pyproject.toml) -replace "version = `"$CURRENT_VERSION`"", "version = `"$DEV_VERSION`"" | Set-Content pyproject.toml
59-
60- Write-Output "Package version set to $DEV_VERSION"
61-
62- $dependencyMessage = @"
63- ## Development Package
64-
65- - Add this package as a dependency in your pyproject.toml:
66-
67- ``````toml
68- [project]
69- dependencies = [
70- # Exact version:
71- "$PROJECT_NAME==$DEV_VERSION",
72-
73- # Any version from PR
74- "$PROJECT_NAME>=$MIN_VERSION,<$MAX_VERSION"
75- ]
76-
77- [[tool.uv.index]]
78- name = "testpypi"
79- url = "https://test.pypi.org/simple/"
80- publish-url = "https://test.pypi.org/legacy/"
81- explicit = true
82-
83- [tool.uv.sources]
84- $PROJECT_NAME = { index = "testpypi" }
85- ``````
86- "@
87-
88- # Get the owner and repo from the GitHub repository
89- $owner = "${{ github.repository_owner }}"
90- $repo = "${{ github.repository }}".Split('/')[1]
91- $prNumber = $PR_NUM
92-
93- # Get the current PR description
94- $prUri = "https://api.github.com/repos/$owner/$repo/pulls/$prNumber"
95- $headers = @{
96- Authorization = "token $env:GITHUB_TOKEN"
97- Accept = "application/vnd.github.v3+json"
98- }
99-
100- $pr = Invoke-RestMethod -Uri $prUri -Method Get -Headers $headers
101- $currentBody = $pr.body
102-
103- # Check if there's already a development package section
104- if ($currentBody -match '## Development Package') {
105- # Replace the existing section with the new dependency message
106- $newBody = $currentBody -replace '## Development Package(\r?\n|.)*?(?=##|$)', $dependencyMessage
107- } else {
108- # Append the dependency message to the end of the description
109- $newBody = if ($currentBody) { "$currentBody`n`n$dependencyMessage" } else { $dependencyMessage }
110- }
111-
112- # Update the PR description
113- $updateBody = @{
114- body = $newBody
115- } | ConvertTo-Json
116-
117- Invoke-RestMethod -Uri $prUri -Method Patch -Headers $headers -Body $updateBody -ContentType "application/json"
118-
119- Write-Output "Updated PR description with development package information"
120-
121- - name : Build package
122- run : uv build
123-
124- - name : Publish
125- run : uv publish --index testpypi
126- env :
127- UV_PUBLISH_TOKEN : ${{ secrets.TEST_PYPI_TOKEN }}
1+ name : Publish Dev Build
2+
3+ on :
4+ pull_request :
5+ types : [opened, synchronize, reopened, labeled]
6+
7+ jobs :
8+ publish-dev :
9+ runs-on : ubuntu-latest
10+ permissions :
11+ contents : read
12+ pull-requests : write
13+
14+ # Only run if PR has the build:dev label
15+ if : contains(github.event.pull_request.labels.*.name, 'build:dev')
16+
17+ steps :
18+ - name : Checkout
19+ uses : actions/checkout@v4
20+
21+ - name : Setup uv
22+ uses : astral-sh/setup-uv@v5
23+ with :
24+ enable-cache : true
25+
26+ - name : Setup Python
27+ uses : actions/setup-python@v5
28+ with :
29+ python-version-file : " .python-version"
30+
31+ - name : Install dependencies
32+ run : uv sync --all-extras
33+
34+ - name : Set development version
35+ shell : pwsh
36+ env :
37+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
38+ run : |
39+ $pyprojcontent = Get-Content pyproject.toml -Raw
40+
41+ $PROJECT_NAME = ($pyprojcontent | Select-String -Pattern '(?m)^\[(project|tool\.poetry)\][^\[]*?name\s*=\s*"([^"]*)"' -AllMatches).Matches[0].Groups[2].Value
42+ $CURRENT_VERSION = ($pyprojcontent | Select-String -Pattern '(?m)^\[(project|tool\.poetry)\][^\[]*?version\s*=\s*"([^"]*)"' -AllMatches).Matches[0].Groups[2].Value
43+
44+ # Get PR number and run number with proper padding
45+ $PR_NUM = [int]"${{ github.event.pull_request.number }}"
46+ $PADDED_PR = "{0:D5}" -f [int]"${{ github.event.pull_request.number }}"
47+ $PADDED_RUN = "{0:D4}" -f [int]"${{ github.run_number }}"
48+ $PADDED_NEXT_PR = "{0:D5}" -f ($PR_NUM + 1)
49+
50+ # Create version range strings for PR
51+ $MIN_VERSION = "$CURRENT_VERSION.dev1$PADDED_PR" + "0000"
52+ $MAX_VERSION = "$CURRENT_VERSION.dev1$PADDED_NEXT_PR" + "0000"
53+
54+ # Create unique dev version with PR number and run ID
55+ $DEV_VERSION = "$CURRENT_VERSION.dev1$PADDED_PR$PADDED_RUN"
56+
57+ # Update version in pyproject.toml
58+ (Get-Content pyproject.toml) -replace "version = `"$CURRENT_VERSION`"", "version = `"$DEV_VERSION`"" | Set-Content pyproject.toml
59+
60+ Write-Output "Package version set to $DEV_VERSION"
61+
62+ $dependencyMessage = @"
63+ ## Development Package
64+
65+ - Add this package as a dependency in your pyproject.toml:
66+
67+ ``````toml
68+ [project]
69+ dependencies = [
70+ # Exact version:
71+ "$PROJECT_NAME==$DEV_VERSION",
72+
73+ # Any version from PR
74+ "$PROJECT_NAME>=$MIN_VERSION,<$MAX_VERSION"
75+ ]
76+
77+ [[tool.uv.index]]
78+ name = "testpypi"
79+ url = "https://test.pypi.org/simple/"
80+ publish-url = "https://test.pypi.org/legacy/"
81+ explicit = true
82+
83+ [tool.uv.sources]
84+ $PROJECT_NAME = { index = "testpypi" }
85+ ``````
86+ "@
87+
88+ # Get the owner and repo from the GitHub repository
89+ $owner = "${{ github.repository_owner }}"
90+ $repo = "${{ github.repository }}".Split('/')[1]
91+ $prNumber = $PR_NUM
92+
93+ # Get the current PR description
94+ $prUri = "https://api.github.com/repos/$owner/$repo/pulls/$prNumber"
95+ $headers = @{
96+ Authorization = "token $env:GITHUB_TOKEN"
97+ Accept = "application/vnd.github.v3+json"
98+ }
99+
100+ $pr = Invoke-RestMethod -Uri $prUri -Method Get -Headers $headers
101+ $currentBody = $pr.body
102+
103+ # Check if there's already a development package section
104+ if ($currentBody -match '## Development Package') {
105+ # Replace the existing section with the new dependency message
106+ $newBody = $currentBody -replace '## Development Package(\r?\n|.)*?(?=##|$)', $dependencyMessage
107+ } else {
108+ # Append the dependency message to the end of the description
109+ $newBody = if ($currentBody) { "$currentBody`n`n$dependencyMessage" } else { $dependencyMessage }
110+ }
111+
112+ # Update the PR description
113+ $updateBody = @{
114+ body = $newBody
115+ } | ConvertTo-Json
116+
117+ Invoke-RestMethod -Uri $prUri -Method Patch -Headers $headers -Body $updateBody -ContentType "application/json"
118+
119+ Write-Output "Updated PR description with development package information"
120+
121+ - name : Build package
122+ run : uv build
123+
124+ - name : Publish
125+ run : uv publish --index testpypi
126+ env :
127+ UV_PUBLISH_TOKEN : ${{ secrets.TEST_PYPI_TOKEN }}
0 commit comments