Publishing to PyPI

Este documento descreve como publicar o pacote django-rule-engine no PyPI usando GitHub Actions.

Configuração Inicial

1. Configurar Trusted Publishing no PyPI

O workflow usa o método de “Trusted Publishing” (OIDC) do PyPI, mais seguro que tokens longos.

Para PyPI (produção)

  1. Acesse https://pypi.org/manage/account/publishing/

  2. Clique em “Add a new pending publisher”

  3. Preencha:

    • PyPI Project Name: django-rule-engine

    • Owner: kelsoncm

    • Repository name: django-rule-engine

    • Workflow name: publish-to-pypi.yml

    • Environment name: pypi

  4. Clique em “Add”

Para TestPyPI (testes)

  1. Acesse https://test.pypi.org/manage/account/publishing/

  2. Siga os mesmos passos acima, mas com:

    • Environment name: testpypi

2. Configurar Environments no GitHub

  1. Vá para Settings → Environments no seu repositório GitHub

  2. Crie dois environments:

    • pypi - para publicação em produção

    • testpypi - para testes

Como Publicar

Método 1: Publicação Automática (Release)

A forma recomendada é criar uma release no GitHub:

  1. Atualize a versão no arquivo pyproject.toml e src/django_rule_engine/__init__.py

  2. Commit e push das mudanças

  3. Crie uma tag de versão:

    git tag v1.0.1
    git push origin v1.0.1
    
  4. Vá para GitHub → Releases → “Create a new release”

  5. Selecione a tag criada e clique em “Publish release”

Método 2: Publicação Manual

Para testar no TestPyPI ou forçar uma publicação manual:

  1. Vá para Actions → “Publish to PyPI” → “Run workflow”

  2. Escolha a branch e a opção test_pypi se for um teste.

Testando a Publicação

# Instalar do TestPyPI
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ django-rule-engine

# Testar a instalação
python -c "import django_rule_engine; print(django_rule_engine.__version__)"