The solution to your question is to use
git describe --exact-match HEAD
(which would consider only annotated tags, but you should use annotated and probably even signed tags for tagging releases).
If you want to consider all tags, also lightweight tags (which are usually used for local tagging), you can use --tags option:
git describe --exact-match --tags HEAD
But I think you have “XY problem” here, in that you are asking question about possible solution to the problem, rather than asking question about a problem… which can have better solution.
The solution to your problem is to take a look how Git does it in GIT-VERSION-GEN script, and how it uses it in its Makefile.