name: Docker Build And Push To Docker Hub

on:
  push:
    branches: [main]
    paths:
      - "appmanage/Dockerfile"
      - "appmanage/main.py"
      - "appmanage/config/*"

jobs:
  build:
    name: Build Docker image
    runs-on: ubuntu-latest
    #env:
    #  TAGS: latest
    steps:
      - uses: actions/checkout@v2
        name: Check out code

      - name: Get version
        run: |
          version=$(grep -Po '(?<=LABEL version=").*?(?=")' appmanage/Dockerfile)
          echo $version
          echo "::set-output name=version::$version"
          echo "VERSION=$version" >> $GITHUB_ENV

      - uses: mr-smithers-excellent/docker-build-push@v5
        name: Build & push Docker image
        with:
          image: websoft9dev/appmanage
          tags: ${{ env.VERSION }}
          registry: docker.io
          dockerfile: appmanage/Dockerfile
          directory: appmanage
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: add readme file
        run: |
          echo ${{ secrets.DOCKER_USERNAME }}
          echo ${{ secrets.DOCKER_PASSWORD }}
          cd appmanage
          touch myread.md
          echo "This repository is the easiest appmanage deployment on GitHub and DockerHub  "' 
          ```  
             git clone https://github.com/Websoft9/websoft9.git  
             sudo docker network create websoft9 && cd websoft9/appmanage &&  sudo docker compose up -d  
          ```' > myread.md

      - name: Docker Hub Description
        uses: peter-evans/dockerhub-description@v3
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          repository: websoft9dev/appmanage
          readme-filepath: appmanage/myread.md
