name: Hydra Deployment Manager (Odoo 18) on: push: branches: - 'dev_**' - 'preprod_**' # - 'master_**' workflow_dispatch: inputs: target_env: description: 'Target Environment' required: true type: choice options: - dev - preprod - prod default: 'dev' specific_host: description: 'Specific Server IP (Optional)' required: false type: string default: '' force_restart: description: 'Force Service Restart' required: true type: boolean default: true jobs: deploy: runs-on: ubuntu-latest name: Deploy steps: - name: Extract Context id: context run: | REF_NAME=${{ github.ref_name }} EVENT_NAME=${{ github.event_name }} INPUT_ENV=${{ inputs.target_env }} echo "Processing Event: $EVENT_NAME on Ref: $REF_NAME" ENV="" MODULE="" PORT="" # Logic: if [ "$EVENT_NAME" == "push" ]; then if [[ "$REF_NAME" == dev_* ]]; then ENV="dev" MODULE=${REF_NAME#dev_} elif [[ "$REF_NAME" == preprod_* ]]; then ENV="preprod" MODULE=${REF_NAME#preprod_} fi elif [ "$EVENT_NAME" == "workflow_dispatch" ]; then ENV="$INPUT_ENV" if [[ "$REF_NAME" == dev_* ]]; then MODULE=${REF_NAME#dev_} elif [[ "$REF_NAME" == preprod_* ]]; then MODULE=${REF_NAME#preprod_} elif [[ "$REF_NAME" == master_* ]]; then MODULE=${REF_NAME#master_} else # Fallback assuming valid module name in branch suffix MODULE=${REF_NAME#*_} fi fi # ODOO 18 PORT CONFIGURATION if [ "$ENV" == "dev" ]; then PORT="18000" elif [ "$ENV" == "preprod" ]; then PORT="18010" elif [ "$ENV" == "prod" ]; then PORT="18069" fi echo "ENV=$ENV" >> $GITHUB_OUTPUT echo "MODULE=$MODULE" >> $GITHUB_OUTPUT echo "PORT=$PORT" >> $GITHUB_OUTPUT - name: Deploy to Hydra Server (SSH) if: steps.context.outputs.ENV != '' uses: appleboy/ssh-action@v1.0.0 with: host: ${{ inputs.specific_host != '' && inputs.specific_host || secrets.HYDRA_HOST }} username: ${{ secrets.HYDRA_USER }} key: ${{ secrets.HYDRA_SSH_KEY }} port: 22 script: | MODULE="${{ steps.context.outputs.MODULE }}" ENV="${{ steps.context.outputs.ENV }}" BRANCH="${{ github.ref_name }}" FORCE_RESTART="${{ inputs.force_restart }}" echo "🚀 Deploying (Odoo 18) $MODULE to $ENV Environment..." if [ "$ENV" == "dev" ]; then TARGET_ROOT="/root/odoo-infra/odoo18/addons/custom_modules" SERVICE="odoo-18" else echo "🚧 Environment '$ENV' folder structure is not yet created on the server for Odoo 18. Deployment simulated." exit 0 fi TARGET_DIR="$TARGET_ROOT/$MODULE" # Auto-create directory if it doesn't exist (First run) if [ ! -d "$TARGET_DIR" ]; then echo "✨ Creating new module directory: $TARGET_DIR" mkdir -p "$TARGET_DIR" # Initial clone logic handled by script usually, but here we can just git init if empty # Better to assume the setup script handles it, or handle it here: cd "$TARGET_DIR" git init git remote add origin git@github.com-odoo18:hydracp9/odex30_standard.git fi cd "$TARGET_DIR" echo "⬇️ Pulling changes from $BRANCH..." git fetch origin git reset --hard origin/$BRANCH if [ "$FORCE_RESTART" == "true" ] || [ "${{ github.event_name }}" == "push" ]; then echo "🔄 Restarting Service ($SERVICE)..." cd /root/odoo-infra docker compose restart $SERVICE fi echo "✅ Deployment Successful."