Skip to content

Commit 00a66ab

Browse files
committed
Refactor version handling and update build process in release workflow
- Changed version declaration to embed version information directly from a file, improving version management. - Updated the build step in release.yml to write the version to a file before building the CLI, streamlining the build process.
1 parent 89ca2ef commit 00a66ab

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,10 @@ jobs:
3131
echo "Extracted version: $VERSION"
3232
echo "version=$VERSION" >> $GITHUB_OUTPUT
3333
34-
# - name: Build CLI with version
35-
# run: |
36-
# # Asume que tu main.go está en el directorio cmd/cli
37-
# go build -ldflags="-X 'main.Version=${{ steps.version.outputs.version }}'" -o netsocs .
38-
39-
- name: Build and Push CLI
40-
uses: docker/build-push-action@v5
41-
with:
42-
context: cli
43-
platforms: linux/amd64
44-
provenance: false
45-
push: false
46-
tags: |
47-
${{ env.REGISTRY }}/netsocs-team/netsocs-cli/main:${{ steps.branch.outputs.branch }}
48-
${{ env.REGISTRY }}/netsocs-team/netsocs-cli/main:${{ github.sha }}
49-
build-args: |
50-
VERSION=${{ steps.version.outputs.version }}
34+
- name: Build CLI with version
35+
run: |
36+
echo "${{ steps.version.outputs.version }}" > version
37+
go build -o netsocs .
5138
5239
- name: Create Release
5340
uses: softprops/action-gh-release@v1

main.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@ import (
1212
commandstatus "github.com/Netsocs-Team/netsocs-manager-cli/command_status"
1313
commandupgrade "github.com/Netsocs-Team/netsocs-manager-cli/command_upgrade"
1414
"github.com/Netsocs-Team/netsocs-manager-cli/utils"
15-
1615
"github.com/spf13/cobra"
16+
_ "embed"
1717
)
1818

19-
var (
20-
version = "v0.0.0"
21-
)
19+
//go:embed version
20+
var versionBytes []byte
21+
22+
var version = GetVersion()
23+
24+
func GetVersion() string {
25+
version := string(versionBytes)
26+
version = strings.ReplaceAll(version, "\n", "")
27+
return string(version)
28+
}
2229

2330
var rootCmd = &cobra.Command{
2431
Use: "netsocs-manager-cli",

0 commit comments

Comments
 (0)