Skip to content

Commit

Permalink
Merge pull request #96 from fingerprintjs/build/fix-major-release
Browse files Browse the repository at this point in the history
Correctly replace version mentions on major release during generation
  • Loading branch information
TheUnderScorer authored Sep 27, 2024
2 parents 839073c + d398848 commit e17a8fa
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 147 deletions.
7 changes: 1 addition & 6 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,5 @@
"initialVersions": {
"fingerprint-pro-server-api-go-sdk": "6.1.0"
},
"changesets": [
"angry-crabs-roll",
"cuddly-wasps-try",
"sour-moose-exist",
"wild-oranges-feel"
]
"changesets": []
}
5 changes: 5 additions & 0 deletions .changeset/tough-roses-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fingerprint-pro-server-api-go-sdk": patch
---

Remove unused `Model` struct
265 changes: 147 additions & 118 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Fingerprint Pro Server API allows you to get information about visitors and abou
This Go package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:

- API version: 3
- Package version: 7.0.0-test.0
- Package version: 6.1.0
- Build package: io.swagger.codegen.v3.generators.go.GoClientCodegen

## Requirements
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"packageVersion": "7.0.0-test.0",
"packageVersion": "6.1.0",
"gitRepoId": "fingerprint-pro-server-api-go-sdk",
"gitUserId": "fingerprintjs",
"packageName": "sdk",
Expand Down
46 changes: 30 additions & 16 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ func moveFilesToKeepFromTmpDir() {
}
}

func getModuleVersion() string {
cmd := exec.Command("go", "mod", "edit", "-json")

output, err := cmd.Output()
if err != nil {
log.Fatal(err)
}

var module struct {
Module struct {
Path string
}
}
if err := json.Unmarshal(output, &module); err != nil {
log.Fatal(err)
}

parts := strings.Split(module.Module.Path, "/")
version := parts[len(parts)-1]

// Return version without "v" prefix
return version[1:]
}

func getVersion() string {
var version string

Expand All @@ -84,13 +108,9 @@ func getVersion() string {
return version
}

func replaceMajorVersionMentions(newMajor string) {
configVersion := config.ReadConfig("./config.json").PackageVersion

oldMajor := strings.Split(configVersion, ".")[0]
oldMajor = fmt.Sprintf("github.com/fingerprintjs/fingerprint-pro-server-api-go-sdk/v%s", oldMajor)

func replaceMajorVersionMentions(newMajor string, oldMajor string) {
newMajor = fmt.Sprintf("github.com/fingerprintjs/fingerprint-pro-server-api-go-sdk/v%s", newMajor)
oldMajor = fmt.Sprintf("github.com/fingerprintjs/fingerprint-pro-server-api-go-sdk/v%s", oldMajor)

log.Println("Replacing major version mentions in files", oldMajor, "->", newMajor)

Expand Down Expand Up @@ -126,20 +146,14 @@ func replaceMajorVersionMentions(newMajor string) {

func handlePotentialMajorRelease() {
version := getVersion()

configVersion := config.ReadConfig("./config.json").PackageVersion

if configVersion == version {
return
}

newMajorVersion := strings.Split(version, ".")[0]
currentMajorVersion := strings.Split(configVersion, ".")[0]

if newMajorVersion != currentMajorVersion {
moduleVersion := getModuleVersion()

if newMajorVersion != moduleVersion {
log.Println("Major update detected, bumping version usage in all files")

replaceMajorVersionMentions(newMajorVersion)
replaceMajorVersionMentions(newMajorVersion, moduleVersion)
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fingerprint-pro-server-api-go-sdk",
"version": "7.0.0-test.0",
"version": "6.1.0",
"private": true,
"devDependencies": {
"@changesets/cli": "^2.27.8",
Expand Down
2 changes: 1 addition & 1 deletion sdk/api_fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"strings"
)

const IntegrationInfo = "fingerprint-pro-server-go-sdk/7.0.0-test.0"
const IntegrationInfo = "fingerprint-pro-server-go-sdk/6.1.0"

type FingerprintApiServiceInterface interface {
/*
Expand Down
2 changes: 1 addition & 1 deletion sdk/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (c *Configuration) AddDefaultHeader(key string, value string) {
func NewConfiguration() *Configuration {
cfg := &Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "Swagger-Codegen/7.0.0-test.0/go",
UserAgent: "Swagger-Codegen/6.1.0/go",
region: RegionUS,
}
cfg.basePath = resolveBasePath(cfg.region)
Expand Down
2 changes: 0 additions & 2 deletions sdk/model_map.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package sdk

type Model struct{}

type ModelMap map[string]any

0 comments on commit e17a8fa

Please sign in to comment.