name: Deploy Latest Version on DigitalOcean

on:
  workflow_run:
    workflows:
      - Build and Push Docker Image
    types:
      - completed

jobs:
  on-success:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    steps:
      - name: Install DigitalOcean CLI
        uses: digitalocean/action-doctl@v2.3.0
        with:
          token: ${{ secrets.DIGITALOCEAN_TOKEN }}

      - name: Create Deployment with Latest Version
        run: doctl apps create-deployment ${{ secrets.DIGITALOCEAN_APP_ID }} --wait --force-rebuild

  on-failure:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'failure' }}
    steps:
      - name: Abruptly end the worklfow
        run: exit 1
