diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 3c248c9..ecf4335 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -15,7 +15,7 @@ on: - 'qt/**' - 'services/**' -# 1. Cancel previous runs if a new commit is pushed to the same branch +# Cancel previous runs if a new commit is pushed to the same branch concurrency: group: deploy-${{ github.ref }} cancel-in-progress: true @@ -25,21 +25,17 @@ env: AGEBD_ENV: ${{ github.ref_type == 'tag' && 'prod' || 'dev' }} jobs: - define-filters: + deploy: runs-on: hla-dev - outputs: - bin: ${{ steps.filter.outputs.bin }} - agebd: ${{ steps.filter.outputs.agebd }} - qt: ${{ steps.filter.outputs.qt }} - services: ${{ steps.filter.outputs.services }} - steps: - name: Checkout repository uses: actions/checkout@v4 + with: + fetch-depth: 0 # Needed for git diff in service detection - - name: Defined filter paths - uses: actions/paths-filter@v3 # see: https://gitea.psi.ch/actions/paths-filter + - name: Define filter paths + uses: actions/paths-filter@v3 id: filter with: filters: | @@ -52,16 +48,8 @@ jobs: services: - 'services/**' - deploy: - needs: define-filters - runs-on: hla-dev - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Install uv - uses: actions/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 + uses: actions/setup-uv@v5 - name: Install Python 3.10 run: uv python install 3.10 @@ -70,80 +58,58 @@ jobs: run: | cd scripts && uv run pytest + # ----------------------------------------------------------------- + # Directory Deployments + # ----------------------------------------------------------------- - name: Bin - deploy - if: needs.define-filters.outputs.bin == 'true' + if: steps.filter.outputs.bin == 'true' env: DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/bin run: | - mkdir -p ${DEST_DIR} + mkdir -p "${DEST_DIR}" rsync -av --delete --exclude='.nfs*' ./bin/ "${DEST_DIR}/" - name: Agebd - deploy - if: needs.define-filters.outputs.agebd == 'true' + if: steps.filter.outputs.agebd == 'true' env: DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/packages/agebd run: | - mkdir -p ${DEST_DIR} + mkdir -p "${DEST_DIR}" rsync -av --delete --exclude='.nfs*' ./packages/agebd/ "${DEST_DIR}/" - name: Qt - deploy - if: needs.define-filters.outputs.qt == 'true' + if: steps.filter.outputs.qt == 'true' env: DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/qt run: | - mkdir -p ${DEST_DIR} + mkdir -p "${DEST_DIR}" rsync -av --delete --exclude='.nfs*' ./qt/ "${DEST_DIR}/" - # TODO: (when) do we need to restart the master service or reinstall/restart the master ioc? - - detect-changed-services: - runs-on: hla-dev - needs: define-filters - if: needs.define-filters.outputs.services == 'true' - - outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Generate matrix of changed services - id: set-matrix + # ----------------------------------------------------------------- + # Services Deployment + # ----------------------------------------------------------------- + - name: Deploy Changed Services + if: steps.filter.outputs.services == 'true' run: | - # Fallback if github.event.before is zeroed out (e.g. initial branch push or tag) + # 1. Determine git comparison point BEFORE="${{ github.event.before }}" if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then BEFORE="HEAD~1" fi - - # Generate JSON array of changed service folders - SERVICES=$(git diff --name-only "$BEFORE" "${{ github.sha }}" | awk -F/ '$1=="services" {print $2}' | sort -u | jq -R . | jq -s -c .) - echo "matrix=$SERVICES" >> $GITHUB_OUTPUT - deploy-services: - needs: detect-changed-services - runs-on: hla-dev - if: needs.detect-changed-services.outputs.matrix != '[]' && needs.detect-changed-services.outputs.matrix != '' - steps: - - name: Checkout repository - uses: actions/checkout@v4 + # 2. Extract list of modified service folder names + CHANGED_SERVICES=$(git diff --name-only "$BEFORE" "${{ github.sha }}" | awk -F/ '$1=="services" && $2!="" {print $2}' | sort -u) - - name: Deploy Changed Services - run: | - # Parse JSON array produced by detect-changed-services - SERVICES_JSON='${{ needs.detect-changed-services.outputs.matrix }}' - - echo "Services to deploy: $SERVICES_JSON" - - # Iterate over each service and deploy - echo "$SERVICES_JSON" | jq -r '.[]' | while read -r SERVICE; do - if [ -z "$SERVICE" ]; then continue; fi - + if [ -z "$CHANGED_SERVICES" ]; then + echo "No service directory changes detected in diff." + exit 0 + fi + + # 3. Loop through changed services and invoke deployment script + echo "$CHANGED_SERVICES" | while read -r SERVICE; do echo "==========================================" - echo "Deploying service: $SERVICE (${{ env.AGEBD_ENV }})" + echo "Deploying service: ${SERVICE} (${AGEBD_ENV})" echo "==========================================" - ./.gitea/scripts/deploy-service.sh ${SERVICE} ${{ env.AGEBD_ENV }} + ./.gitea/scripts/deploy-service.sh "${SERVICE}" "${AGEBD_ENV}" done