Skip to content
Merged
Show file tree
Hide file tree
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
111 changes: 111 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: CD

on:
workflow_run:
workflows: ["CI"]
types:
- completed

permissions:
contents: write

jobs:
update-manifests:
name: Update Kubernetes Manifests

runs-on: ubuntu-latest

if: |
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main'

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: main

- name: Download Changed Services
uses: dawidd6/action-download-artifact@v6
with:
workflow: ci.yml
run_id: ${{ github.event.workflow_run.id }}
name: changed-services
path: changed

- name: Check Changed Services
id: changed
shell: bash
run: |
if [ ! -d changed ]; then
echo "deploy=false" >> $GITHUB_OUTPUT
exit 0
fi

if grep -Rq "true" changed; then
echo "deploy=true" >> $GITHUB_OUTPUT
else
echo "deploy=false" >> $GITHUB_OUTPUT
fi

- name: Configure Git
if: steps.changed.outputs.deploy == 'true'
run: |
git config user.name github-actions
git config user.email github-actions@github.com

- name: Update Image Tags
if: steps.changed.outputs.deploy == 'true'
shell: bash
run: |
VERSION=v1.2.${{ github.event.workflow_run.run_number }}

if [ "$(cat changed/backend)" = "true" ]; then
sed -i "s|image: krishanand01/axion-backend:.*|image: krishanand01/axion-backend:$VERSION|g" ops/deployment.yml
fi

if [ "$(cat changed/frontend)" = "true" ]; then
sed -i "s|image: krishanand01/axion-frontend:.*|image: krishanand01/axion-frontend:$VERSION|g" ops/deployment.yml
fi

if [ "$(cat changed/worker)" = "true" ]; then
sed -i "s|image: krishanand01/axion-worker:.*|image: krishanand01/axion-worker:$VERSION|g" ops/deployment.yml
fi

if [ "$(cat changed/ws-relayer)" = "true" ]; then
sed -i "s|image: krishanand01/axion-ws-relayer:.*|image: krishanand01/axion-ws-relayer:$VERSION|g" ops/deployment.yml
fi

if [ "$(cat changed/depin-ws-relayer)" = "true" ]; then
sed -i "s|image: krishanand01/axion-depin-ws-relayer:.*|image: krishanand01/axion-depin-ws-relayer:$VERSION|g" ops/deployment.yml
fi

if [ "$(cat changed/indexer)" = "true" ]; then
sed -i "s|image: krishanand01/axion-indexer:.*|image: krishanand01/axion-indexer:$VERSION|g" ops/deployment.yml
fi

- name: Check For Manifest Changes
if: steps.changed.outputs.deploy == 'true'
id: gitcheck
shell: bash
run: |
if git diff --quiet ops/deployment.yml; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi

- name: Commit Changes
if: |
steps.changed.outputs.deploy == 'true' &&
steps.gitcheck.outputs.changed == 'true'
run: |
git add ops/deployment.yml
git commit -m "chore: update image tags to v1.2.${{ github.event.workflow_run.run_number }}"

- name: Push Changes
if: |
steps.changed.outputs.deploy == 'true' &&
steps.gitcheck.outputs.changed == 'true'
run: |
git push origin main
268 changes: 268 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
name: CI

on:
pull_request:
paths:
- "apps/**"
- "packages/**"
- "indexer/**"
- "docker/**"
- ".github/workflows/**"
- "turbo.json"
- "package.json"
- "bun.lock"

push:
branches:
- main
paths:
- "apps/**"
- "packages/**"
- "indexer/**"
- "docker/**"
- ".github/workflows/**"
- "turbo.json"
- "package.json"
- "bun.lock"

permissions:
contents: read

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
quality:
name: Lint / Build
runs-on: ubuntu-latest
timeout-minutes: 20

defaults:
run:
working-directory: web-services

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Cache Bun Dependencies
uses: actions/cache@v4
with:
path: |
~/.bun/install/cache
node_modules
.turbo
key: ${{ runner.os }}-bun-${{ hashFiles('web-services/bun.lock') }}

- name: Install Dependencies
run: bun install

- name: Run Lint
run: bun run lint

- name: Run Build
run: bun run build

detect-changes:
name: Detect Changed Services
runs-on: ubuntu-latest
needs: quality

outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
worker: ${{ steps.filter.outputs.worker }}
ws-relayer: ${{ steps.filter.outputs.ws-relayer }}
depin-ws-relayer: ${{ steps.filter.outputs.depin-ws-relayer }}
indexer: ${{ steps.filter.outputs.indexer }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Detect Changed Files
id: filter
shell: bash
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
else
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
fi

echo "$CHANGED_FILES"

echo "backend=false" >> $GITHUB_OUTPUT
echo "frontend=false" >> $GITHUB_OUTPUT
echo "worker=false" >> $GITHUB_OUTPUT
echo "ws-relayer=false" >> $GITHUB_OUTPUT
echo "depin-ws-relayer=false" >> $GITHUB_OUTPUT
echo "indexer=false" >> $GITHUB_OUTPUT

if echo "$CHANGED_FILES" | grep -q '^web-services/apps/backend/'; then
echo "backend=true" >> $GITHUB_OUTPUT
fi

if echo "$CHANGED_FILES" | grep -q '^web-services/apps/frontend/'; then
echo "frontend=true" >> $GITHUB_OUTPUT
fi

if echo "$CHANGED_FILES" | grep -q '^web-services/apps/worker/'; then
echo "worker=true" >> $GITHUB_OUTPUT
fi

if echo "$CHANGED_FILES" | grep -q '^web-services/apps/ws-relayer/'; then
echo "ws-relayer=true" >> $GITHUB_OUTPUT
fi

if echo "$CHANGED_FILES" | grep -q '^web-services/apps/depin-ws-relayer/'; then
echo "depin-ws-relayer=true" >> $GITHUB_OUTPUT
fi

if echo "$CHANGED_FILES" | grep -q '^indexer/'; then
echo "indexer=true" >> $GITHUB_OUTPUT
fi

if echo "$CHANGED_FILES" | grep -q '^web-services/docker/backend.dockerfile'; then
echo "backend=true" >> $GITHUB_OUTPUT
fi

if echo "$CHANGED_FILES" | grep -q '^web-services/docker/frontend.dockerfile'; then
echo "frontend=true" >> $GITHUB_OUTPUT
fi

if echo "$CHANGED_FILES" | grep -q '^web-services/docker/worker.dockerfile'; then
echo "worker=true" >> $GITHUB_OUTPUT
fi

if echo "$CHANGED_FILES" | grep -q '^web-services/docker/ws-relayer.dockerfile'; then
echo "ws-relayer=true" >> $GITHUB_OUTPUT
fi

if echo "$CHANGED_FILES" | grep -q '^web-services/docker/depin-ws-relayer.dockerfile'; then
echo "depin-ws-relayer=true" >> $GITHUB_OUTPUT
fi

if echo "$CHANGED_FILES" | grep -q '^indexer/Dockerfile'; then
echo "indexer=true" >> $GITHUB_OUTPUT
fi

if echo "$CHANGED_FILES" | grep -q '^web-services/packages/'; then
echo "backend=true" >> $GITHUB_OUTPUT
echo "frontend=true" >> $GITHUB_OUTPUT
echo "worker=true" >> $GITHUB_OUTPUT
echo "ws-relayer=true" >> $GITHUB_OUTPUT
echo "depin-ws-relayer=true" >> $GITHUB_OUTPUT
fi

- name: Save Changed Services
run: |
mkdir -p changed

echo '${{ steps.filter.outputs.backend }}' > changed/backend
echo '${{ steps.filter.outputs.frontend }}' > changed/frontend
echo '${{ steps.filter.outputs.worker }}' > changed/worker
echo '${{ steps.filter.outputs.ws-relayer }}' > changed/ws-relayer
echo '${{ steps.filter.outputs.depin-ws-relayer }}' > changed/depin-ws-relayer
echo '${{ steps.filter.outputs.indexer }}' > changed/indexer

- name: Upload Changed Services
uses: actions/upload-artifact@v4
with:
name: changed-services
path: changed/

docker-build:
name: Docker Build & Push
runs-on: ubuntu-latest

needs:
- quality
- detect-changes

if: |
github.event_name == 'push' &&
github.ref == 'refs/heads/main'

strategy:
fail-fast: false

matrix:
include:
- service: backend
dockerfile: web-services/docker/backend.dockerfile
context: web-services
image: axion-backend
changed: ${{ needs.detect-changes.outputs.backend }}

- service: frontend
dockerfile: web-services/docker/frontend.dockerfile
context: web-services
image: axion-frontend
changed: ${{ needs.detect-changes.outputs.frontend }}

- service: worker
dockerfile: web-services/docker/worker.dockerfile
context: web-services
image: axion-worker
changed: ${{ needs.detect-changes.outputs.worker }}

- service: ws-relayer
dockerfile: web-services/docker/ws-relayer.dockerfile
context: web-services
image: axion-ws-relayer
changed: ${{ needs.detect-changes.outputs.ws-relayer }}

- service: depin-ws-relayer
dockerfile: web-services/docker/depin-ws-relayer.dockerfile
context: web-services
image: axion-depin-ws-relayer
changed: ${{ needs.detect-changes.outputs.depin-ws-relayer }}

- service: indexer
dockerfile: indexer/Dockerfile
context: indexer
image: axion-indexer
changed: ${{ needs.detect-changes.outputs.indexer }}

steps:
- name: Checkout
if: matrix.changed == 'true'
uses: actions/checkout@v4

- name: Setup Docker Buildx
if: matrix.changed == 'true'
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
if: matrix.changed == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Push
if: matrix.changed == 'true'
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
push: true

build-args: |
${{ matrix.service == 'frontend' && format('VITE_BACKEND_URL={0}', secrets.BACKEND_URL) || '' }}

tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.image }}:latest
${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.image }}:v1.2.${{ github.run_number }}

cache-from: type=gha
cache-to: type=gha,mode=max
Loading
Loading