name: CI

on:
  push:
    branches:
    - master
    tags:
    - v[0-9]+.[0-9]+**
  pull_request:
    branches:
    - master

jobs:

  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up JDK 15
        uses: actions/setup-java@v2
        with:
          distribution: 'zulu'
          java-version: 15

      - name: Cache Local Maven Repo
        uses: actions/cache@v2.1.2
        with:
          path: ~/.m2/repository
          key: maven-repo

      - name: Build
        run: mvn -B package

  build-broker:
    if: ${{ startsWith(github.ref, 'refs/tags/v') }}
    needs: test
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Login to GitHub Docker Registry
      uses: docker/login-action@v1
      with:
        registry: ghcr.io
        username: ${{ github.actor }}
        password: ${{ secrets.GITHUB_TOKEN }}

    - name: Prepare Version
      id: prep
      run: |
        echo ::set-output name=repository::$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
        echo ::set-output name=version::${GITHUB_REF#refs/tags/v}

    - name: Build and push docker image for aktin-broker
      uses: docker/build-push-action@v2
      with:
        context: .
        file: docker/aktin-broker/Dockerfile
        tags: |
          ghcr.io/${{ steps.prep.outputs.repository }}/aktin-broker:latest
          ghcr.io/${{ steps.prep.outputs.repository }}/aktin-broker:${{ steps.prep.outputs.version }}
        push: true

  build-client:
    if: ${{ startsWith(github.ref, 'refs/tags/v') }}
    needs: test
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Login to GitHub Docker Registry
      uses: docker/login-action@v1
      with:
        registry: ghcr.io
        username: ${{ github.actor }}
        password: ${{ secrets.GITHUB_TOKEN }}

    - name: Prepare Version
      id: prep
      run: |
        echo ::set-output name=repository::$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
        echo ::set-output name=version::${GITHUB_REF#refs/tags/v}

    - name: Build and push docker image for aktin-broker
      uses: docker/build-push-action@v2
      with:
        context: .
        file: docker/aktin-client/Dockerfile
        tags: |
          ghcr.io/${{ steps.prep.outputs.repository }}/aktin-client:latest
          ghcr.io/${{ steps.prep.outputs.repository }}/aktin-client:${{ steps.prep.outputs.version }}
        push: true

Add CI to Build Docker Images
Add CI to Build Docker Images

Build docker images for aktin-broker and aktin-client when tag is pushed
to GitHub.