Skip to content

Commit b43321d

Browse files
committed
fix: use VERSION as the source of truth
Updated the implementation to treat `VERSION` as the source of truth instead of having a sort of split brain scenario.
1 parent 73bf93f commit b43321d

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

.github/ISSUE_TEMPLATE/release_checklist.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ labels: release
1111
After completing each task put an `x` in the corresponding box,
1212
and paste the link to the relevant PR.
1313
-->
14-
- [ ] Make sure the [VERSION](https://github.com/oxidecomputer/oxide.go/blob/main/VERSION) and [internal/generate/version.go](https://github.com/oxidecomputer/oxide.go/blob/main/internal/generate/version.go) files have the new version you want to release.
14+
- [ ] Make sure the [VERSION](https://github.com/oxidecomputer/oxide.go/blob/main/VERSION) file has the new version you want to release.
1515
- [ ] Make sure the changelog file in the `.changelog/` directory is set to the new version you want to release.
1616
- [ ] Make sure all examples and docs reference the new version.
1717
- [ ] Make sure you've pulled the latest tag on main, and generate changelog by running `make changelog`. Add the date of the release to the title, and update associated Oxide API version.
1818
- [ ] Release the new version by running `make tag`.
1919
- [ ] Update GitHub release description with release notes generated from `make changelog`.
2020
- [ ] Create a release branch from the commit of the release tag.
21-
- [ ] Bump the version in [VERSION](https://github.com/oxidecomputer/oxide.go/blob/main/VERSION) and [internal/generate/version.go](https://github.com/oxidecomputer/oxide.go/blob/main/internal/generate/version.go).
21+
- [ ] Bump the version in [VERSION](https://github.com/oxidecomputer/oxide.go/blob/main/VERSION) and run `make generate` to update the generated files.
2222
- [ ] Create a new file for the next release in [.changelog/](https://github.com/oxidecomputer/oxide.go/blob/main/.changelog/).

CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ $ make all
1616

1717
## Releasing a new SDK version
1818

19-
1. Make sure the following files have the new version you want to release.
20-
- [`VERSION`](./VERSION)
21-
- [`oxide/version.go`](./oxide/version.go): Updated via [`internal/generate/version.go`](./internal/generate/version.go)
19+
1. Update the [`VERSION`](./VERSION) file with the new version you want to release.
20+
- The [`oxide/version.go`](./oxide/version.go) file will be automatically updated when you run `make generate`
2221
2. Make sure you have run `make all` and pushed any changes. The release
2322
will fail if running `make all` causes any changes to the generated
2423
code.

internal/generate/main.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ func generateSDK() error {
4444
}
4545
}
4646

47+
sdkVersionFile := "../VERSION"
48+
sdkVersion, err := loadSDKVersionFromFile(sdkVersionFile)
49+
if err != nil {
50+
return err
51+
}
52+
4753
typesFile := "../../oxide/types.go"
4854
if err := generateTypes(typesFile, spec); err != nil {
4955
return err
@@ -60,13 +66,33 @@ func generateSDK() error {
6066
}
6167

6268
versionFile := "../../oxide/version.go"
63-
if err := generateVersion(versionFile, spec); err != nil {
69+
if err := generateVersion(versionFile, spec, sdkVersion); err != nil {
6470
return err
6571
}
6672

6773
return nil
6874
}
6975

76+
func loadSDKVersionFromFile(file string) (string, error) {
77+
wd, err := os.Getwd()
78+
if err != nil {
79+
return "", fmt.Errorf("error getting current working directory: %w", err)
80+
}
81+
82+
f := filepath.Join(filepath.Dir(wd), file)
83+
version, err := os.ReadFile(f)
84+
if err != nil {
85+
return "", fmt.Errorf("error retrieving SDK version: %w", err)
86+
}
87+
88+
sdkVersion := strings.TrimSpace(string(version))
89+
if sdkVersion == "" {
90+
return "", fmt.Errorf("sdk version cannot be empty: %s", file)
91+
}
92+
93+
return sdkVersion, nil
94+
}
95+
7096
func loadAPIFromFile(file string) (*openapi3.T, error) {
7197
wd, err := os.Getwd()
7298
if err != nil {

internal/generate/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
// generateVersion generates the version.go file with both SDK and API versions.
15-
func generateVersion(file string, spec *openapi3.T) error {
15+
func generateVersion(file string, spec *openapi3.T, sdkVersion string) error {
1616
f, err := openGeneratedFile(file)
1717
if err != nil {
1818
return err
@@ -36,7 +36,7 @@ func generateVersion(file string, spec *openapi3.T) error {
3636
SDKVersion string
3737
OpenAPIVersion string
3838
}{
39-
SDKVersion: "v0.8.0",
39+
SDKVersion: sdkVersion,
4040
OpenAPIVersion: apiVersion,
4141
}
4242

0 commit comments

Comments
 (0)