name: Validation de version GMAO

on:
  push:
    tags:
      - 'gmao-v*'

jobs:
  validate-version:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Verifier la correspondance du tag
        shell: bash
        run: |
          version="$(tr -d '\r\n' < VERSION)"
          expected="gmao-v${version}"
          if [ "${GITHUB_REF_NAME}" != "${expected}" ]; then
            echo "Le tag ${GITHUB_REF_NAME} ne correspond pas a VERSION (${expected})."
            exit 1
          fi

      - name: Construire l'image versionnee
        shell: bash
        run: |
          version="$(tr -d '\r\n' < VERSION)"
          docker build \
            --build-arg GMAO_VERSION="${version}" \
            --build-arg GIT_VERSION="${GITHUB_SHA}" \
            --tag "gmao-college:${version}" \
            .
