name: Deploy HML Avanzato

on:
  push:
    branches:
      - develop

jobs:
  deploy-hml:
    runs-on: linux_amd64

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Instalar dependências
        run: npm install

      - name: Build projeto
        run: npm run build

      - name: Compactar dist
        run: tar -czf dist.tar.gz dist

      - name: Enviar para servidor HML
        run: scp -o StrictHostKeyChecking=no -i /data/avz_hml_deploy dist.tar.gz root@191.252.100.174:/tmp/avz-site-hml-dist.tar.gz

      - name: Publicar HML
        run: |
          ssh -o StrictHostKeyChecking=no -i /data/avz_hml_deploy root@191.252.100.174 '
            rm -rf /opt/avanzato/site-hml/app/dist_old
            mv /opt/avanzato/site-hml/app/dist /opt/avanzato/site-hml/app/dist_old
            mkdir -p /opt/avanzato/site-hml/app/dist
            tar -xzf /tmp/avz-site-hml-dist.tar.gz -C /opt/avanzato/site-hml/app
            rm -f /tmp/avz-site-hml-dist.tar.gz
            docker restart avanzato-site-hml
          '
