name: Containerization

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build_container:
    name: Build docker image
    runs-on: ubuntu-latest    
    steps:
    - name: Check out repository
      uses: actions/checkout@v2
    - name: Calculate image label
      run: |
        echo "::set-env name=docker-label::libgit2-$(git log -1 --pretty=format:"%h" azure-pipelines/docker)"
    - name: Build image
      run: |
        docker build -t docker.pkg.github.com/${{github.repository}}/xenial:${{ env.docker-label }} --build-arg BASE=ubuntu:xenial -f xenial .
      working-directory: azure-pipelines/docker
    - name: Publish image
      run: |
        docker login https://docker.pkg.github.com -u ${{github.actor}} -p ${{github.token}}
        docker push docker.pkg.github.com/${{github.repository}}/xenial:${{env.docker-label}}
