Skip to content

Commit 47b0368

Browse files
committed
fix: add ci/cd
1 parent c17f476 commit 47b0368

File tree

6 files changed

+350
-0
lines changed

6 files changed

+350
-0
lines changed

.github/workflows/cd.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: CD
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- pyproject.toml
10+
11+
jobs:
12+
lint:
13+
uses: ./.github/workflows/lint.yml
14+
15+
test:
16+
uses: ./.github/workflows/test.yml
17+
18+
build:
19+
name: Build
20+
runs-on: ubuntu-latest
21+
22+
needs:
23+
- lint
24+
- test
25+
26+
if: ${{ github.repository == 'UiPath/uipath-python' }}
27+
permissions:
28+
contents: read
29+
actions: write
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
35+
- name: Setup uv
36+
uses: astral-sh/setup-uv@v5
37+
with:
38+
enable-cache: true
39+
40+
- name: Setup Python
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version-file: ".python-version"
44+
45+
- name: Install dependencies
46+
run: uv sync --all-extras
47+
48+
- name: Build
49+
run: uv build
50+
51+
- name: Upload artifacts
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: release-dists
55+
path: dist/
56+
57+
pypi-publish:
58+
name: Upload release to PyPI
59+
runs-on: ubuntu-latest
60+
environment: pypi
61+
62+
needs:
63+
- build
64+
permissions:
65+
contents: read
66+
id-token: write
67+
68+
steps:
69+
- name: Retrieve release distributions
70+
uses: actions/download-artifact@v4
71+
with:
72+
name: release-dists
73+
path: dist/
74+
75+
- name: Publish package distributions to PyPI
76+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- pyproject.toml
9+
pull_request:
10+
branches:
11+
- main
12+
13+
jobs:
14+
commit-lint:
15+
if: ${{ github.event_name == 'pull_request' }}
16+
uses: ./.github/workflows/commitlint.yml
17+
18+
lint:
19+
uses: ./.github/workflows/lint.yml
20+
21+
test:
22+
uses: ./.github/workflows/test.yml

.github/workflows/commitlint.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Commit Lint
2+
3+
on:
4+
workflow_call
5+
6+
jobs:
7+
commitlint:
8+
name: Commit Lint
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Setup Node
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: 22
23+
24+
- name: Install Git
25+
run: |
26+
if ! command -v git &> /dev/null; then
27+
echo "Git is not installed. Installing..."
28+
sudo apt-get update
29+
sudo apt-get install -y git
30+
else
31+
echo "Git is already installed."
32+
fi
33+
34+
- name: Install commitlint
35+
run: |
36+
npm install conventional-changelog-conventionalcommits
37+
npm install commitlint@latest
38+
npm install @commitlint/config-conventional
39+
40+
- name: Configure
41+
run: |
42+
echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
43+
44+
- name: Validate PR commits with commitlint
45+
run: |
46+
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr_branch
47+
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to pr_branch --verbose

.github/workflows/lint.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Lint
2+
3+
on:
4+
workflow_call
5+
6+
jobs:
7+
lint:
8+
name: Lint
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup uv
18+
uses: astral-sh/setup-uv@v5
19+
with:
20+
enable-cache: true
21+
22+
- name: Setup Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version-file: ".python-version"
26+
27+
- name: Install dependencies
28+
run: uv sync --all-extras
29+
30+
- name: Check static types
31+
run: uv run mypy --config-file pyproject.toml .
32+
33+
- name: Check linting
34+
run: uv run ruff check .
35+
36+
- name: Check formatting
37+
run: uv run ruff format --check .
38+
39+

.github/workflows/publish-dev.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
45+
# Get PR number and run number with proper padding
46+
$PR_NUM = [int]"${{ github.event.pull_request.number }}"
47+
$PADDED_PR = "{0:D5}" -f [int]"${{ github.event.pull_request.number }}"
48+
$PADDED_RUN = "{0:D4}" -f [int]"${{ github.run_number }}"
49+
$PADDED_NEXT_PR = "{0:D5}" -f ($PR_NUM + 1)
50+
51+
# Create version range strings for PR
52+
$MIN_VERSION = "$CURRENT_VERSION.dev1$PADDED_PR" + "0000"
53+
$MAX_VERSION = "$CURRENT_VERSION.dev1$PADDED_NEXT_PR" + "0000"
54+
55+
# Create unique dev version with PR number and run ID
56+
$DEV_VERSION = "$CURRENT_VERSION.dev1$PADDED_PR$PADDED_RUN"
57+
58+
# Update version in pyproject.toml
59+
(Get-Content pyproject.toml) -replace "version = `"$CURRENT_VERSION`"", "version = `"$DEV_VERSION`"" | Set-Content pyproject.toml
60+
61+
Write-Output "Package version set to $DEV_VERSION"
62+
63+
$dependencyMessage = @"
64+
## Development Package
65+
66+
- Add this package as a dependency in your pyproject.toml:
67+
68+
``````toml
69+
[project]
70+
dependencies = [
71+
# Exact version:
72+
"$PROJECT_NAME==$DEV_VERSION",
73+
74+
# Any version from PR
75+
"$PROJECT_NAME>=$MIN_VERSION,<$MAX_VERSION"
76+
]
77+
78+
[[tool.uv.index]]
79+
name = "testpypi"
80+
url = "https://test.pypi.org/simple/"
81+
publish-url = "https://test.pypi.org/legacy/"
82+
explicit = true
83+
84+
[tool.uv.sources]
85+
$PROJECT_NAME = { index = "testpypi" }
86+
``````
87+
"@
88+
89+
# Get the owner and repo from the GitHub repository
90+
$owner = "${{ github.repository_owner }}"
91+
$repo = "${{ github.repository }}".Split('/')[1]
92+
$prNumber = $PR_NUM
93+
94+
# Get the current PR description
95+
$prUri = "https://api.github.com/repos/$owner/$repo/pulls/$prNumber"
96+
$headers = @{
97+
Authorization = "token $env:GITHUB_TOKEN"
98+
Accept = "application/vnd.github.v3+json"
99+
}
100+
101+
$pr = Invoke-RestMethod -Uri $prUri -Method Get -Headers $headers
102+
$currentBody = $pr.body
103+
104+
# Check if there's already a development package section
105+
if ($currentBody -match '## Development Package') {
106+
# Replace the existing section with the new dependency message
107+
$newBody = $currentBody -replace '## Development Package(\r?\n|.)*?(?=##|$)', $dependencyMessage
108+
} else {
109+
# Append the dependency message to the end of the description
110+
$newBody = if ($currentBody) { "$currentBody`n`n$dependencyMessage" } else { $dependencyMessage }
111+
}
112+
113+
# Update the PR description
114+
$updateBody = @{
115+
body = $newBody
116+
} | ConvertTo-Json
117+
118+
Invoke-RestMethod -Uri $prUri -Method Patch -Headers $headers -Body $updateBody -ContentType "application/json"
119+
120+
Write-Output "Updated PR description with development package information"
121+
122+
- name: Build package
123+
run: uv build
124+
125+
- name: Publish
126+
run: uv publish --index testpypi
127+
env:
128+
UV_PUBLISH_TOKEN: ${{ secrets.TESTPYPI_TOKEN }}
129+

.github/workflows/test.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Test
2+
3+
on:
4+
workflow_call
5+
6+
jobs:
7+
test:
8+
name: Test
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
python-version: ["3.10", "3.11", "3.12", "3.13"]
13+
os: [ubuntu-latest, windows-latest]
14+
15+
permissions:
16+
contents: read
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Setup uv
23+
uses: astral-sh/setup-uv@v5
24+
25+
- name: Setup Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
30+
- name: Install dependencies
31+
run: uv sync --all-extras
32+
33+
- name: Run tests
34+
run: uv run pytest
35+
36+
continue-on-error: true
37+

0 commit comments

Comments
 (0)