From 47b0368f4608df2739933e8dc262fbf3c360baa3 Mon Sep 17 00:00:00 2001 From: Cristian Pufu Date: Mon, 27 Oct 2025 16:58:11 +0200 Subject: [PATCH] fix: add ci/cd --- .github/workflows/cd.yml | 76 ++++++++++++++++++ .github/workflows/ci.yml | 22 +++++ .github/workflows/commitlint.yml | 47 +++++++++++ .github/workflows/lint.yml | 39 +++++++++ .github/workflows/publish-dev.yml | 129 ++++++++++++++++++++++++++++++ .github/workflows/test.yml | 37 +++++++++ 6 files changed, 350 insertions(+) create mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/commitlint.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/publish-dev.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..2946e64 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,76 @@ +name: CD + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - pyproject.toml + +jobs: + lint: + uses: ./.github/workflows/lint.yml + + test: + uses: ./.github/workflows/test.yml + + build: + name: Build + runs-on: ubuntu-latest + + needs: + - lint + - test + + if: ${{ github.repository == 'UiPath/uipath-python' }} + permissions: + contents: read + actions: write + + 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: Build + run: uv build + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: release-dists + path: dist/ + + pypi-publish: + name: Upload release to PyPI + runs-on: ubuntu-latest + environment: pypi + + needs: + - build + permissions: + contents: read + id-token: write + + steps: + - name: Retrieve release distributions + uses: actions/download-artifact@v4 + with: + name: release-dists + path: dist/ + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..10192fb --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: CI + +on: + push: + branches: + - main + paths-ignore: + - pyproject.toml + pull_request: + branches: + - main + +jobs: + commit-lint: + if: ${{ github.event_name == 'pull_request' }} + uses: ./.github/workflows/commitlint.yml + + lint: + uses: ./.github/workflows/lint.yml + + test: + uses: ./.github/workflows/test.yml diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml new file mode 100644 index 0000000..8562e45 --- /dev/null +++ b/.github/workflows/commitlint.yml @@ -0,0 +1,47 @@ +name: Commit Lint + +on: + workflow_call + +jobs: + commitlint: + name: Commit Lint + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 22 + + - name: Install Git + run: | + if ! command -v git &> /dev/null; then + echo "Git is not installed. Installing..." + sudo apt-get update + sudo apt-get install -y git + else + echo "Git is already installed." + fi + + - name: Install commitlint + run: | + npm install conventional-changelog-conventionalcommits + npm install commitlint@latest + npm install @commitlint/config-conventional + + - name: Configure + run: | + echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js + + - name: Validate PR commits with commitlint + run: | + git fetch origin pull/${{ github.event.pull_request.number }}/head:pr_branch + npx commitlint --from ${{ github.event.pull_request.base.sha }} --to pr_branch --verbose diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..d259d94 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,39 @@ +name: Lint + +on: + workflow_call + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + permissions: + contents: read + + 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: Check static types + run: uv run mypy --config-file pyproject.toml . + + - name: Check linting + run: uv run ruff check . + + - name: Check formatting + run: uv run ruff format --check . + + diff --git a/.github/workflows/publish-dev.yml b/.github/workflows/publish-dev.yml new file mode 100644 index 0000000..ae0907d --- /dev/null +++ b/.github/workflows/publish-dev.yml @@ -0,0 +1,129 @@ +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: 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" + + $dependencyMessage = @" + ## Development Package + + - 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" } + `````` + "@ + + # 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 there's already a development package section + if ($currentBody -match '## Development Package') { + # Replace the existing section with the new dependency message + $newBody = $currentBody -replace '## Development Package(\r?\n|.)*?(?=##|$)', $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 }} + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..61c431f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,37 @@ +name: Test + +on: + workflow_call + +jobs: + test: + name: Test + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: ["3.10", "3.11", "3.12", "3.13"] + os: [ubuntu-latest, windows-latest] + + permissions: + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup uv + uses: astral-sh/setup-uv@v5 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: uv sync --all-extras + + - name: Run tests + run: uv run pytest + + continue-on-error: true +