For what it’s worth, this was strongly discouraged when I asked about it:
I think using versioneer or setuptools_scm (or versioningit, or …) should do what you want. Just make sure when using GitHub actions to checkout with full history, so that you get tags and enough history for git describe --tags to work properly.