fix: cicd
This commit is contained in:
@@ -0,0 +1,100 @@
|
|||||||
|
name: Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
tags:
|
||||||
|
- 'prod'
|
||||||
|
- 'v*'
|
||||||
|
paths:
|
||||||
|
- 'bin/**'
|
||||||
|
- 'packages/agebd/**'
|
||||||
|
- 'services/**'
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: hla-dev
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # needed for git diff tracking
|
||||||
|
|
||||||
|
- name: Defined filter paths
|
||||||
|
uses: dorny/paths-filter@v3
|
||||||
|
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 hosts.yml \
|
||||||
|
-e "changed_services_raw='$CHANGED_SVC'" \
|
||||||
|
-e "agebd_env=$AGEBD_ENV" \
|
||||||
|
-vvv
|
||||||
+30
-11
@@ -21,19 +21,38 @@ jobs:
|
|||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # needed for git diff tracking
|
fetch-depth: 2 # needed for git diff tracking
|
||||||
|
|
||||||
- name: Defined filter paths
|
- name: Defined filter paths
|
||||||
uses: dorny/paths-filter@v3
|
|
||||||
id: filter
|
id: filter
|
||||||
with:
|
run: |
|
||||||
filters: |
|
# Get list of modified files between current commit (HEAD) and its parent (HEAD~1)
|
||||||
bin:
|
CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r HEAD HEAD~1 || true)
|
||||||
- 'bin/**'
|
echo "Changed files:"
|
||||||
agebd:
|
echo "$CHANGED_FILES"
|
||||||
- 'packages/agebd/**'
|
|
||||||
services:
|
# Initialize flags to false
|
||||||
- 'services/**'
|
BIN_CHANGED="false"
|
||||||
|
AGEBD_CHANGED="false"
|
||||||
|
SERVICES_CHANGED="false"
|
||||||
|
|
||||||
|
# Check if any changed files
|
||||||
|
if echo "$CHANGED_FILES" | grep -q "^bin/"; then
|
||||||
|
BIN_CHANGED="true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if echo "$CHANGED_FILES" | grep -q "^packages/agebd/"; then
|
||||||
|
AGEBD_CHANGED="true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if echo "$CHANGED_FILES" | grep -q "^services/"; then
|
||||||
|
SERVICES_CHANGED="true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Output variables to the runner step context
|
||||||
|
echo "bin_changed=$BIN_CHANGED" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "agebd_changed=$AGEBD_CHANGED" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "services_changed=$SERVICES_CHANGED" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
# TODO: maybe this is better: `rsync -av --delete ./ "${DEST_DIR}/"` # Sync everything perfectly, including hidden files, and delete old stale files
|
# TODO: maybe this is better: `rsync -av --delete ./ "${DEST_DIR}/"` # Sync everything perfectly, including hidden files, and delete old stale files
|
||||||
- name: Bin - deploy
|
- name: Bin - deploy
|
||||||
@@ -91,7 +110,7 @@ jobs:
|
|||||||
echo "No services changed in this commit range. Skipping deployment smoothly."
|
echo "No services changed in this commit range. Skipping deployment smoothly."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 3. Fire the playbook passing variables down
|
# 3. Fire the playbook passing variables down
|
||||||
ansible-playbook playbooks/deploy-and-restart-modified-services.yml \
|
ansible-playbook playbooks/deploy-and-restart-modified-services.yml \
|
||||||
-i hosts.yml \
|
-i hosts.yml \
|
||||||
|
|||||||
Reference in New Issue
Block a user