Skip to content

Commit b323726

Browse files
committed
fix: env vars setup
1 parent 3246e67 commit b323726

6 files changed

Lines changed: 27 additions & 51 deletions

File tree

.github/workflows/release.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,13 @@ jobs:
7474
- name: Install Task
7575
uses: go-task/setup-task@v1
7676

77-
- name: Set version in environment
78-
run: |
79-
export VERSION_MAJOR=${{ needs.create-release.outputs.MAJOR }}
80-
export VERSION_MINOR=${{ needs.create-release.outputs.MINOR }}
81-
export VERSION_PATCH=${{ needs.create-release.outputs.PATCH }}
82-
export VERSION_BUILD=${{ github.run_number }}
83-
echo "VERSION_MAJOR=$VERSION_MAJOR" >> $GITHUB_ENV
84-
echo "VERSION_MINOR=$VERSION_MINOR" >> $GITHUB_ENV
85-
echo "VERSION_PATCH=$VERSION_PATCH" >> $GITHUB_ENV
86-
echo "VERSION_BUILD=$VERSION_BUILD" >> $GITHUB_ENV
87-
8877
- name: Build for ${{ matrix.os }}-${{ matrix.arch }}
8978
env:
9079
MBVPN_HOLOCRON_URL: ${{ vars.MBVPN_HOLOCRON_URL }}
80+
VERSION_MAJOR: ${{ needs.create-release.outputs.MAJOR }}
81+
VERSION_MINOR: ${{ needs.create-release.outputs.MINOR }}
82+
VERSION_PATCH: ${{ needs.create-release.outputs.PATCH }}
83+
VERSION_BUILD: ${{ github.run_number }}
9184
run: |
9285
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} task build-release
9386
mv mbvpn ${{ env.BINARY_NAME }}

Taskfile.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ vars:
2727
-X '{{.GO_PKG}}/pkg/config.HolocronUrl={{.MBVPN_HOLOCRON_URL}}'
2828
2929
# Debug flags
30-
DEBUG_LDFLAGS: -X '{{.GO_PKG}}/pkg/config.BuildType=debug'
3130
DEBUG_GCFLAGS: -N -l
3231

3332
# Release flags
34-
RELEASE_LDFLAGS: -X '{{.GO_PKG}}/pkg/config.BuildType=release'
3533
RELEASE_BUILDFLAGS: -trimpath
3634

3735
tasks:
@@ -47,7 +45,7 @@ tasks:
4745
go build {{.GOFLAGS}}
4846
-o {{.BINARY_NAME}}
4947
-gcflags="{{.DEBUG_GCFLAGS}}"
50-
-ldflags "{{.COMMON_LDFLAGS}} {{.ENV_LDFLAGS}} {{.DEBUG_LDFLAGS}}"
48+
-ldflags "{{.COMMON_LDFLAGS}} {{.ENV_LDFLAGS}}"
5149
./cmd/mbvpn
5250
5351
build-release:
@@ -57,7 +55,7 @@ tasks:
5755
go build {{.GOFLAGS}}
5856
{{.RELEASE_BUILDFLAGS}}
5957
-o {{.BINARY_NAME}}
60-
-ldflags "{{.COMMON_LDFLAGS}} {{.ENV_LDFLAGS}} {{.RELEASE_LDFLAGS}}"
58+
-ldflags "{{.COMMON_LDFLAGS}} {{.ENV_LDFLAGS}}"
6159
./cmd/mbvpn
6260
6361
test:

cmd/version.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ func NewVersionCommand() *cobra.Command {
1919
Run: func(cmd *cobra.Command, args []string) {
2020
fmt.Printf("Version: %s\n", config.Version())
2121
fmt.Printf("Environment: %s\n", config.BuildEnv)
22-
fmt.Printf("Build Type: %s\n", config.BuildType)
2322
fmt.Printf("Debug Mode: %t\n", config.Debug())
2423
},
2524
}

cmd/version_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,6 @@ func TestVersionCommandOutput(t *testing.T) {
8383
t.Errorf("Expected environment '%s', got '%s'", config.BuildEnv, envValue)
8484
}
8585

86-
// Verify build type value
87-
buildTypeLine := lines[2]
88-
buildTypeValue := strings.TrimPrefix(buildTypeLine, "Build Type: ")
89-
if buildTypeValue != config.BuildType {
90-
t.Errorf("Expected build type '%s', got '%s'", config.BuildType, buildTypeValue)
91-
}
92-
9386
// Verify debug mode value
9487
debugLine := lines[3]
9588
debugValue := strings.TrimPrefix(debugLine, "Debug Mode: ")

pkg/config/env.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import (
88
var (
99
DebugFlag bool
1010
BuildEnv string
11-
BuildType string
1211
HolocronUrl string
13-
12+
1413
// Version information
1514
VersionMajor = "0"
1615
VersionMinor = "0"

test/e2e/version_test.go

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ func TestVersionCommand(t *testing.T) {
1414

1515
// Execute the version command
1616
output, err := execCommand(t, []string{"version"}, homeDir)
17-
17+
1818
// Version command should always succeed
1919
if err != nil {
2020
t.Errorf("Version command failed with error: %v", err)
2121
}
22-
22+
2323
// Check that output contains version information
2424
if !strings.Contains(output, "Version:") {
2525
t.Errorf("Expected 'Version:' in output, got: %s", output)
2626
}
27-
27+
2828
// Check that output contains environment information
2929
if !strings.Contains(output, "Environment:") {
3030
t.Errorf("Expected 'Environment:' in output, got: %s", output)
3131
}
32-
32+
3333
// Check that output contains build type information
3434
if !strings.Contains(output, "Build Type:") {
3535
t.Errorf("Expected 'Build Type:' in output, got: %s", output)
3636
}
37-
37+
3838
// Check that output contains debug mode information
3939
if !strings.Contains(output, "Debug Mode:") {
4040
t.Errorf("Expected 'Debug Mode:' in output, got: %s", output)
@@ -48,47 +48,41 @@ func TestVersionCommandFormat(t *testing.T) {
4848

4949
// Execute the version command
5050
output, err := execCommand(t, []string{"version"}, homeDir)
51-
51+
5252
if err != nil {
5353
t.Errorf("Version command failed with error: %v", err)
5454
}
55-
55+
5656
lines := strings.Split(strings.TrimSpace(output), "\n")
57-
57+
5858
// Should have exactly 4 lines of output
5959
if len(lines) != 4 {
6060
t.Errorf("Expected 4 lines of output, got %d lines: %s", len(lines), output)
6161
}
62-
62+
6363
// Check version format (should be like "Version: 0.0.1+0")
6464
versionLine := lines[0]
6565
if !strings.HasPrefix(versionLine, "Version: ") {
6666
t.Errorf("First line should start with 'Version: ', got: %s", versionLine)
6767
}
68-
68+
6969
versionValue := strings.TrimPrefix(versionLine, "Version: ")
7070
if !strings.Contains(versionValue, ".") || !strings.Contains(versionValue, "+") {
7171
t.Errorf("Version should be in format 'major.minor.patch+build', got: %s", versionValue)
7272
}
73-
73+
7474
// Check environment line
7575
envLine := lines[1]
7676
if !strings.HasPrefix(envLine, "Environment: ") {
7777
t.Errorf("Second line should start with 'Environment: ', got: %s", envLine)
7878
}
79-
80-
// Check build type line
81-
buildTypeLine := lines[2]
82-
if !strings.HasPrefix(buildTypeLine, "Build Type: ") {
83-
t.Errorf("Third line should start with 'Build Type: ', got: %s", buildTypeLine)
84-
}
85-
79+
8680
// Check debug mode line
8781
debugLine := lines[3]
8882
if !strings.HasPrefix(debugLine, "Debug Mode: ") {
8983
t.Errorf("Fourth line should start with 'Debug Mode: ', got: %s", debugLine)
9084
}
91-
85+
9286
debugValue := strings.TrimPrefix(debugLine, "Debug Mode: ")
9387
if debugValue != "true" && debugValue != "false" {
9488
t.Errorf("Debug Mode should be 'true' or 'false', got: %s", debugValue)
@@ -102,19 +96,19 @@ func TestVersionCommandWithDebugFlag(t *testing.T) {
10296

10397
// Execute the version command with debug flag
10498
output, err := execCommand(t, []string{"version", "--debug"}, homeDir)
105-
99+
106100
if err != nil {
107101
t.Errorf("Version command with debug flag failed with error: %v", err)
108102
}
109-
103+
110104
// Should still contain all version information
111105
expectedFields := []string{"Version:", "Environment:", "Build Type:", "Debug Mode:"}
112106
for _, field := range expectedFields {
113107
if !strings.Contains(output, field) {
114108
t.Errorf("Expected '%s' in output, got: %s", field, output)
115109
}
116110
}
117-
111+
118112
// When debug flag is used, debug mode should be true
119113
if !strings.Contains(output, "Debug Mode: true") {
120114
t.Errorf("Expected 'Debug Mode: true' when using --debug flag, got: %s", output)
@@ -128,17 +122,17 @@ func TestVersionCommandWithHelp(t *testing.T) {
128122

129123
// Execute the version command with help flag
130124
output, err := execCommand(t, []string{"version", "--help"}, homeDir)
131-
125+
132126
if err != nil {
133127
t.Errorf("Version command with help flag failed with error: %v", err)
134128
}
135-
129+
136130
// Should show help text
137131
if !strings.Contains(output, "Display the application version, build environment and build type") {
138132
t.Errorf("Expected help text in output, got: %s", output)
139133
}
140-
134+
141135
if !strings.Contains(output, "Usage:") {
142136
t.Errorf("Expected usage information in output, got: %s", output)
143137
}
144-
}
138+
}

0 commit comments

Comments
 (0)