150 lines
4.4 KiB
YAML
150 lines
4.4 KiB
YAML
name: Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
# TODO: remove
|
|
- chore/migrate-ansible-logic-to-workflow-steps
|
|
tags:
|
|
- 'prod'
|
|
- 'v*'
|
|
paths:
|
|
- 'bin/**'
|
|
- 'packages/agebd/**'
|
|
- 'qt/**'
|
|
- 'services/**'
|
|
|
|
# 1. 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' }}
|
|
|
|
jobs:
|
|
define-filters:
|
|
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
|
|
|
|
- name: Defined filter paths
|
|
uses: actions/paths-filter@v3 # see: https://gitea.psi.ch/actions/paths-filter
|
|
id: filter
|
|
with:
|
|
filters: |
|
|
bin:
|
|
- 'bin/**'
|
|
agebd:
|
|
- 'packages/agebd/**'
|
|
qt:
|
|
- 'qt/**'
|
|
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
|
|
|
|
- name: Install Python 3.10
|
|
run: uv python install 3.10
|
|
|
|
- name: Run tests
|
|
run: |
|
|
cd scripts && uv run pytest
|
|
|
|
- name: Bin - deploy
|
|
if: needs.define-filters.outputs.bin == 'true'
|
|
env:
|
|
DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/bin
|
|
run: |
|
|
mkdir -p ${DEST_DIR}
|
|
rsync -av --delete --exclude='.nfs*' ./bin/ "${DEST_DIR}/"
|
|
|
|
- name: Agebd - deploy
|
|
if: needs.define-filters.outputs.agebd == 'true'
|
|
env:
|
|
DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/packages/agebd
|
|
run: |
|
|
mkdir -p ${DEST_DIR}
|
|
rsync -av --delete --exclude='.nfs*' ./packages/agebd/ "${DEST_DIR}/"
|
|
|
|
- name: Qt - deploy
|
|
if: needs.define-filters.outputs.qt == 'true'
|
|
env:
|
|
DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/qt
|
|
run: |
|
|
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
|
|
run: |
|
|
# Fallback if github.event.before is zeroed out (e.g. initial branch push or tag)
|
|
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
|
|
|
|
- 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
|
|
|
|
echo "=========================================="
|
|
echo "Deploying service: $SERVICE (${{ env.AGEBD_ENV }})"
|
|
echo "=========================================="
|
|
|
|
./.gitea/scripts/deploy-service.sh ${SERVICE} ${{ env.AGEBD_ENV }}
|
|
done
|