From 976426296d42958570d6c7f514940e3fe30ac477 Mon Sep 17 00:00:00 2001 From: Ivanildo Barauna de Souza Junior Date: Mon, 10 Mar 2025 15:47:01 -0300 Subject: [PATCH] chore: workflow to generate releases --- .github/workflows/CD.yaml | 87 +++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 31 deletions(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index a091de0..ad98aa5 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -1,38 +1,63 @@ -name: Publish to PyPI +name: Publish Python Package on: - release: - types: [published] + push: + branches: [ "main" ] - workflow_dispatch: +permissions: + contents: write jobs: - build_publish: + publish: + name: Build and publish to PyPI runs-on: ubuntu-latest + environment: Production + steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.9' - - - name: Install Poetry - run: | - pip install --upgrade pip - curl -sSL https://install.python-poetry.org | python3 - - poetry config virtualenvs.create false - poetry install - - - name: Build package - run: poetry build - - - name: Publish package to PyPI - env: - POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} - run: poetry publish --username __token__ --password $POETRY_PYPI_TOKEN_PYPI - - environment: - name: Production - url: https://pypi.org/project/api-to-dataframe/ + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.6.1 + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Install dependencies + run: | + poetry install --no-interaction + + - name: Extract version + id: extract_version + run: | + VERSION=$(poetry version -s) + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Versão encontrada: $VERSION" + + - name: Build package + run: | + poetry build + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + tag_name: v${{ steps.extract_version.outputs.version }} + name: Release v${{ steps.extract_version.outputs.version }} + draft: false + prerelease: false + files: | + dist/* + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish to PyPI + run: | + poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }} + poetry publish + env: + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} \ No newline at end of file