Files
hla_framework_bd/.gitea/workflows/deploy.yml
T
2026-07-30 10:30:06 +02:00

127 lines
3.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
jobs:
define-filters:
runs-on: hla-dev
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
env:
# commit tagged ? yes->prod : no->dev
AGEBD_ENV: ${{ github.ref_type == 'tag' && 'prod' || '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: steps.filter.outputs.bin == 'true'
env:
DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/bin
run: |
mkdir -p ${DEST_DIR}
rsync -av --delete ./bin/ "${DEST_DIR}/"
- name: Agebd - deploy
if: steps.filter.outputs.agebd == 'true'
env:
DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/packages/agebd
run: |
mkdir -p ${DEST_DIR}
rsync -av --delete ./packages/agebd/ "${DEST_DIR}/"
- name: Qt - deploy
if: steps.filter.outputs.qt == 'true'
env:
DEST_DIR: /sls/bd/hla/${{ env.AGEBD_ENV }}/qt
run: |
mkdir -p ${DEST_DIR}
rsync -av --delete ./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: steps.filter.outputs.services == 'true'
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- 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-services
if: ${{ needs.detect-services.outputs.matrix != '[]' }}
strategy:
fail-fast: false
matrix:
service: ${{ fromJson(needs.detect-services.outputs.matrix) }}
uses: ./.gitea/workflows/deploy-service.yml
with:
service_name: ${{ matrix.service }}
environment: ${{ env.AGEBD_ENV }}