Update pypi.yml #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build, Push Docker Image & Publish to PyPI | |
| permissions: | |
| contents: read | |
| packages: write | |
| on: | |
| push: | |
| branches: | |
| - 'v[0-9]+.[0-9]+.[0-9]+' | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: rohanbatra | |
| password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
| - name: Log in to GitHub Container Registry (GHCR) | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract version from branch | |
| id: extract_version | |
| run: | | |
| VERSION=${GITHUB_REF#refs/heads/v} | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "Extracted version: $VERSION" | |
| - name: Inject version into pyproject.toml | |
| run: | | |
| sed -i "s/^version = \".*\"/version = \"${VERSION}\"/" pyproject.toml | |
| echo "Updated version in pyproject.toml to $VERSION" | |
| - name: Build and push Docker image (Docker Hub) | |
| run: | | |
| docker build -t rohanbatra/second-brain-database:${{ env.VERSION }} . | |
| docker push rohanbatra/second-brain-database:${{ env.VERSION }} | |
| - name: Push Docker image to GHCR | |
| run: | | |
| docker tag rohanbatra/second-brain-database:${{ env.VERSION }} ghcr.io/rohanbatrain/second_brain_database:${{ env.VERSION }} | |
| docker push ghcr.io/rohanbatrain/second_brain_database:${{ env.VERSION }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install build & twine | |
| run: pip install build twine pytest pytest-cov pylint | |
| - name: Build Python package from pyproject.toml | |
| run: python -m build | |
| - name: Install python packages | |
| run: pip install -r requirements.txt | |
| - name: Linting | |
| run: pylint src/second_brain_database | |
| - name: Run tests and generate coverage report | |
| run: pytest --cov --cov-branch --cov-report=xml | |
| - name: Publish package to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: twine upload dist/* | |