name: Test and Build
on: [push]

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: actions/setup-go@v1
        with:
          go-version: '1.13.x'
      - name: Execute test and upload coverage
        run: |
          go version
          go test -coverprofile=coverage.txt -covermode=atomic -p 1 . ./worker ./cli ./State
          bash <(curl -s https://codecov.io/bash)
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
          REDIS_URL: redis://localhost:${{ job.services.redis.ports['6379'] }}
    services:
      redis:
        image: redis
        ports:
          - 6379/tcp
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - name: Build Docker Images
        run: |
          docker build -t activity-relay:$(echo ${GITHUB_SHA}|head -c7) .
      - name: Push Docker Images to DockerHub
        run: |
          docker login -u ${{ secrets.REGISTORY_USER }} -p ${{ secrets.REGISTORY_PASS }}
          docker tag activity-relay:$(echo ${GITHUB_SHA}|head -c7) ${{ secrets.REGISTORY_USER }}/activity-relay:$(echo ${GITHUB_SHA}|head -c7)
          docker push ${{ secrets.REGISTORY_USER }}/activity-relay:$(echo ${GITHUB_SHA}|head -c7)
      - name: Push Docker Images to GitHub Packages
        run: |
          docker login docker.pkg.github.com -u ${{ secrets.REGISTORY_USER }} -p ${{ secrets.GITHUB_TOKEN }}
          docker tag activity-relay:$(echo ${GITHUB_SHA}|head -c7) docker.pkg.github.com/${{ secrets.REGISTORY_USER }}/activity-relay/activity-relay:$(echo ${GITHUB_SHA}|head -c7)
          docker push docker.pkg.github.com/${{ secrets.REGISTORY_USER }}/activity-relay/activity-relay:$(echo ${GITHUB_SHA}|head -c7)
