name: CI

on:
  push:
    tags:
      - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

env:
  IMAGE_NAME: chatbot

jobs:
  ci:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Extract version from ref
        id: extract-version
        run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\/v/}

      - name: Docker build
        run: docker build -t $IMAGE_NAME .

      - name: Docker login
        run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin

      - name: Push to Dockerhub
        run: |
          FULL_IMAGE_NAME="${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.extract-version.outputs.version }}"

          docker tag $IMAGE_NAME $FULL_IMAGE_NAME
          docker push $FULL_IMAGE_NAME

Build Docker Image and deploy to Docker Hub on version release
Build Docker Image and deploy to Docker Hub on version release

