name: Deploy to production

on:
  workflow_dispatch:
  schedule:
    - cron: '0 1,22 * * *'

jobs:
  deploy:
    runs_on: ubuntu-latest
    steps:
      - name: Setup SSH key
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          ssh-keyscan 34.90.187.4 >> ~/.ssh/known_hosts

      - name: Deploy
        run: ssh bot@34.90.187.4 "cd /var/www/crm-siteconseil && ansible-playbook ansible/deploy.yml -i ansible/hosts.ini --vault-password-file <(echo '${{ secrets.ANSIBLE_VAULT_PASSWORD }}')"
