name: Run tests and build server Docker image
on:
  workflow_dispatch:
  push:
    paths-ignore:
      - '!server/**'

    branches:
      - master

defaults:
  run:
    working-directory: server

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      # Setup Go
      - name: Setup Go
        uses: actions/setup-go@v2
        with:
          go-version: '1.18'

      # Tests
      - name: Run testing
        run: go test ./... -race

      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_HUB_USERNAME }}
          password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: ./server
          push: true
          # prettier-ignore
          tags:
            ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:latest

name: Run tests and build server Docker image
on:
  workflow_dispatch:
  push:
    paths-ignore:
      - '!server/**'

    branches:
      - master

defaults:
  run:
    working-directory: server

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      # Setup Go
      - name: Setup Go
        uses: actions/setup-go@v2
        with:
          go-version: '1.18'

      # Tests
      - name: Run testing
        run: go test ./... -race

      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_HUB_USERNAME }}
          password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: ./server
          push: true
          # prettier-ignore
          tags: |
            ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:${{ github.sha }}
            ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:latest

Tag docker image with commit hash
Tag docker image with commit hash

So that its easy to differentiate images
