104 lines
3.5 KiB
YAML
104 lines
3.5 KiB
YAML
name: Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- 'prod'
|
|
- 'v*'
|
|
paths:
|
|
- 'bin/**'
|
|
- 'packages/agebd/**'
|
|
- 'services/**'
|
|
|
|
|
|
jobs:
|
|
deploy:
|
|
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
|
|
with:
|
|
fetch-depth: 2 # needed for git diff tracking
|
|
|
|
- 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/**'
|
|
services:
|
|
- 'services/**'
|
|
|
|
# TODO: maybe this is better: `rsync -av --delete ./ "${DEST_DIR}/"` # Sync everything perfectly, including hidden files, and delete old stale files
|
|
- name: Bin - deploy
|
|
if: steps.filter.outputs.bin == 'true'
|
|
env:
|
|
# commit tagged ? yes->prod : no->dev
|
|
DEST_DIR: /sls/bd/hla/${{ github.ref_type == 'tag' && 'prod' || 'dev' }}/bin
|
|
working-directory: bin
|
|
run: |
|
|
mkdir -p ${DEST_DIR}
|
|
cp -r ./* ${DEST_DIR}
|
|
|
|
# TODO: maybe this is better: `rsync -av --delete ./ "${DEST_DIR}/"` # Sync everything perfectly, including hidden files, and delete old stale files
|
|
- name: Agebd - deploy
|
|
if: steps.filter.outputs.agebd == 'true'
|
|
env:
|
|
# commit tagged ? yes->prod : no->dev
|
|
DEST_DIR: /sls/bd/hla/${{ github.ref_type == 'tag' && 'prod' || 'dev' }}/packages/agebd
|
|
working-directory: packages/agebd
|
|
run: |
|
|
mkdir -p ${DEST_DIR}
|
|
cp -r ./* ${DEST_DIR}
|
|
|
|
# TODO: (when) do we need to restart the master service or reinstall/restart the master ioc?
|
|
|
|
- name: Services - Initialize Virtual Environment from cli/uv.lock
|
|
if: steps.filter.outputs.services == 'true'
|
|
run: |
|
|
uv venv .venv
|
|
uv sync --directory cli
|
|
|
|
- name: Services - Install Ansible Galaxy Collections
|
|
if: steps.filter.outputs.services == 'true'
|
|
run: |
|
|
uv run ansible-galaxy collection install -r ansible/collections/requirements.yml -p ./ansible/installed-collections
|
|
|
|
- name: Services - Run Ansible Orchestrator
|
|
if: steps.filter.outputs.services == 'true'
|
|
working-directory: ansible
|
|
run: |
|
|
set -x
|
|
|
|
# Disable pipefail temporarily or add an '|| true' fallback so grep doesn't kill the script
|
|
set +e
|
|
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
|
|
set -e
|
|
|
|
# 1. Parse changed directory names into space-separated string (e.g. "master other-service")
|
|
CHANGED_SVC=$(echo "$CHANGED_FILES" | awk -F/ '$1=="services" {print $2}' | sort -u | xargs)
|
|
|
|
echo "Detected changed services: '$CHANGED_SVC'"
|
|
|
|
# Safely halt the execution if there is nothing to pass to Ansible
|
|
if [ -z "$CHANGED_SVC" ]; then
|
|
echo "No services changed in this commit range. Skipping deployment smoothly."
|
|
exit 0
|
|
fi
|
|
|
|
# 3. Fire the playbook passing variables down
|
|
ansible-playbook playbooks/deploy-and-restart-modified-services.yml \
|
|
-i "inventories/$AGEBD_ENV/hosts.yml" \
|
|
--extra-vars="changed_services_raw='$CHANGED_SVC'"
|
|
-v
|