I have a .NET 6.0 Web API and want it to know its version. To publish the Docker images I use Github Actions docker/build-push-action@v3.1.0
. I tried using MinVer which would exactly meet my needs as it is using the latest git version tag and adds the number of commits since that version as last digit. But as the docker/build-push-action@v3.1.0
does not have the full Git environment, Minver can not extract the version number of the Git tags while the image is built. It would be possible to use a CLI tool to extract the version before creating the Docker image:
- name: install minver-cli
run: dotnet tool install --global minver-cli
- name: get version
run: echo "MINVERVERSIONOVERRIDE=$(minver --tag-prefix v --verbosity e)" >> $GITHUB_ENV
- name: echo environementvariable
run: echo ${{ env.MINVERVERSIONOVERRIDE }}
If MINVERVERSIONOVERRIDE
does exist as environment variable at build time, MinVer does not try to extract the version of the git history but just use that version. But it does not look like this environment variable exists in the docker/build-push-action@v3.1.0
.
Is there any other way to use version numbers based on the git tags when creating a Docker image?