From 03aef2049d6b685bbe92d50674981bce395a4201 Mon Sep 17 00:00:00 2001 From: Benjamin Labrecque Date: Wed, 15 Jul 2026 15:01:00 +0200 Subject: [PATCH] cicd: add all into one deployment file to fix order --- .../workflows/deploy-and-restart-service.yml | 134 +++++++++--------- .gitea/workflows/deploy-bin.yml | 70 ++++----- .gitea/workflows/deploy-py-agebd.yml | 68 ++++----- .gitea/workflows/deploy.yml | 100 +++++++++++++ 4 files changed, 236 insertions(+), 136 deletions(-) create mode 100644 .gitea/workflows/deploy.yml diff --git a/.gitea/workflows/deploy-and-restart-service.yml b/.gitea/workflows/deploy-and-restart-service.yml index 33d7c4a..fa4a82f 100644 --- a/.gitea/workflows/deploy-and-restart-service.yml +++ b/.gitea/workflows/deploy-and-restart-service.yml @@ -1,67 +1,67 @@ -name: Deploy and restart modified services -# TODO: take care of .venv building when required (i.e when uv.lock changed) - -on: - push: - # TODO: if someone tags 'prod' to a (broken) feature branch - # this still triggers (and deploys to prod). - branches: - - main - tags: - - 'prod' - - 'v*' - paths: - - '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: 0 # needed for git diff tracking - - # TODO: (when) do we need to restart the master service or reinstall/restart the master ioc? - - - name: Initialize Virtual Environment from cli/uv.lock - run: | - uv venv .venv - uv sync --directory cli - - - name: Install Ansible Galaxy Collections - run: | - uv run ansible-galaxy collection install -r ansible/collections/requirements.yml -p ./ansible/installed-collections - - - name: Run Ansible Orchestrator - 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 +# name: Deploy and restart modified services +# # TODO: take care of .venv building when required (i.e when uv.lock changed) +# +# on: +# push: +# # TODO: if someone tags 'prod' to a (broken) feature branch +# # this still triggers (and deploys to prod). +# branches: +# - main +# tags: +# - 'prod' +# - 'v*' +# paths: +# - '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: 0 # needed for git diff tracking +# +# # TODO: (when) do we need to restart the master service or reinstall/restart the master ioc? +# +# - name: Initialize Virtual Environment from cli/uv.lock +# run: | +# uv venv .venv +# uv sync --directory cli +# +# - name: Install Ansible Galaxy Collections +# run: | +# uv run ansible-galaxy collection install -r ansible/collections/requirements.yml -p ./ansible/installed-collections +# +# - name: Run Ansible Orchestrator +# 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 diff --git a/.gitea/workflows/deploy-bin.yml b/.gitea/workflows/deploy-bin.yml index 8b1a108..6429687 100644 --- a/.gitea/workflows/deploy-bin.yml +++ b/.gitea/workflows/deploy-bin.yml @@ -1,35 +1,35 @@ -name: Deploy bin - -# TODO: this should be deployed before service restarts, -# if both bin and a service changed. -on: - push: - branches: - - main - tags: - - 'prod' - - 'v*' - paths: - - 'bin/**' - -jobs: - deploy: - runs-on: hla-dev - defaults: - run: - working-directory: ./bin - - env: - # commit tagged ? yes->prod : no->dev - DEST_DIR: /sls/bd/hla/${{ github.ref_type == 'tag' && 'prod' || 'dev' }}/bin - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Copy files - 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: Deploy bin +# +# # TODO: this should be deployed before service restarts, +# # if both bin and a service changed. +# on: +# push: +# branches: +# - main +# tags: +# - 'prod' +# - 'v*' +# paths: +# - 'bin/**' +# +# jobs: +# deploy: +# runs-on: hla-dev +# defaults: +# run: +# working-directory: ./bin +# +# env: +# # commit tagged ? yes->prod : no->dev +# DEST_DIR: /sls/bd/hla/${{ github.ref_type == 'tag' && 'prod' || 'dev' }}/bin +# +# steps: +# - name: Checkout repository +# uses: actions/checkout@v4 +# +# - name: Copy files +# 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 diff --git a/.gitea/workflows/deploy-py-agebd.yml b/.gitea/workflows/deploy-py-agebd.yml index d3d3119..5cb35de 100644 --- a/.gitea/workflows/deploy-py-agebd.yml +++ b/.gitea/workflows/deploy-py-agebd.yml @@ -1,34 +1,34 @@ -name: Deploy agebd python package - -# TODO: services depend on this workflow -on: - push: - branches: - - main - tags: - - 'prod' - - 'v*' - paths: - - 'packages/agebd/**' - -jobs: - deploy: - runs-on: hla-dev - defaults: - run: - working-directory: ./packages/agebd - - env: - # commit tagged ? yes->prod : no->dev - DEST_DIR: /sls/bd/hla/${{ github.ref_type == 'tag' && 'prod' || 'dev' }}/packages/agebd - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Copy files - 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: Deploy agebd python package +# +# # TODO: services depend on this workflow +# on: +# push: +# branches: +# - main +# tags: +# - 'prod' +# - 'v*' +# paths: +# - 'packages/agebd/**' +# +# jobs: +# deploy: +# runs-on: hla-dev +# defaults: +# run: +# working-directory: ./packages/agebd +# +# env: +# # commit tagged ? yes->prod : no->dev +# DEST_DIR: /sls/bd/hla/${{ github.ref_type == 'tag' && 'prod' || 'dev' }}/packages/agebd +# +# steps: +# - name: Checkout repository +# uses: actions/checkout@v4 +# +# - name: Copy files +# 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 diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..a27edd3 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -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