157 lines
5.3 KiB
YAML
157 lines
5.3 KiB
YAML
name: Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
# TODO: remove
|
|
- feature/add-services-tests-cicd
|
|
tags:
|
|
- 'prod'
|
|
- 'v*'
|
|
paths:
|
|
- 'bin/**'
|
|
- 'packages/agebd/**'
|
|
- 'qt/**'
|
|
- 'services/**'
|
|
|
|
# Cancel previous runs if a new commit is pushed to the same branch
|
|
concurrency:
|
|
group: deploy-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
# commit tagged ? yes->prod : no->dev
|
|
AGEBD_ENV: ${{ github.ref_type == 'tag' && 'prod' || 'dev' }}
|
|
UV_CACHE_DIR: /sls/bd/hla/.cache/uv
|
|
UV_LINK_MODE: copy
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: hla-dev
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # Needed for git diff in service detection
|
|
|
|
- name: Define filter paths
|
|
uses: actions/paths-filter@v3
|
|
id: filter
|
|
with:
|
|
filters: |
|
|
bin:
|
|
- 'bin/**'
|
|
agebd:
|
|
- 'packages/agebd/**'
|
|
qt:
|
|
- 'qt/**'
|
|
services:
|
|
- 'services/**'
|
|
|
|
- name: Install uv
|
|
uses: actions/setup-uv@v5
|
|
enable-cache: true
|
|
cache-local-path: /sls/bd/hla/.cache/uv
|
|
|
|
- name: Install Python 3.10
|
|
run: uv python install 3.10
|
|
|
|
- name: Run core tests
|
|
run: |
|
|
uv run --directory cli pytest
|
|
uv run --directory packages/agebd pytest
|
|
uv run --directory scripts pytest
|
|
|
|
# -----------------------------------------------------------------
|
|
# Directory Deployments
|
|
# -----------------------------------------------------------------
|
|
- name: Bin - deploy
|
|
if: steps.filter.outputs.bin == 'true'
|
|
env:
|
|
DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/bin
|
|
run: |
|
|
rm -rf "${DEST_DIR}"
|
|
mkdir -p "${DEST_DIR}"
|
|
cp -r ./bin/* "${DEST_DIR}/"
|
|
|
|
- name: Agebd - deploy
|
|
if: steps.filter.outputs.agebd == 'true'
|
|
env:
|
|
DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/packages/agebd
|
|
run: |
|
|
rm -rf "${DEST_DIR}"
|
|
mkdir -p "${DEST_DIR}"
|
|
cp -r ./packages/agebd/* "${DEST_DIR}/"
|
|
|
|
- name: Qt - deploy
|
|
if: steps.filter.outputs.qt == 'true'
|
|
env:
|
|
DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/qt
|
|
run: |
|
|
rm -rf "${DEST_DIR}"
|
|
mkdir -p "${DEST_DIR}"
|
|
cp -r ./qt/* "${DEST_DIR}/"
|
|
|
|
# -----------------------------------------------------------------
|
|
# Services Detection, Testing, and Deployment
|
|
# -----------------------------------------------------------------
|
|
- name: Detect Services to Test
|
|
# Run tests for a service if the service changed OR if core package agebd changed
|
|
if: steps.filter.outputs.services == 'true' || steps.filter.outputs.agebd == 'true'
|
|
id: detect-services
|
|
run: |
|
|
# If agebd changed, test ALL services to prevent breaking downstream dependencies
|
|
if [ "${{ steps.filter.outputs.agebd }}" = "true" ]; then
|
|
echo ":packages/agebd changed. Triggering tests for ALL services."
|
|
SERVICES_TO_TEST=$(ls -d services/*/ | xargs -n1 basename | tr '\n' ' ')
|
|
else
|
|
BEFORE="${{ github.event.before }}"
|
|
if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
|
|
BEFORE="HEAD~1"
|
|
fi
|
|
|
|
# Get space-separated list of modified service folder names
|
|
SERVICES_TO_TEST=$(git diff --name-only "$BEFORE" "${{ github.sha }}" | awk -F/ '$1=="services" && $2!="" {print $2}' | sort -u | tr '\n' ' ')
|
|
fi
|
|
|
|
echo "services=$SERVICES_TO_TEST" >> $GITHUB_OUTPUT
|
|
echo "Services queued for testing: $SERVICES_TO_TEST"
|
|
|
|
- name: Test Services
|
|
if: steps.detect-services.outputs.services != ''
|
|
run: |
|
|
SERVICES="${{ steps.detect-services.outputs.services }}"
|
|
|
|
for SERVICE in $SERVICES; do
|
|
SERVICE_DIR="services/$SERVICE"
|
|
if [ -d "$SERVICE_DIR/tests" ]; then
|
|
echo "=========================================="
|
|
echo "Running tests for: $SERVICE"
|
|
echo "=========================================="
|
|
|
|
uv run --directory "$SERVICE_DIR" pytest
|
|
else
|
|
echo "Skipping $SERVICE (no tests directory found)..."
|
|
fi
|
|
done
|
|
|
|
- name: Deploy Changed Services
|
|
# ONLY deploy services that explicitly had file changes (prevents redeploying all services if only agebd changed)
|
|
if: steps.filter.outputs.services == 'true'
|
|
run: |
|
|
BEFORE="${{ github.event.before }}"
|
|
if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
|
|
BEFORE="HEAD~1"
|
|
fi
|
|
|
|
CHANGED_SERVICES=$(git diff --name-only "$BEFORE" "${{ github.sha }}" | awk -F/ '$1=="services" && $2!="" {print $2}' | sort -u)
|
|
|
|
for SERVICE in $CHANGED_SERVICES; do
|
|
echo "=========================================="
|
|
echo "Deploying service: $SERVICE (${AGEBD_ENV})"
|
|
echo "=========================================="
|
|
./.gitea/scripts/deploy-and-restart-service.sh "${SERVICE}" "${AGEBD_ENV}"
|
|
done
|