# Preloop Open Source - Release Pipeline
# Builds and pushes Docker images to GitHub Container Registry on releases and main branch
name: Release
on:
push:
branches: [main]
tags: ['v*']
release:
types: [published]
env:
REGISTRY: ghcr.io
IMAGE_NAME_BACKEND: ${{ github.repository }}
IMAGE_NAME_FRONTEND: ${{ github.repository }}/frontend
jobs:
# ==========================================================================
# Build and Push Backend Image
# ==========================================================================
build-backend:
name: Build Backend
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
image-tag: ${{ steps.meta.outputs.tags }}
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_BACKEND }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix=
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# ==========================================================================
# Build and Push Frontend Image
# ==========================================================================
build-frontend:
name: Build Frontend
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_FRONTEND }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix=
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ./frontend
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BRAND=preloop
cache-from: type=gha
cache-to: type=gha,mode=max
# ==========================================================================
# Build Python Package (sdist + wheel)
# ==========================================================================
build-python:
name: Build Python Package
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install build tools
run: pip install build
- name: Build package
run: python -m build
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: python-dist
path: dist/
# ==========================================================================
# Build CLI Binaries (cross-compilation)
# ==========================================================================
build-cli:
name: Build CLI (${{ matrix.goos }}/${{ matrix.goarch }})
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
- goos: windows
goarch: arm64
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Build CLI
working-directory: cli
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
VERSION=${GITHUB_REF_NAME#v}
COMMIT=$(git rev-parse --short HEAD)
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
EXT=""
if [ "${{ matrix.goos }}" = "windows" ]; then EXT=".exe"; fi
OUTPUT="preloop-${{ matrix.goos }}-${{ matrix.goarch }}${EXT}"
go build \
-ldflags "-X github.com/preloop/preloop/cli/internal/version.Version=${VERSION} \
-X github.com/preloop/preloop/cli/internal/version.Commit=${COMMIT} \
-X github.com/preloop/preloop/cli/internal/version.BuildDate=${BUILD_DATE}" \
-o "../${OUTPUT}" \
./cmd/preloop
- name: Upload CLI binary
uses: actions/upload-artifact@v4
with:
name: cli-${{ matrix.goos }}-${{ matrix.goarch }}
path: preloop-${{ matrix.goos }}-${{ matrix.goarch }}*
# ==========================================================================
# Publish to PyPI
# ==========================================================================
publish-pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [build-backend, build-frontend, build-python]
if: startsWith(github.ref, 'refs/tags/v')
environment: release
steps:
- name: Download Python artifacts
uses: actions/download-artifact@v4
with:
name: python-dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
# ==========================================================================
# Create GitHub Release (on tag)
# ==========================================================================
create-release:
name: Create Release
runs-on: ubuntu-latest
needs: [build-backend, build-frontend, build-python, build-cli]
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/
- name: Prepare release assets
run: |
mkdir -p release-assets
# Copy Python packages
if [ -d "artifacts/python-dist" ]; then
cp artifacts/python-dist/* release-assets/
fi
# Copy CLI binaries
for dir in artifacts/cli-*; do
[ -d "$dir" ] && cp "$dir"/* release-assets/
done
ls -la release-assets/
- name: Generate changelog
id: changelog
uses: orhun/git-cliff-action@v3
with:
config: cliff.toml
args: --latest --strip header
continue-on-error: true
- name: Compute pip version
id: version
run: echo "pip_version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: release-assets/*
body: |
## Docker Images
```bash
# Backend
docker pull ghcr.io/${{ github.repository }}:${{ github.ref_name }}
# Frontend
docker pull ghcr.io/${{ github.repository }}/frontend:${{ github.ref_name }}
```
## Install CLI
Download the binary for your platform from the assets below, or install via pip:
```bash
pip install preloop==${{ steps.version.outputs.pip_version }}
```
## Changelog
${{ steps.changelog.outputs.content }}
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}