#!/usr/bin/env bash

release_regex='\d+.\d+.\d+'
snapshot_regex='\d+.\d+.\d+-SNAPSHOT'
rootVersion=$(run_mvn.sh help:evaluate -Dexpression=project.version -q -DforceStdout)

if [[ "$CI_COMMIT_REF_NAME" == "release" ]]; then
    if ! [[ "$rootVersion" =~ $release_regex ]]; then
        echo "Keine Release Version für Branch $CI_COMMIT_REF_NAME."
        exit 1
    fi
else
    if ! [[ "$rootVersion" =~ $snapshot_regex ]]; then
        echo "Keine Snapshot Version für Branch $CI_COMMIT_REF_NAME."
        exit 1
    fi
fi