name: Release → (Test)PyPI + GitHub Assets on: release: types: [released, prereleased] # published normal release и pre-release jobs: build-and-publish: runs-on: ubuntu-latest env: PYTHON_VERSION: "3.12" steps: - name: Checkout uses: actions/checkout@v4 - name: Set variables from Release tag id: meta run: | TAG="${{ github.event.release.tag_name }}" # e.g. v0.1.0 or 0.1.0 VERSION="${TAG#v}" # strip leading 'v' if present echo "version=$VERSION" >> $GITHUB_OUTPUT if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then echo "repo=testpypi" >> $GITHUB_OUTPUT else echo "repo=pypi" >> $GITHUB_OUTPUT fi echo "Resolved: version=$VERSION repo=$(cat $GITHUB_OUTPUT | grep repo | cut -d= -f2)" - name: Set up Python uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_VERSION }} - name: Install Poetry run: pipx install "poetry==1.8.3" - name: Show Poetry version run: poetry --version - name: Cache Poetry & pip uses: actions/cache@v4 with: path: | ~/.cache/pypoetry ~/.cache/pip key: poetry-${{ runner.os }}-${{ env.PYTHON_VERSION }}-**1.8.3**-${{ hashFiles('**/poetry.lock') }} restore-keys: | poetry-${{ runner.os }}-${{ env.PYTHON_VERSION }}-**1.8.3**- - name: Install deps (no dev) run: poetry install --no-interaction --no-root --only main - name: Sync version into pyproject.toml run: poetry version ${{ steps.meta.outputs.version }} - name: Build sdist + wheel run: poetry build --no-interaction # (опционально) Быстрая проверка метаданных пакета перед публикацией - name: Twine check run: | python -m pip install --upgrade twine twine check dist/* # Настройка репозиториев/токенов Poetry - name: Configure TestPyPI if: ${{ steps.meta.outputs.repo == 'testpypi' }} run: | poetry config repositories.testpypi https://test.pypi.org/legacy/ poetry config pypi-token.testpypi ${{ secrets.TEST_PYPI_API_TOKEN }} - name: Configure PyPI if: ${{ steps.meta.outputs.repo == 'pypi' }} run: | poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }} # Публикация - name: Publish to TestPyPI if: ${{ steps.meta.outputs.repo == 'testpypi' }} run: poetry publish -r testpypi --no-interaction - name: Publish to PyPI if: ${{ steps.meta.outputs.repo == 'pypi' }} run: poetry publish --no-interaction # Прикрепляем артефакты к странице GitHub Release - name: Upload artifacts to GitHub Release uses: softprops/action-gh-release@v2 with: tag_name: ${{ github.event.release.tag_name }} files: | dist/*.whl dist/*.tar.gz # (опционально) также сохраняем артефакты в job artifacts - name: Upload build artifacts (job) uses: actions/upload-artifact@v4 with: name: dist-${{ steps.meta.outputs.version }} path: dist/ if-no-files-found: error