name: build and deploy portfolio

on:
  push:
    branches: [ "master" ]
    paths-ignore: ['Writerside/**']
  pull_request:
    branches: [ "master" ]
    paths-ignore: ['Writerside/**']

jobs:

  build:

    runs-on: self-hosted

    steps:
    - uses: actions/checkout@v3
    - name: 'Create env file'
      run: |
        touch .env
        echo BOT_TOKEN=${{ secrets.BOT_TOKEN }} >> .env
        echo ERROR_CHANNEL_ID=${{ secrets.ERROR_CHANNEL_ID }} >> .env
        echo LOG_CHANNEL_ID=${{ secrets.LOG_CHANNEL_ID }} >> .env
        echo ENVIRONMENT=${{ secrets.ENVIRONMENT }} >> .env
    - name: Docker login
      run: docker login docker.dariusklein.nl -u Darius -p ${{ secrets.DOCKER_PASSWORD }}
    - name: Build the Docker image
      run: docker build . --file Dockerfile --tag docker.dariusklein.nl/kleincord
    - name: Docker push
      run: docker push docker.dariusklein.nl/kleincord


  publish:
  
    needs: build
    
    runs-on: self-hosted
    
    steps:
    - name: Docker stop
      run: docker stop kleincordBot  || true
    - name: Docker login
      run: docker login docker.dariusklein.nl -u Darius -p ${{ secrets.DOCKER_PASSWORD }}
    - name: Docker pull
      run: docker pull docker.dariusklein.nl/kleincord
    - name: Docker run
      run: docker run --rm -d --name kleincordBot docker.dariusklein.nl/kleincord
