name: Promote beta to production
on:
  release:
    types: [published]
jobs:
  push_to_registry:
    name: Push beta image to production
    runs-on: ubuntu-latest
    steps:
      - name: Set env
        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
      - name: Login to ECR
        id: ecr
        uses: elgohr/ecr-login-action@master
        with:
          access_key: ${{ secrets.ACCESS_KEY_ID }}
          secret_access_key: ${{ secrets.SECRET_ACCESS_KEY }}
          region: eu-west-1
      - name: Push Dialimpics to production
        uses: colbyhill21/Rancher-Action@1.1
        with:
          token: ${{ secrets.RANCHER_TOKEN }}
          context: ${{ secrets.RANCHER_CONTEXT }}
          url: ${{ secrets.RANCHER_URL }}
          args: |
            set image deployment/front-prod front-prod="402083338966.dkr.ecr.eu-west-1.amazonaws.com/dialimpics-front:${{ env.RELEASE_VERSION }}" --record -n dialimpics-prod
      - name: Production update Success
        uses: rjstone/discord-webhook-notify@v1
        if: success()
        with:
          severity: info
          details: Version ${{ env.RELEASE_VERSION }} of ${{ github.event.repository.name }} is published in production environment! Check it at https://dialimpics.binpar.cloud/
          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
          avatarUrl: https://cdn.discordapp.com/attachments/580783243586961412/845272217969491978/android-chrome-256x256.png
      - name: Production update Failure
        uses: rjstone/discord-webhook-notify@v1
        if: failure()
        with:
          severity: error
          details: Release Failed pushing version ${{ env.RELEASE_VERSION }} of ${{ github.event.repository.name }} to production environment!
          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
          avatarUrl: https://cdn.discordapp.com/attachments/580783243586961412/845272217969491978/android-chrome-256x256.png
      - name: Production update Cancelled
        uses: rjstone/discord-webhook-notify@v1
        if: cancelled()
        with:
          severity: warn
          details: Release Cancelled!
          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
          avatarUrl: https://cdn.discordapp.com/attachments/580783243586961412/845272217969491978/android-chrome-256x256.png
