name: Deploy on: push: branches: - main 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: /var/cache/uv UV_LINK_MODE: hardlink 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: Run core tests run: | echo $UV_CACHE_DIR 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: | # TODO: see https://gitea.psi.ch/sls/hla_framework_bd/issues/50 # rm -rf "${DEST_DIR}" # mkdir -p "${DEST_DIR}" # cp -r ./bin/* "${DEST_DIR}/" rsync -avz --delete \ --exclude='.nfs*' \ --exclude='.git/' \ --exclude='.venv/' \ --exclude='__pycache__/' \ --exclude='*.pyc' \ --exclude='.pytest_cache/' \ ./bin/* "${DEST_DIR}/" - name: Agebd - deploy if: steps.filter.outputs.agebd == 'true' env: DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/packages/agebd run: | # TODO: see https://gitea.psi.ch/sls/hla_framework_bd/issues/50 # rm -rf "${DEST_DIR}" # mkdir -p "${DEST_DIR}" # cp -r ./packages/agebd/* "${DEST_DIR}/" rsync -avz --delete \ --exclude='.nfs*' \ --exclude='.git/' \ --exclude='.venv/' \ --exclude='__pycache__/' \ --exclude='*.pyc' \ --exclude='.pytest_cache/' \ ./packages/agebd/* "${DEST_DIR}/" - name: Qt - deploy if: steps.filter.outputs.qt == 'true' env: DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/qt run: | # TODO: see https://gitea.psi.ch/sls/hla_framework_bd/issues/50 # rm -rf "${DEST_DIR}" # mkdir -p "${DEST_DIR}" # cp -r ./qt/* "${DEST_DIR}/" rsync -avz --delete \ --exclude='.nfs*' \ --exclude='.git/' \ --exclude='.venv/' \ --exclude='__pycache__/' \ --exclude='*.pyc' \ --exclude='.pytest_cache/' \ ./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_APP_DIR="services/$SERVICE/current/app" if [ -d "$SERVICE_APP_DIR" ]; then echo "==========================================" echo "Running tests for: $SERVICE_APP_DIR" echo "==========================================" uv run --directory "$SERVICE_APP_DIR" pytest 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 ./.gitea/scripts/deploy-and-restart-service.sh "${SERVICE}" "${AGEBD_ENV}" done