Skip to content

Merge pull request #87 from indrazm/broadcast #236

Merge pull request #87 from indrazm/broadcast

Merge pull request #87 from indrazm/broadcast #236

Workflow file for this run

name: Deploy to Cloudflare Pages & API to G
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
deploy_all:
description: "Deploy all projects regardless of changes"
required: false
default: false
type: boolean
jobs:
check-affected:
runs-on: ubuntu-latest
name: Check Affected Projects
outputs:
admin: ${{ steps.affected.outputs.admin }}
platform: ${{ steps.affected.outputs.platform }}
api: ${{ steps.affected.outputs.api }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup moon
uses: moonrepo/setup-toolchain@v0
- name: Check affected projects
id: affected
run: |
# Check if this is a manual deploy all trigger
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ "${{ github.event.inputs.deploy_all }}" == "true" ]; then
echo "admin=true" >> $GITHUB_OUTPUT
echo "platform=true" >> $GITHUB_OUTPUT
echo "api=true" >> $GITHUB_OUTPUT
echo "Manual deploy all triggered - deploying all projects"
else
# Get affected projects as JSON
AFFECTED=$(moon query projects --affected --json)
# Check if each project is affected
echo "admin=$(echo $AFFECTED | jq -r '.projects | map(select(.id == "admin")) | if length > 0 then "true" else "false" end')" >> $GITHUB_OUTPUT
echo "platform=$(echo $AFFECTED | jq -r '.projects | map(select(.id == "platform")) | if length > 0 then "true" else "false" end')" >> $GITHUB_OUTPUT
echo "api=$(echo $AFFECTED | jq -r '.projects | map(select(.id == "api")) | if length > 0 then "true" else "false" end')" >> $GITHUB_OUTPUT
fi
test-api:
runs-on: ubuntu-latest
needs: check-affected
if: |
needs.check-affected.outputs.api == 'true' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_all == 'true')
name: Test API
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Install dependencies
run: |
cd apps/api
uv sync
- name: Run tests
run: |
cd apps/api
uv run pytest tests/ -v
env:
DB_URL: sqlite:///test.db
deploy-admin:
runs-on: ubuntu-latest
needs: check-affected
if: |
(github.ref == 'refs/heads/main' && needs.check-affected.outputs.admin == 'true') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_all == 'true')
name: Deploy Admin to Cloudflare Pages
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.18.3
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build UI Package
run: pnpm --filter @opencircle/ui build
- name: Build Admin
run: pnpm --filter admin build
env:
VITE_API_URL: ${{ secrets.VITE_API_URL }}
- name: Deploy to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: circle-admin
directory: apps/admin/dist
deploy-platform:
runs-on: ubuntu-latest
needs: check-affected
if: |
(github.ref == 'refs/heads/main' && needs.check-affected.outputs.platform == 'true') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_all == 'true')
name: Deploy Platform to Cloudflare Pages
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.18.3
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build UI Package
run: pnpm --filter @opencircle/ui build
- name: Build Platform
run: pnpm --filter platform build
env:
VITE_API_URL: ${{ secrets.VITE_API_URL }}
- name: Deploy to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: devscale-circle
directory: apps/platform/dist
deploy-api:
runs-on: ubuntu-latest
needs: [test-api, check-affected]
if: |
(github.ref == 'refs/heads/main' &&
needs.check-affected.outputs.api == 'true' &&
needs.test-api.result == 'success') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_all == 'true')
name: Deploy API to Docker Registry
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PAT_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/opencircle-api
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./apps/api/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max