publish.ymlโข2.72 kB
name: Publish to PyPI
on:
release:
types: [published]
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to publish (leave empty for current version)'
required: false
type: string
permissions:
contents: write
packages: write
id-token: write
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run ruff
run: |
python -m ruff check src/ tests/
- name: Run bandit
run: |
python -m bandit -r src/ -f txt
- name: Run tests
run: |
python -m pytest tests/ -v --tb=short --cov=src/mockloop_mcp --cov-report=xml
- name: Upload coverage to Codecov
if: matrix.python-version == '3.12'
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
fail_ci_if_error: false
build:
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: |
python -m build
- name: Check package
run: |
python -m twine check dist/*
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
publish:
needs: [test, build]
runs-on: ubuntu-latest
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
environment:
name: pypi
url: https://pypi.org/p/mockloop-mcp
permissions:
contents: write
packages: write
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
print-hash: true