From e636e6066730f38fed2021bbe090e83aa3c5d83d Mon Sep 17 00:00:00 2001 From: Dmitrii Kharitonov Date: Sun, 29 Jun 2025 15:57:19 +0200 Subject: [PATCH] Add continuous deployment workflow for package publishing --- .github/workflows/cd.yml | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..e2f2380 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,53 @@ +name: CD + +on: + # Deploy to TestPyPI after CI passes on main branch + workflow_run: + workflows: ["CI"] + types: [completed] + branches: [main] + + # Deploy to PyPI on version tags + push: + tags: + - 'v*' + +jobs: + publish: + runs-on: ubuntu-latest + # Only run if CI workflow succeeded (for main branch) or on tags + if: | + (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main') || + startsWith(github.ref, 'refs/tags/v') + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Needed for hatch-vcs to work properly + + - name: Install uv + uses: astral-sh/setup-uv@v4 + with: + version: "latest" + + - name: Set up Python + run: uv python install 3.9 + + - name: Install dependencies + run: uv sync --group dev + + - name: Build package + run: uv build + + - name: Publish to TestPyPI (on main branch) + if: github.ref == 'refs/heads/main' + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} + run: uv run twine upload --repository testpypi dist/* + + - name: Publish to PyPI (on tags) + if: startsWith(github.ref, 'refs/tags/v') + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: uv run twine upload dist/*