diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index fedd679..528d89c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,43 +1,69 @@ -name: Build and Push Docker Image to GHCR +name: Build, Push Docker Image & Publish to PyPI -# Trigger the action when pushing to the main branch on: push: branches: - - main + - 'v[0-9]+.[0-9]+.[0-9]+' jobs: - build: + release: runs-on: ubuntu-latest steps: - # Checkout the code from the repository - name: Checkout code uses: actions/checkout@v2 - # Set up Docker Buildx (needed for building Docker images in GitHub Actions) - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - # Login to Docker Hub before building and pushing (good practice) - - name: Login to Docker Hub + - name: Log in to Docker Hub uses: docker/login-action@v2 with: username: rohanbatra password: ${{ secrets.DOCKER_HUB_TOKEN }} - # Build and push Docker image to Docker Hub - - name: Build and Push Docker image (Docker Hub) - run: | - docker build -t rohanbatra/second-brain-database:latest . - docker push rohanbatra/second-brain-database:latest - - - name: Publish to Github Registry - uses: elgohr/Publish-Docker-Github-Action@v5 + - name: Log in to GitHub Container Registry (GHCR) + uses: docker/login-action@v2 with: - name: rohanbatrain/second_brain_database + registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - registry: ghcr.io + - 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 + + - name: Build Python package from pyproject.toml + run: python -m build + - name: Publish package to PyPI + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: twine upload dist/*