name: CI

on:
  pull_request:
    paths-ignore:
      - README.md
      - ChangeLog.md
      - LICENSE
  push:
    paths-ignore:
      - README.md
      - ChangeLog.md
      - LICENSE

jobs:
  docker:
    runs-on: ubuntu-18.04
    strategy:
      fail-fast: true
      matrix:
        distro:
          - ubuntu
          - alpine
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Create Docker image
        run: |
          docker build \
              --tag pandocscholar/${{ matrix.distro }}:dev \
              --file docker/${{ matrix.distro }}.Dockerfile \
              .

      - name: Run Docker on example
        run: |
          docker run --rm \
                 --user "$(id -u):$(id -g)" \
                 --volume "$(pwd)/example:/data" \
                 pandocscholar/${{ matrix.distro }}:dev

      - name: Login to Docker Hub
        run: >-
          echo "${{ secrets.DOCKER_HUB_TOKEN }}" |
            docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin

      - name: Push dev image
        run: docker push pandocscholar/${{ matrix.distro }}:dev
