name: Preview Deployment

on:
  workflow_run:
    workflows: ["Development Image"]
    types:
      - completed

concurrency:
  group: ${{ github.workflow }}
  cancel-in-progress: true

jobs:
  deployment:
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    name: deployment to preview environment
    runs-on: ubuntu-latest
    environment: ${{ vars.DEPLOY_ENV }}
    steps:
    - name: Send start notification
      uses: appleboy/discord-action@master
      with:
        webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }}
        webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
        color: "#6848a9"
        message: Deployment ${{ github.ref_name }} started
    - name: ssh
      uses: appleboy/ssh-action@master
      with:
        host: ${{ secrets.SSH_HOST }}
        port: ${{ secrets.SSH_PORT }}
        username: ${{ secrets.SSH_USER }}
        key: ${{ secrets.SSH_KEY }}
        script: ${{ vars.DEPLOY_SCRIPT }}
    - name: Send complete notification
      uses: appleboy/discord-action@master
      with:
        webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }}
        webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
        color: "#6848a9"
        message: Deployment ${{ github.ref_name }} complete
