name: Build docker image based on commit sha

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: [self-hosted, cicd]
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

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

      - name: Add IMAGE_TAG_SHORT_SHA env property with commit short sha
        run: echo "IMAGE_TAG_SHORT_SHA=aulaapp/aula-frontend:$(git rev-parse --short HEAD)" >> $GITHUB_ENV

      - name: Build and tag Docker image
        run: docker build --build-arg DOCKER_TAG=$IMAGE_TAG_SHORT_SHA -t $IMAGE_TAG_SHORT_SHA .

      - name: Push Docker image tag
        run: docker push $IMAGE_TAG_SHORT_SHA
