I wasn't able to perfectly test it as my forked repository does not have any releases yet.
I've added a step to the workflow that dry-runs the semantic release. This step automatically sets the version variable.
The version variable is being used by the go build command:
run: go build -ldflags="-X 'main.version=${{ steps.version.outputs.VERSION }}'"
This injects the variable into the variable declared in the main.go.
I've thought about having a separate file version.go or something like that, but I've opted against it. It might make sense in the future if you want to enable the customary --version flag.
I wasn't able to perfectly test it as my forked repository does not have any releases yet.
I've added a step to the workflow that dry-runs the semantic release. This step automatically sets the version variable.
The version variable is being used by the go build command:
run: go build -ldflags="-X 'main.version=${{ steps.version.outputs.VERSION }}'"
This injects the variable into the variable declared in the
main.go
.I've thought about having a separate file
version.go
or something like that, but I've opted against it. It might make sense in the future if you want to enable the customary--version
flag.