Skip to content

Commit d7853e3

Browse files
committed
add scripts and ci
1 parent 381b9bd commit d7853e3

17 files changed

Lines changed: 1284 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
release:
9+
types: [created]
10+
11+
jobs:
12+
lint:
13+
name: Lint
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
service: [server]
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: '3.11'
27+
cache: 'pip'
28+
29+
- name: Install dependencies
30+
working-directory: ./services/${{ matrix.service }}
31+
run: |
32+
python -m pip install --upgrade pip
33+
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
34+
if [ -f requirements-server.txt ]; then pip install -r requirements-server.txt; fi
35+
pip install pre-commit
36+
37+
- name: Run pre-commit
38+
working-directory: ./services/${{ matrix.service }}
39+
run: |
40+
if [ -f .pre-commit-config.yaml ]; then
41+
pre-commit run --all-files
42+
else
43+
echo "No pre-commit config found, running basic linting"
44+
chmod +x ../../s/ci/lint.sh ../../s/lib.sh
45+
cd ../..
46+
./s/ci/lint.sh ${{ matrix.service }} || true
47+
fi
48+
49+
detect-changes:
50+
name: Detect Changed Services
51+
runs-on: ubuntu-latest
52+
outputs:
53+
services: ${{ steps.changes.outputs.services }}
54+
steps:
55+
- name: Checkout repository
56+
uses: actions/checkout@v4
57+
with:
58+
fetch-depth: 0
59+
60+
- name: Detect changed services
61+
id: changes
62+
run: |
63+
if [ "${{ github.event_name }}" == "pull_request" ]; then
64+
BASE=${{ github.event.pull_request.base.sha }}
65+
HEAD=${{ github.sha }}
66+
else
67+
BASE=${{ github.event.before }}
68+
HEAD=${{ github.sha }}
69+
fi
70+
71+
CHANGED_SERVICES="[]"
72+
for svc in server bot ai chronos sockets scheduler; do
73+
if git diff --name-only $BASE $HEAD | grep -q "^services/$svc/"; then
74+
CHANGED_SERVICES=$(echo $CHANGED_SERVICES | jq -c ". + [\"$svc\"]")
75+
fi
76+
done
77+
78+
echo "services=$CHANGED_SERVICES" >> $GITHUB_OUTPUT
79+
echo "Changed services: $CHANGED_SERVICES"
80+
81+
build:
82+
name: Build Docker Images
83+
needs: detect-changes
84+
if: needs.detect-changes.outputs.services != '[]'
85+
runs-on: ubuntu-latest
86+
strategy:
87+
fail-fast: false
88+
matrix:
89+
service: ${{ fromJson(needs.detect-changes.outputs.services) }}
90+
steps:
91+
- name: Checkout repository
92+
uses: actions/checkout@v4
93+
94+
- name: Set up Docker Buildx
95+
uses: docker/setup-buildx-action@v3
96+
97+
- name: Build Docker image (no push)
98+
uses: docker/build-push-action@v5
99+
with:
100+
context: ./services/${{ matrix.service }}
101+
push: false
102+
tags: swecc-${{ matrix.service }}:test
103+
cache-from: type=gha
104+
cache-to: type=gha,mode=max
105+

.github/workflows/deploy-ai.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Deploy AI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
paths:
7+
- 'services/ai/**'
8+
- 's/ops/**'
9+
- 's/lib.sh'
10+
- '.github/workflows/deploy-ai.yml'
11+
- '.github/workflows/reusable-deploy.yml'
12+
workflow_dispatch:
13+
14+
jobs:
15+
deploy:
16+
uses: ./.github/workflows/reusable-deploy.yml
17+
with:
18+
service: ai
19+
secrets:
20+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
21+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
22+

.github/workflows/deploy-all.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Deploy All Services
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
confirm:
7+
description: 'Type "deploy-all" to confirm deployment of all services'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
validate:
13+
name: Validate Confirmation
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check confirmation
17+
if: inputs.confirm != 'deploy-all'
18+
run: |
19+
echo "Deployment cancelled. You must type 'deploy-all' to confirm."
20+
exit 1
21+
22+
deploy-server:
23+
name: Deploy Server
24+
needs: validate
25+
uses: ./.github/workflows/reusable-deploy.yml
26+
with:
27+
service: server
28+
secrets:
29+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
30+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
31+
32+
deploy-bot:
33+
name: Deploy Bot
34+
needs: validate
35+
uses: ./.github/workflows/reusable-deploy.yml
36+
with:
37+
service: bot
38+
secrets:
39+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
40+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
41+
42+
deploy-ai:
43+
name: Deploy AI
44+
needs: validate
45+
uses: ./.github/workflows/reusable-deploy.yml
46+
with:
47+
service: ai
48+
secrets:
49+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
50+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
51+
52+
deploy-chronos:
53+
name: Deploy Chronos
54+
needs: validate
55+
uses: ./.github/workflows/reusable-deploy.yml
56+
with:
57+
service: chronos
58+
secrets:
59+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
60+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
61+
62+
deploy-sockets:
63+
name: Deploy Sockets
64+
needs: validate
65+
uses: ./.github/workflows/reusable-deploy.yml
66+
with:
67+
service: sockets
68+
secrets:
69+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
70+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
71+
72+
deploy-scheduler:
73+
name: Deploy Scheduler
74+
needs: validate
75+
uses: ./.github/workflows/reusable-deploy.yml
76+
with:
77+
service: scheduler
78+
secrets:
79+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
80+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
81+
82+
summary:
83+
name: Deployment Summary
84+
needs: [deploy-server, deploy-bot, deploy-ai, deploy-chronos, deploy-sockets, deploy-scheduler]
85+
runs-on: ubuntu-latest
86+
if: always()
87+
steps:
88+
- name: Summary
89+
run: |
90+
echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY
91+
echo "" >> $GITHUB_STEP_SUMMARY
92+
echo "| Service | Status |" >> $GITHUB_STEP_SUMMARY
93+
echo "|---------|--------|" >> $GITHUB_STEP_SUMMARY
94+
echo "| Server | ${{ needs.deploy-server.result }} |" >> $GITHUB_STEP_SUMMARY
95+
echo "| Bot | ${{ needs.deploy-bot.result }} |" >> $GITHUB_STEP_SUMMARY
96+
echo "| AI | ${{ needs.deploy-ai.result }} |" >> $GITHUB_STEP_SUMMARY
97+
echo "| Chronos | ${{ needs.deploy-chronos.result }} |" >> $GITHUB_STEP_SUMMARY
98+
echo "| Sockets | ${{ needs.deploy-sockets.result }} |" >> $GITHUB_STEP_SUMMARY
99+
echo "| Scheduler | ${{ needs.deploy-scheduler.result }} |" >> $GITHUB_STEP_SUMMARY
100+

.github/workflows/deploy-bot.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Deploy Bot
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
paths:
7+
- 'services/bot/**'
8+
- 's/ops/**'
9+
- 's/lib.sh'
10+
- '.github/workflows/deploy-bot.yml'
11+
- '.github/workflows/reusable-deploy.yml'
12+
workflow_dispatch:
13+
14+
jobs:
15+
deploy:
16+
uses: ./.github/workflows/reusable-deploy.yml
17+
with:
18+
service: bot
19+
secrets:
20+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
21+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Deploy Chronos
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
paths:
7+
- 'services/chronos/**'
8+
- 's/ops/**'
9+
- 's/lib.sh'
10+
- '.github/workflows/deploy-chronos.yml'
11+
- '.github/workflows/reusable-deploy.yml'
12+
workflow_dispatch:
13+
14+
jobs:
15+
deploy:
16+
uses: ./.github/workflows/reusable-deploy.yml
17+
with:
18+
service: chronos
19+
secrets:
20+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
21+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Deploy Scheduler
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
paths:
7+
- 'services/scheduler/**'
8+
- 's/ops/**'
9+
- 's/lib.sh'
10+
- '.github/workflows/deploy-scheduler.yml'
11+
- '.github/workflows/reusable-deploy.yml'
12+
workflow_dispatch:
13+
14+
jobs:
15+
deploy:
16+
uses: ./.github/workflows/reusable-deploy.yml
17+
with:
18+
service: scheduler
19+
secrets:
20+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
21+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
22+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Deploy Server
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
paths:
7+
- 'services/server/**'
8+
- '!services/server/rabbit_listener.py'
9+
- 's/ops/**'
10+
- 's/lib.sh'
11+
- '.github/workflows/deploy-server.yml'
12+
- '.github/workflows/reusable-deploy.yml'
13+
workflow_dispatch:
14+
15+
jobs:
16+
deploy:
17+
uses: ./.github/workflows/reusable-deploy.yml
18+
with:
19+
service: server
20+
secrets:
21+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
22+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
23+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Deploy Sockets
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
paths:
7+
- 'services/sockets/**'
8+
- 's/ops/**'
9+
- 's/lib.sh'
10+
- '.github/workflows/deploy-sockets.yml'
11+
- '.github/workflows/reusable-deploy.yml'
12+
workflow_dispatch:
13+
14+
jobs:
15+
deploy:
16+
uses: ./.github/workflows/reusable-deploy.yml
17+
with:
18+
service: sockets
19+
secrets:
20+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
21+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
22+

0 commit comments

Comments
 (0)