diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..3bda9b2 --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,96 @@ +name: Python Package CI/CD + +on: + push: + branches: + - main + tags: + - "v*" + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12"] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest ruff build + + - name: Lint + run: | + ruff check . + + - name: Run tests + run: | + pytest + + build: + runs-on: ubuntu-latest + needs: test + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install build tools + run: | + python -m pip install --upgrade pip + pip install build twine + + - name: Clean old build artifacts (Just in case) + run: | + rm -rf dist/ build/ *.egg-info + + - name: Build package + run: | + python -m build + + - name: Check package + run: | + twine check dist/* + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: python-package + path: dist/* + retention-days: 1 + + publish: + if: startsWith(github.ref, 'refs/tags/') + needs: build + runs-on: ubuntu-latest + permissions: + id-token: write + + environment: + name: pypi + + steps: + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: python-package + path: dist + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1