-
-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow overriding the binary version when VCS not available (#1163)
As mentioned in #1046, for environments, like Nix, that build without a Version Control System (VCS) available, we output `(devel)` as the version of oapi-codegen even when it's building from source from a Git tag. We can therefore provide a `noVCSVersionOverride` build-time flag to allow us to override this with an arbitrary string. Closes #1046. Co-authored-by: Jamie Tanna <[email protected]>
- Loading branch information
1 parent
aaa0b59
commit beb29bb
Showing
8 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Overriding the version of oapi-codegen | ||
|
||
## Why? | ||
|
||
oapi-codegen uses the standard Go means to determine what the version of the binary is. | ||
|
||
However, this doesn't work when there's no Version Control System (VCS), for instance when building from a source bundle. | ||
|
||
This example shows how to override the version at build-time. | ||
|
||
## How? | ||
|
||
By specifying `-ldflags` for the `noVCSVersionOverride` when running `go build` or `go run`: | ||
|
||
```sh | ||
go run -ldflags "-X main.noVCSVersionOverride=v123.456.789" ./cmd/oapi-codegen --config=config.yaml ../../api.yaml | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
openapi: "3.0.0" | ||
info: | ||
version: 1.0.0 | ||
title: NOOP API | ||
description: An test API to check some build-time features | ||
paths: | ||
/nothing: | ||
get: | ||
operationId: getNothing | ||
description: | | ||
Returns nothing as expected | ||
responses: | ||
200: | ||
description: Ok |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package: api | ||
generate: | ||
echo-server: true | ||
output: api.gen.go | ||
output-options: | ||
skip-prune: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package api | ||
|
||
//go:generate go run -ldflags "-X main.noVCSVersionOverride=v123.456.789" github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config.yaml ../../api.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters