Skip to content

Commit 185c509

Browse files
Sylvia Mossazr
andauthored
Fix versioning (#10)
* fix versioning * Update version/version.go Co-authored-by: Adrien Delorme <[email protected]> Co-authored-by: Adrien Delorme <[email protected]>
1 parent ca39467 commit 185c509

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

.goreleaser.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ builds:
2525
flags:
2626
- -trimpath #removes all file system paths from the compiled executable
2727
ldflags:
28-
- '-s -w -X main.Version={{.Version}} -X main.VersionPrerelease= '
28+
- '-s -w -X {{ .ModulePath }}/version.Version={{.Version}} -X {{ .ModulePath }}/version.VersionPrerelease= '
2929
goos:
3030
- linux
3131
goarch:
@@ -36,7 +36,7 @@ builds:
3636
flags:
3737
- -trimpath #removes all file system paths from the compiled executable
3838
ldflags:
39-
- '-s -w -X main.version={{.Version}} -X main.VersionPrerelease= '
39+
- '-s -w -X {{ .ModulePath }}/version.Version={{.Version}} -X {{ .ModulePath }}/version.VersionPrerelease= '
4040
goos:
4141
- freebsd
4242
- windows

builder/ucloud/common/access_config.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"runtime"
1212

1313
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
14-
"github.com/hashicorp/packer-plugin-sdk/version"
14+
"github.com/hashicorp/packer-plugin-ucloud/version"
1515
"github.com/ucloud/ucloud-sdk-go/external"
1616
"github.com/ucloud/ucloud-sdk-go/private/protocol/http"
1717
"github.com/ucloud/ucloud-sdk-go/services/uaccount"
@@ -24,8 +24,6 @@ import (
2424
"github.com/ucloud/ucloud-sdk-go/ucloud/log"
2525
)
2626

27-
var UcloudPluginVersion *version.PluginVersion
28-
2927
type AccessConfig struct {
3028
// This is the UCloud public key. It must be provided unless `profile` is set,
3129
// but it can also be sourced from the `UCLOUD_PUBLIC_KEY` environment variable.
@@ -70,7 +68,7 @@ func (c *AccessConfig) Client() (*UCloudClient, error) {
7068
cfg.BaseUrl = c.BaseUrl
7169
}
7270
cfg.LogLevel = log.PanicLevel
73-
cfg.UserAgent = fmt.Sprintf("Packer-UCloud/%s", UcloudPluginVersion.FormattedVersion())
71+
cfg.UserAgent = fmt.Sprintf("Packer-UCloud/%s", version.PluginVersion.FormattedVersion())
7472
// set default max retry count
7573
cfg.MaxRetries = 3
7674

builder/ucloud/uhost/builder_acc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"github.com/hashicorp/packer-plugin-sdk/acctest"
1111
"github.com/hashicorp/packer-plugin-sdk/acctest/testutils"
1212
"github.com/hashicorp/packer-plugin-sdk/version"
13-
"github.com/hashicorp/packer-plugin-ucloud/builder/ucloud/common"
1413
ucloudcommon "github.com/hashicorp/packer-plugin-ucloud/builder/ucloud/common"
14+
pluginVersion "github.com/hashicorp/packer-plugin-ucloud/version"
1515
"github.com/stretchr/testify/assert"
1616
)
1717

@@ -235,7 +235,7 @@ func testAccPreCheck() error {
235235
func TestUCloudClientBaseUrlConfigurable(t *testing.T) {
236236
const url = "baseUrl"
237237
access := &ucloudcommon.AccessConfig{BaseUrl: url, PublicKey: "test", PrivateKey: "test"}
238-
common.UcloudPluginVersion = version.InitializePluginVersion("0.0.0", "dev")
238+
pluginVersion.PluginVersion = version.InitializePluginVersion("0.0.0", "dev")
239239
client, err := access.Client()
240240
assert.Nil(t, err)
241241
assert.Equal(t, url, client.UAccountConn.Client.GetConfig().BaseUrl, "account conn's base url not configurable")

main.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,16 @@ import (
55
"os"
66

77
"github.com/hashicorp/packer-plugin-sdk/plugin"
8-
"github.com/hashicorp/packer-plugin-sdk/version"
9-
"github.com/hashicorp/packer-plugin-ucloud/builder/ucloud/common"
108
"github.com/hashicorp/packer-plugin-ucloud/builder/ucloud/uhost"
119
ucloudimport "github.com/hashicorp/packer-plugin-ucloud/post-processor/ucloud-import"
12-
)
13-
14-
var (
15-
// Version is the main version number that is being run at the moment.
16-
Version = "0.0.1"
17-
18-
// VersionPrerelease is A pre-release marker for the Version. If this is ""
19-
// (empty string) then it means that it is a final release. Otherwise, this
20-
// is a pre-release such as "dev" (in development), "beta", "rc1", etc.
21-
VersionPrerelease = "dev"
22-
23-
// PluginVersion is used by the plugin set to allow Packer to recognize
24-
// what version this plugin is.
25-
PluginVersion = version.InitializePluginVersion(Version, VersionPrerelease)
10+
"github.com/hashicorp/packer-plugin-ucloud/version"
2611
)
2712

2813
func main() {
2914
pps := plugin.NewSet()
3015
pps.RegisterBuilder("uhost", new(uhost.Builder))
3116
pps.RegisterPostProcessor("import", new(ucloudimport.PostProcessor))
32-
pps.SetVersion(PluginVersion)
33-
common.UcloudPluginVersion = PluginVersion
17+
pps.SetVersion(version.PluginVersion)
3418
err := pps.Run()
3519
if err != nil {
3620
fmt.Fprintln(os.Stderr, err.Error())

version/version.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package version
2+
3+
import "github.com/hashicorp/packer-plugin-sdk/version"
4+
5+
var (
6+
// Version is the main version number that is being run at the moment.
7+
Version = "0.0.2"
8+
9+
// VersionPrerelease is A pre-release marker for the Version. If this is ""
10+
// (empty string) then it means that it is a final release. Otherwise, this
11+
// is a pre-release such as "dev" (in development), "beta", "rc1", etc.
12+
VersionPrerelease = "dev"
13+
14+
// PluginVersion is used by the plugin set to allow Packer to recognize
15+
// what version this plugin is.
16+
PluginVersion = version.InitializePluginVersion(Version, VersionPrerelease)
17+
)

0 commit comments

Comments
 (0)