Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 44 additions & 18 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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/*
Loading