name: Build and test Docker image

# Controls when the action will run. 
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks out repository under $GITHUB_WORKSPACE, so the job can access it
      - name: Checkout
        uses: actions/checkout@v2
      
      # Set up python 3.6 for linting and comics test script
      - name: Set up python3.6
        uses: actions/setup-python@v2
        with:
          python-version: 3.6
          
      # Set up docker buildx builder for building stuff
      - name: Set up docker buildx
        uses: docker/setup-buildx-action@v1
        with:
          install: true
          
      # Install pyflakes linter and fetch testing IRCd
      - name: Install python dependencies
        run: |
          pip install pyflakes
          git clone -b desertbot --single-branch https://github.com/DesertBot/weercd.git

      # Lint entire project
      - name: Lint with pyflakes
        run: pyflakes start.py desertbot/
      
      # Check correctness of comics data
      - name: Comics test
        run: python test/comics.py
      
      # Build docker image for desertbot
      - name: Docker build
        run: docker build -t starlitghost/desertbot:latest .
      
      # TODO decrypt test/api_keys.json.enc, needs something added to github secrets to decrypt with
      
      # Test bot in docker against weercd IRCd
      # TODO: mount test API keys file into bot for tests, at data/servers/localhost/APIKeys.json
      # TODO: change test/test_config.yaml to not use localhost, so we don't have to use --network=host
      # TODO: maybe just run weercd also in docker?
      - name: Docker tests
        run: |
          python weercd/weercd.py --file test/test_commands.txt -w 25.0 -s 0.25 &
          docker run --rm --network=host --volume test/test_config.yaml:/test_config.yaml starlitghost/desertbot:latest -c /test_config.yaml -l DEBUG
          
      # TODO: Login to docker hub, needs credentials added to github repo secrets
      #- name: Docker login
      #  uses: docker/login-action@v1
      #  with:
      #    username: ${{ secrets.DOCKERHUB_USERNAME }}
      #    password: ${{ secrets.DOCKERHUB_PASSWORD }}
      
      # TODO: Push image to docker hub
      #- name: Docker push
      #  run: |
      #    docker push starlitghost/desertbot:latest
      

Add docker-based github action for tests
Add docker-based github action for tests

Needs some secrets for API key decryption and some tweaking probably.

If we add dockerhub credentials it can even handle that part, since we're already building here.