name: CD Release tag pipeline
on:
  push:
    tags:
      - '[0-9]+.[0-9]+.[0-9]+'
    
jobs:
  deploy-to-live:
    name: Deploy ${{ github.event.repository.name }}@v${{ github.ref_name }}
    runs-on: ubuntu-latest
    steps:
      - name: Login using SSH, deploy and update plugin
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.LIVE_ENV_SSH_HOST }}
          username: ${{ secrets.LIVE_ENV_SSH_USER }}
          key: ${{ secrets.LIVE_ENV_SSH_KEY }}
          debug: true
          script: |
            cd ${{ secrets.LIVE_ENV_PATH }}custom/plugins/${{ github.event.repository.name }}
            git remote rm origin
            git remote add origin https://${{ secrets.LIVE_ENV_GITHUB_ACCESS_KEY }}@github.com/${{ github.repository }}
            git fetch --all --tags
            git checkout ${{ github.ref_name }}
            cd ${{ secrets.LIVE_ENV_PATH }}
            bin/console plugin:refresh
            bin/console plugin:update ${{ github.event.repository.name }}