Skip to content

Commit

Permalink
fix: version, push source, scope reset (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-hajek and jan-hajek authored Mar 16, 2024
1 parent 33a8382 commit 705d994
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 35 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,39 @@ jobs:
include:
- name: linux amd64
os: ubuntu-latest
buildCmd: env GOOS=linux GOARCH=amd64 go build -o builds/zcli-linux-amd64 -ldflags "-s -w -X github.com/zeropsio/zcli/src/cmd/zcli.Version=${{ github.event.release.tag_name }}" ./cmd/zcli/main.go
buildCmd: env GOOS=linux GOARCH=amd64 go build -o builds/zcli-linux-amd64 -ldflags "-s -w -X github.com/zeropsio/zcli/src/cmd.version=${{ github.event.release.tag_name }}" ./cmd/zcli/main.go
file: zcli-linux-amd64
compress: true
strip: true
runLint: true
runTests: true
- name: linux 386
os: ubuntu-latest
buildCmd: env GOOS=linux GOARCH=386 go build -o builds/zcli-linux-i386 -ldflags "-s -w -X github.com/zeropsio/zcli/src/cmd/zcli.Version=${{ github.event.release.tag_name }}" ./cmd/zcli/main.go
buildCmd: env GOOS=linux GOARCH=386 go build -o builds/zcli-linux-i386 -ldflags "-s -w -X github.com/zeropsio/zcli/src/cmd.version=${{ github.event.release.tag_name }}" ./cmd/zcli/main.go
file: zcli-linux-i386
compress: true
strip: true
runLint: true
runTests: true
- name: darwin amd64
os: macos-latest
buildCmd: env GOOS=darwin GOARCH=amd64 go build -o builds/zcli-darwin-amd64 -ldflags "-s -w -X github.com/zeropsio/zcli/src/cmd/zcli.Version=${{ github.event.release.tag_name }}" ./cmd/zcli/main.go
buildCmd: env GOOS=darwin GOARCH=amd64 go build -o builds/zcli-darwin-amd64 -ldflags "-s -w -X github.com/zeropsio/zcli/src/cmd.version=${{ github.event.release.tag_name }}" ./cmd/zcli/main.go
file: zcli-darwin-amd64
compress: false
strip: false
runLint: true
runTests: true
- name: darwin arm64
os: macos-latest
buildCmd: env GOOS=darwin GOARCH=arm64 go build -o builds/zcli-darwin-arm64 -ldflags "-s -w -X github.com/zeropsio/zcli/src/cmd/zcli.Version=${{ github.event.release.tag_name }}" ./cmd/zcli/main.go
buildCmd: env GOOS=darwin GOARCH=arm64 go build -o builds/zcli-darwin-arm64 -ldflags "-s -w -X github.com/zeropsio/zcli/src/cmd.version=${{ github.event.release.tag_name }}" ./cmd/zcli/main.go
file: zcli-darwin-arm64
compress: false
strip: false
runLint: false
runTests: false
- name: windows amd64
os: ubuntu-latest
buildCmd: env GOOS=windows GOARCH=amd64 go build -o builds/zcli-win-x64.exe -ldflags "-s -w -X github.com/zeropsio/zcli/src/cmd/zcli.Version=${{ github.event.release.tag_name }}" ./cmd/zcli/main.go
buildCmd: env GOOS=windows GOARCH=amd64 go build -o builds/zcli-win-x64.exe -ldflags "-s -w -X github.com/zeropsio/zcli/src/cmd.version=${{ github.event.release.tag_name }}" ./cmd/zcli/main.go
file: zcli-win-x64.exe
compress: false
strip: false
Expand Down
17 changes: 11 additions & 6 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"time"

"github.com/zeropsio/zcli/src/cmd/scope"
"github.com/zeropsio/zcli/src/cmdBuilder"
"github.com/zeropsio/zcli/src/constants"
"github.com/zeropsio/zcli/src/entity/repository"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/zeropsio/zcli/src/nettools"
"github.com/zeropsio/zcli/src/uxBlock"
"github.com/zeropsio/zcli/src/uxBlock/styles"
"github.com/zeropsio/zerops-go/errorCode"
)

func ExecuteCmd() error {
Expand Down Expand Up @@ -66,14 +68,17 @@ func rootCmd() *cmdBuilder.Cmd {
projectId, _ := cmdData.CliStorage.Data().ScopeProjectId.Get()
project, err := repository.GetProjectById(ctx, cmdData.RestApiClient, projectId)
if err != nil {
if errorsx.IsUserError(err) {
cmdData.UxBlocks.PrintWarning(styles.WarningLine(i18n.T(i18n.ScopedProjectNotFound)))
if errorsx.Check(err, errorsx.CheckErrorCode(errorCode.ProjectNotFound)) {
err := scope.ProjectScopeReset(cmdData)
if err != nil {
return err
}
} else {
body.AddStringsRow(i18n.T(i18n.ScopedProject), err.Error())
}

return err
} else {
body.AddStringsRow(i18n.T(i18n.ScopedProject), fmt.Sprintf("%s [%s]", project.Name.String(), project.ID.Native()))
}

body.AddStringsRow(i18n.T(i18n.ScopedProject), fmt.Sprintf("%s [%s]", project.Name.String(), project.ID.Native()))
}

ctx, cancel := context.WithTimeout(ctx, time.Second*5)
Expand Down
30 changes: 23 additions & 7 deletions src/cmd/scope/scopeProject.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package scope
import (
"context"

"github.com/zeropsio/zcli/src/cliStorage"
"github.com/zeropsio/zcli/src/cmdBuilder"
"github.com/zeropsio/zcli/src/entity"
"github.com/zeropsio/zcli/src/entity/repository"
Expand Down Expand Up @@ -38,14 +39,17 @@ func (p *project) LoadSelectedScope(ctx context.Context, cmd *cmdBuilder.Cmd, cm

project, err = repository.GetProjectById(ctx, cmdData.RestApiClient, projectId)
if err != nil {
return errorsx.Convert(
err,
errorsx.ConvertInvalidUserInput("id", i18n.T(i18n.ErrorInvalidScopedProjectId)),
errorsx.ConvertErrorCode(errorCode.ProjectNotFound, i18n.T(i18n.ScopedProjectNotFound)),
)
if errorsx.Check(err, errorsx.CheckErrorCode(errorCode.ProjectNotFound)) {
err := ProjectScopeReset(cmdData)
if err != nil {
return err
}
} else {
return err
}
} else {
infoText = i18n.ScopedProject
}

infoText = i18n.ScopedProject
}

if projectId, exists := cmdData.Args[ProjectArgName]; exists {
Expand Down Expand Up @@ -86,3 +90,15 @@ func (p *project) LoadSelectedScope(ctx context.Context, cmd *cmdBuilder.Cmd, cm

return nil
}

func ProjectScopeReset(cmdData *cmdBuilder.LoggedUserCmdData) error {
_, err := cmdData.CliStorage.Update(func(data cliStorage.Data) cliStorage.Data {
data.ScopeProjectId = uuid.ProjectIdNull{}
return data
})
if err != nil {
return err
}

return nil
}
8 changes: 2 additions & 6 deletions src/cmd/scopeReset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package cmd
import (
"context"

"github.com/zeropsio/zcli/src/cliStorage"
"github.com/zeropsio/zcli/src/cmd/scope"
"github.com/zeropsio/zcli/src/cmdBuilder"
"github.com/zeropsio/zcli/src/i18n"
"github.com/zeropsio/zcli/src/uxBlock/styles"
"github.com/zeropsio/zerops-go/types/uuid"
)

func scopeResetCmd() *cmdBuilder.Cmd {
Expand All @@ -16,10 +15,7 @@ func scopeResetCmd() *cmdBuilder.Cmd {
Short(i18n.T(i18n.CmdScopeReset)).
HelpFlag(i18n.T(i18n.ScopeResetHelp)).
LoggedUserRunFunc(func(ctx context.Context, cmdData *cmdBuilder.LoggedUserCmdData) error {
_, err := cmdData.CliStorage.Update(func(data cliStorage.Data) cliStorage.Data {
data.ScopeProjectId = uuid.ProjectIdNull{}
return data
})
err := scope.ProjectScopeReset(cmdData)
if err != nil {
return err
}
Expand Down
8 changes: 1 addition & 7 deletions src/cmd/servicePush.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func servicePushCmd() *cmdBuilder.Cmd {
StringFlag("workingDir", "./", i18n.T(i18n.BuildWorkingDir)).
StringFlag("archiveFilePath", "", i18n.T(i18n.BuildArchiveFilePath)).
StringFlag("versionName", "", i18n.T(i18n.BuildVersionName)).
StringFlag("source", "", i18n.T(i18n.SourceName)).
StringFlag("zeropsYamlPath", "", i18n.T(i18n.ZeropsYamlLocation)).
BoolFlag("deployGitFolder", false, i18n.T(i18n.UploadGitFolder)).
HelpFlag(i18n.T(i18n.ServicePushHelp)).
Expand Down Expand Up @@ -144,18 +143,13 @@ func servicePushCmd() *cmdBuilder.Cmd {

uxBlocks.PrintInfo(styles.InfoLine(i18n.T(i18n.BuildDeployDeployingStart)))

sourceName := cmdData.Params.GetString("source")
if sourceName == "" {
sourceName = cmdData.Service.Name.String()
}

deployResponse, err := cmdData.RestApiClient.PutAppVersionBuildAndDeploy(ctx,
dtoPath.AppVersionId{
Id: appVersion.Id,
},
body.PutAppVersionBuildAndDeploy{
ZeropsYaml: types.MediumText(configContent),
Source: types.NewStringNull(sourceName),
Source: types.NewStringNull("CLI"),
},
)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"github.com/zeropsio/zcli/src/i18n"
)

var Version string
var version string

func versionCmd() *cmdBuilder.Cmd {
return cmdBuilder.NewCmd().
Use("version").
Short(i18n.T(i18n.CmdVersion)).
HelpFlag(i18n.T(i18n.VersionHelp)).
GuestRunFunc(func(ctx context.Context, cmdData *cmdBuilder.GuestCmdData) error {
fmt.Printf("zcli version %s (%s) %s/%s\n", Version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
fmt.Printf("zcli version %s (%s) %s/%s\n", version, runtime.Version(), runtime.GOOS, runtime.GOARCH)

return nil
})
Expand Down
1 change: 0 additions & 1 deletion src/i18n/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ var en = map[string]string{
RegionFlag: "Choose one of Zerops regions. Use the \"zcli region list\" command to list all Zerops regions.",
RegionUrlFlag: "Zerops region file url.",
BuildVersionName: "Adds a custom version name. Automatically filled if the VERSIONNAME environment variable exists.",
SourceName: "Override zerops.yml service name.",
BuildWorkingDir: "Sets a custom working directory. Default working directory is the current directory.",
BuildArchiveFilePath: "If set, zCLI creates a tar.gz archive with the application code in the required path relative\nto the working directory. By default, no archive is created.",
ZeropsYamlLocation: "Sets a custom path to the zerops.yml file relative to the working directory. By default zCLI\nlooks for zerops.yml in the working directory.",
Expand Down
1 change: 0 additions & 1 deletion src/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const (
RegionFlag = "RegionFlag"
RegionUrlFlag = "RegionUrlFlag"
BuildVersionName = "BuildVersionName"
SourceName = "SourceName"
BuildWorkingDir = "BuildWorkingDir"
BuildArchiveFilePath = "BuildArchiveFilePath"
ZeropsYamlLocation = "ZeropsYamlLocation"
Expand Down

0 comments on commit 705d994

Please sign in to comment.