From 5efea9b77956680c2b378d35b088fb8b58623f7f Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Wed, 26 Nov 2025 14:24:26 +0545 Subject: [PATCH] feat(ci): add workflow to publish package to PyPI on release --- .github/workflows/dependabot-auto-merge.yml | 9 +---- .github/workflows/publish.yml | 29 +++++++++++++++ .github/workflows/release.yml | 39 --------------------- 3 files changed, 30 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index d2a5644..d99cbf8 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -1,13 +1,10 @@ name: Dependabot Auto-Approve and Auto-Merge - on: pull_request_target: types: [opened, reopened, synchronize] - permissions: contents: write pull-requests: write - jobs: dependabot: if: github.actor == 'dependabot[bot]' @@ -16,27 +13,23 @@ jobs: - name: Dependabot metadata id: metadata uses: dependabot/fetch-metadata@v2 - - name: Approve PR if: | steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch' uses: actions/github-script@v8 with: - github-token: ${{ secrets.DEPENDABOT_AUTOMERGE_TOKEN || secrets.GITHUB_TOKEN }} script: | - await github.pulls.createReview({ + await github.rest.pulls.createReview({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.payload.pull_request.number, event: 'APPROVE' }) - - name: Enable auto-merge (squash) if: | steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch' uses: peter-evans/enable-pull-request-automerge@v3 with: - token: ${{ secrets.DEPENDABOT_AUTOMERGE_TOKEN || secrets.GITHUB_TOKEN }} merge-method: squash diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..adc82f2 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,29 @@ +name: Publish to PyPI +on: + release: + types: [published] +permissions: + contents: read +jobs: + deploy: + runs-on: ubuntu-latest + environment: release + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + cache: 'pip' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install hatch twine + - name: Build package + run: hatch build + - name: Test package + run: hatch run test + - name: Publish package to PyPI + run: python -m twine upload dist/* --verbose diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 1dc5367..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Release - -on: - push: - tags: - - 'v*' - -jobs: - build-and-publish: - name: Build and Publish to PyPI - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v6 - - - name: Set up Python - uses: actions/setup-python@v6 - with: - python-version: "3.11" - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build twine - - - name: Build package - run: | - python -m build - - - name: Check package - run: | - twine check dist/* - - - name: Publish to PyPI - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} - run: | - twine upload dist/*