This is an automated email from the ASF dual-hosted git repository. msciabarra pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/openserverless-cli.git
commit 8f1c3cbf8a1e8416f377db052f8620765f02bf59 Author: Michele Sciabarra <[email protected]> AuthorDate: Wed Jul 31 15:02:28 2024 +0200 versioning --- .github/workflows/release.yml | 2 ++ Taskfile.yml | 10 +++--- branch.txt | 2 +- common.go | 2 +- main.go | 42 +++++++++---------------- prepare.go | 18 +++++++---- tests/mvrm.bats | 55 +++++++++++++++++++++++++++++++++ tests/testdata/olaris-other/nuvfile.yml | 2 +- tools/remove.go | 24 ++++++++++++++ tools/rename.go | 24 ++++++++++++++ tools/tools.go | 46 +++++++++++---------------- version.txt | 2 +- 12 files changed, 158 insertions(+), 71 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c3d50a0..56549c7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,6 +20,8 @@ jobs: fetch-depth: 0 - name: Set up Go uses: actions/setup-go@v5 + with: + go-version: '>=1.22.5' - name: Run Tests run: | sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d diff --git a/Taskfile.yml b/Taskfile.yml index eb49f88..f27d1a8 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -18,8 +18,8 @@ version: "3" vars: - BRANCH: "0.1.0-testing" - BASEVER: "0.1.0-testing" + BASEVER: "0.1.0" + VARIANT: "dev" VERSION: sh: git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD DEBUG: "" @@ -29,13 +29,13 @@ tasks: default: task -l setup: { silent:true } - cli-tag: + tag: desc: tag the cli to generate the build cmds: - git tag -d $(git tag) - - echo "{{.BASEVER}}.$(date +%y%m%d%H%M)" >version.txt + - echo "{{.BASEVER}}-$(date +%y%m%d%H%M).{{.VARIANT}}" >version.txt - git tag -f "v$(cat version.txt)" - - echo "{{.BRANCH}}" >branch.txt + - echo "{{.BASEVER}}" >branch.txt - git add version.txt branch.txt - git tag diff --git a/branch.txt b/branch.txt index 19f64bc..6e8bf73 100644 --- a/branch.txt +++ b/branch.txt @@ -1 +1 @@ -0.1.0-testing +0.1.0 diff --git a/common.go b/common.go index 62852f2..0012ff5 100644 --- a/common.go +++ b/common.go @@ -172,7 +172,7 @@ func trace(args ...any) { } } -var debugging = os.Getenv("DEBUG") != "" +var debugging = os.Getenv("DEBUG") != "" || os.Getenv("TRACE") != "" func debug(args ...any) { if debugging { diff --git a/main.go b/main.go index 08621d3..3c892da 100644 --- a/main.go +++ b/main.go @@ -104,17 +104,12 @@ func info() { fmt.Println("NUV_ROOT_PLUGIN:", os.Getenv("NUV_ROOT_PLUGIN")) } -// execute the embedded tools -// version -// info -// help -// serve -// update -// retry -// login -// config -// plugin -func executeEmbeddedToolsAndExit(cmd string, args []string, nuvHome string) int { +// not available in taskfiles +var mainTools = []string{ + "task", "version", "info", "help", "serve", "update", "retry", "login", "config", "plugin", +} + +func executeMainToolsAndExit(cmd string, args []string, nuvHome string) int { if cmd == "" || cmd == "-" || cmd == "task" { exitCode, err := Task(args[2:]...) if err != nil { @@ -133,7 +128,7 @@ func executeEmbeddedToolsAndExit(cmd string, args []string, nuvHome string) int info() case "help": - tools.Help() + tools.Help(mainTools) case "serve": nuvRootDir := getRootDirOrExit() @@ -150,10 +145,6 @@ func executeEmbeddedToolsAndExit(cmd string, args []string, nuvHome string) int if err := setNuvOlarisHash(dir); err != nil { log.Fatal("unable to set NUV_OLARIS...", err.Error()) } - err = ensurePrereq(dir) - if err != nil { - log.Fatalf("cannot download prerequisites: %v", err) - } case "retry": if err := tools.ExpBackoffRetry(args[1:]); err != nil { @@ -175,7 +166,7 @@ func executeEmbeddedToolsAndExit(cmd string, args []string, nuvHome string) int if err := wskPropertySet(loginResult.ApiHost, loginResult.Auth); err != nil { log.Fatalf("error: %s", err.Error()) } - fmt.Println("Nuvolaris host and auth set successfully. You are now ready to use nuv -wsk!") + fmt.Println("OpenServerless host and auth set successfully. You are now ready to use ops!") case "config": os.Args = args[1:] @@ -235,7 +226,7 @@ func Main() { // setup OPS_CMD me := args[0] if strings.Contains("ops ops.exe nuv nuv.exe", filepath.Base(me)) { - tools.NuvCmd, err = setupCmd(me) + _, err = setupCmd(me) if err != nil { log.Fatalf("cannot setup cmd: %s", err.Error()) } @@ -269,6 +260,9 @@ func Main() { log.Fatalf("cannot setup NUV_PWD: %s", err.Error()) } + // setup the envvar for the embedded tools + os.Setenv("OPS_TOOLS", strings.Join(append(mainTools, tools.ToolList...), " ")) + // NUV_REPO && NUV_ROOT_PLUGIN getNuvRepo() setNuvRootPluginEnv() @@ -278,7 +272,7 @@ func Main() { if err != nil { olarisDir := joinpath(joinpath(nuvHome, getNuvBranch()), "olaris") if !isDir(olarisDir) { - log.Println("Welcome to nuv! Setting up...") + log.Println("Welcome to ops! Setting up...") olarisDir, err = pullTasks(true, true) if err != nil { log.Fatalf("cannot locate or download NUV_ROOT: %s", err.Error()) @@ -335,18 +329,10 @@ func Main() { cmd := args[1][1:] trace("executing embedded tool", cmd, args) // execute the embeded tool and exit - exitCode := executeEmbeddedToolsAndExit(cmd, args, nuvHome) + exitCode := executeMainToolsAndExit(cmd, args, nuvHome) os.Exit(exitCode) } - // *************** executing tasks - - // ensure prerequisites - err = ensurePrereq(nuvRootDir) - if err != nil { - log.Fatalf("cannot ensure prerequisites: %s", err.Error()) - } - if err := runNuv(nuvRootDir, args); err != nil { log.Fatalf("task execution error: %s", err.Error()) } diff --git a/prepare.go b/prepare.go index 7c7413d..38ed336 100644 --- a/prepare.go +++ b/prepare.go @@ -18,6 +18,7 @@ package openserverless import ( "fmt" + "log" "os" "os/exec" "path/filepath" @@ -99,7 +100,7 @@ func downloadTasksFromGitHub(force bool, silent bool) (string, error) { return "", err } - fmt.Println("Nuvfiles downloaded successfully") + fmt.Println("Tasks downloaded successfully") createLatestCheckFile(nuvBranchDir) @@ -115,6 +116,11 @@ func pullTasks(force, silent bool) (string, error) { return "", err } + err = ensurePrereq(localDir) + if err != nil { + log.Fatalf("cannot download prerequisites: %v", err) + } + // validate NuvVersion semver against nuvroot.json nuvRoot, err := readNuvRootFile(localDir) if err != nil { @@ -138,8 +144,7 @@ func pullTasks(force, silent bool) (string, error) { // check if the version is up to date, if not warn the user if nuvVersion.LessThan(nuvRootVersion) { fmt.Println() - fmt.Printf("Your nuv version (%v) is older than the required version in nuvroot.json (%v).\n", nuvVersion, nuvRootVersion) - fmt.Println("Attempting to update nuv...") + fmt.Printf("Your ops version (%v) is older than the required version (%v).\n", nuvVersion, nuvRootVersion) if err := autoCLIUpdate(); err != nil { return "", err } @@ -208,8 +213,9 @@ func locateNuvRootSearch(cur string) string { } func autoCLIUpdate() error { - trace("autoCLIUpdate") - cmd := exec.Command("nuv", "update", "cli") + cli := os.Getenv("OPS_CMD") + trace("autoCLIUpdate", cli) + cmd := exec.Command(cli, "util", "update-cli") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return cmd.Run() @@ -221,7 +227,7 @@ func checkOperatorVersion(nuvRootConfig map[string]interface{}) error { operator := images["operator"].(string) opVer := strings.Split(operator, ":")[1] - cmd := exec.Command("nuv", "util", "check-operator-version", opVer) + cmd := exec.Command(os.Getenv("OPS_CMD"), "util", "check-operator-version", opVer) return cmd.Run() } diff --git a/tests/mvrm.bats b/tests/mvrm.bats new file mode 100644 index 0000000..76947b8 --- /dev/null +++ b/tests/mvrm.bats @@ -0,0 +1,55 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +setup() { + load 'test_helper/bats-support/load' + load 'test_helper/bats-assert/load' + export NO_COLOR=1 +} + +@test "-rename -remove" { + run nuv -rename + assert_line "Usage: rename <source> <destination>" + + run nuv -rename missing + assert_line "Usage: rename <source> <destination>" + + run nuv -rename missing something + assert_failure + assert_line "rename missing something: no such file or directory" + + touch something + run nuv -rename something somethingelse + assert_success + assert_line "renamed something -> somethingelse" + + run nuv -rename somethingelse /dev/null + assert_failure + assert_line "rename somethingelse /dev/null: invalid cross-device link" + + run nuv -remove + assert_line "Usage: remove <filename>" + + run nuv -remove missing + assert_failure + assert_line "remove missing: no such file or directory" + + run nuv -remove somethingelse + assert_success + assert_line "removed somethingelse" +} + diff --git a/tests/testdata/olaris-other/nuvfile.yml b/tests/testdata/olaris-other/nuvfile.yml index b811f80..1de705d 100644 --- a/tests/testdata/olaris-other/nuvfile.yml +++ b/tests/testdata/olaris-other/nuvfile.yml @@ -29,4 +29,4 @@ tasks: command: desc: run nuv setup status cmds: - - nuv setup status + - nuv version diff --git a/tools/remove.go b/tools/remove.go new file mode 100644 index 0000000..1b669f0 --- /dev/null +++ b/tools/remove.go @@ -0,0 +1,24 @@ +package tools + +import ( + "fmt" + "os" +) + +func Remove() (int, error) { + if len(os.Args) != 2 { + fmt.Println("Usage: remove <filename>") + return 0, nil + } + + filename := os.Args[1] + + err := os.Remove(filename) + if err != nil { + return 1, err + } + + fmt.Printf("removed %s\n", filename) + + return 0, nil +} diff --git a/tools/rename.go b/tools/rename.go new file mode 100644 index 0000000..b59dd08 --- /dev/null +++ b/tools/rename.go @@ -0,0 +1,24 @@ +package tools + +import ( + "fmt" + "os" +) + +func Rename() (int, error) { + if len(os.Args) != 3 { + fmt.Println("Usage: rename <source> <destination>") + return 0, nil + } + + source := os.Args[1] + destination := os.Args[2] + + err := os.Rename(source, destination) + if err != nil { + return 1, err + } + + fmt.Printf("renamed %s -> %s\n", source, destination) + return 0, nil +} diff --git a/tools/tools.go b/tools/tools.go index 946e128..df41f00 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -32,23 +32,16 @@ import ( // available in taskfiles // note some of them are implemented in main.go (config, retry) -var tools = []string{ - "awk", "die", "jq", - "envsubst", "wsk", - "filetype", "random", "datefmt", - "config", "retry", "urlenc", - "replace", "base64", "validate", +var ToolList = []string{ + "wsk", "awk", "jq", + "envsubst", "filetype", "random", "datefmt", + "die", "urlenc", "replace", "base64", "validate", "echoif", "echoifempty", "echoifexists", - "needupdate", "gron", "jj", "deploy", -} - -// not available in taskfiles -var extraTools = []string{ - "update", "login", "help", "info", "version", "task", "plugin", "serve", + "needupdate", "gron", "jj", "rename", "remove", } func IsTool(name string) bool { - for _, s := range tools { + for _, s := range ToolList { if s == name { return true } @@ -56,19 +49,6 @@ func IsTool(name string) bool { return false } -var NuvCmd = "" - -func GetNuvCmd() string { - if NuvCmd != "" { - return NuvCmd - } - nuv := os.Getenv("NUV_CMD") - if nuv != "" { - return nuv - } - return "" -} - func RunTool(name string, args []string) (int, error) { switch name { case "wsk": @@ -156,14 +136,24 @@ func RunTool(name string, args []string) (int, error) { case "jj": os.Args = append([]string{"jj"}, args...) return jj.JJMain() + + case "rename": + os.Args = append([]string{"rename"}, args...) + return Rename() + + case "remove": + os.Args = append([]string{"rename"}, args...) + return Remove() + default: + return 1, fmt.Errorf("unknown tool") } return 0, nil } -func Help() { +func Help(mainTools []string) { fmt.Println("Available tools:") - availableTools := append(tools, extraTools...) + availableTools := append(mainTools, ToolList...) slices.Sort(availableTools) for _, x := range availableTools { fmt.Printf("-%s\n", x) diff --git a/version.txt b/version.txt index ba5ea1c..8d7a4ad 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.1.0-testing.2407310845 +0.1.0-2407311501.dev
