name: Gitea Actions
run-name: ${{ gitea.actor }} is testing out Gitea Actions ??
on: [push]

jobs:
  Explore-Gitea-Actions:
    runs-on: ubuntu-latest
    name: Build and deploy
    steps:
      - name: Migrate env file
        run: | 
          echo "${{ secrets.ENVIRONMENT }}" > ./.env
          cat ./.env
      - name: Know current user and host
        run: |
          apt-get net-tools
          echo $USER
          ifconfig -a    
      - name: Stop site service on remote server  
        uses: D3rHase/ssh-command-action@v0.2.2
        with:
          host: ${{secrets.SSH_HOST}}
          user: ${{secrets.SSH_USER}}
          private_key: ${{secrets.SSH_KEY}}
          command: |
            systemctl stop resume
      - name: Checkout code
        uses: actions/checkout@v3
      - name: Install PHP
        run: apt update && apt install -y php-cli php-intl php-mbstring php-xml php-zip 
      - name: Install Composer
        run: |
          php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
          php composer-setup.php
          php -r "unlink('composer-setup.php');"
          php composer.phar install
          php composer.phar dump-autoload    
      - name: Update npm dependencies
        run: | 
          node -v
          npm i --progress=false
      - name: Update composer dependencies
        run: | 
          export COMPOSER_ALLOW_SUPERUSER=1
          composer show
          composer install
      - name: Build frontend
        run: pwd; npm run build;
      - name: Deploy to Server
        uses: https://gitea.com/aquelle1/ssh-deploy@main
        env:
          SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY }}
          ARGS: "-rlgoDzvc -i --delete"  
          SOURCE: "site/"
          REMOTE_HOST: ${{ secrets.SSH_HOST }}
          REMOTE_USER: ${{ secrets.SSH_USER }}
          TARGET: ${{ secrets.SSH_DIR }}
      - name: Start site service on remote server
        uses: D3rHase/ssh-command-action@v0.2.2
        with:
          host: ${{secrets.SSH_HOST}}
          user: ${{secrets.SSH_USER}}
          private_key: ${{secrets.SSH_KEY}}
          command: |
            systemctl start resume