From c1848ca8cf5c9883c889c0999dc11137224eacab Mon Sep 17 00:00:00 2001 From: Devin Pastoor Date: Fri, 1 Jul 2022 07:18:35 -0400 Subject: [PATCH 01/10] feat: add arm + update install instructions for linux admin vs user --- .goreleaser.yml | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 24fe19b..93f0e43 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -24,6 +24,17 @@ release: sudo chmod +x /usr/local/bin/qvm ``` + ### Linux User + + Assumes `~/bin` is available in your PATH + + ``` + wget https://github.com/dpastoor/qvm/releases/download/{{ .Tag }}/qvm_Linux_x86_64.tar.gz -O /tmp/qvm.tar.gz + tar xzf /tmp/qvm.tar.gz qvm + mv qvm ~/bin/qvm + chmod +x ~/bin/qvm + ``` + before: hooks: - go mod tidy @@ -40,10 +51,14 @@ builds: - linux goarch: - amd64 - # - arm64 - # - arm - # goarm: - # - "7" + - arm64 + - arm + ignore: + - goos: darwin + goarch: '386' + +universal_binaries: +- replace: true archives: - name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' From d240edc01e11714f3f900a55c4ea8b4be2d82deb Mon Sep 17 00:00:00 2001 From: Devin Pastoor Date: Fri, 1 Jul 2022 08:28:38 -0400 Subject: [PATCH 02/10] fix: add brew env token since can't use GITHUB_TOKEN since that is repo scoped now --- .goreleaser.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 93f0e43..2b3970b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -52,10 +52,8 @@ builds: goarch: - amd64 - arm64 - - arm - ignore: - - goos: darwin - goarch: '386' + goarm: + - "7" universal_binaries: - replace: true @@ -83,6 +81,7 @@ brews: owner: dpastoor name: homebrew-tap folder: Formula + token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}" goarm: "7" test: | system "#{bin}/qvm -v" From 64c94de51514a335a3feff04936a12d9b7b424da Mon Sep 17 00:00:00 2001 From: Devin Pastoor Date: Fri, 1 Jul 2022 14:40:32 -0400 Subject: [PATCH 03/10] feat: add interactivity for use if no version selected --- cmd/use.go | 30 +++++++++++++++++++++--------- internal/config/fs.go | 27 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/cmd/use.go b/cmd/use.go index 616395e..2c08fa5 100644 --- a/cmd/use.go +++ b/cmd/use.go @@ -33,24 +33,32 @@ func newUse(useOpts useOpts, version string) error { if len(iv) == 0 { return errors.New("no installed versions found, please install a version first") } + if version == "latest" { + version = versions[0] + } if version == "" { - - err := survey.AskOne(&survey.Select{ - Message: "Which version do you want to install?", + // not worried about an error here as an active version of + // empty string just won't match any description below + activeVersion, _ := config.GetActiveVersion() + err = survey.AskOne(&survey.Select{ + Message: "Which version do you want to use?", Options: versions, - }, &version) + Description: func(value string, index int) string { + if value == activeVersion { + return fmt.Sprintf("%s (active)", value) + } + return value + }, + }, &version, survey.WithPageSize(10)) if err != nil { return err } } - if version == "latest" { - version = versions[0] - } quartopath, ok := iv[version] if !ok { return fmt.Errorf("version %s not found", version) } - err = os.MkdirAll(config.GetPathToActiveBinDir(), 0700) + err = os.MkdirAll(config.GetPathToActiveBinDir(), 0755) if err != nil { return err } @@ -97,7 +105,11 @@ func newUseCmd() *useCmd { RunE: func(_ *cobra.Command, args []string) error { //TODO: Add your logic to gather config to pass code here log.WithField("opts", fmt.Sprintf("%+v", root.opts)).Trace("use-opts") - if err := newUse(root.opts, args[0]); err != nil { + var version string + if len(args) > 0 { + version = args[0] + } + if err := newUse(root.opts, version); err != nil { return err } return nil diff --git a/internal/config/fs.go b/internal/config/fs.go index 4e27deb..79d230f 100644 --- a/internal/config/fs.go +++ b/internal/config/fs.go @@ -1,6 +1,7 @@ package config import ( + "errors" "fmt" "os" "path/filepath" @@ -34,10 +35,36 @@ func GetPathToActiveBinDir() string { return path } +func GetPathToActiveQuartoExe() string { + quartoExe := "quarto" + if runtime.GOOS == "windows" { + quartoExe = "quarto.cmd" + } + return filepath.Join(GetPathToActiveBinDir(), quartoExe) +} func GetPathToVersionsDir() string { return filepath.Join(xdg.DataHome, "qvm", "versions") } +func GetActiveVersion() (string, error) { + path, err := filepath.EvalSymlinks(GetPathToActiveQuartoExe()) + if err != nil { + if os.IsNotExist(err) { + return "", errors.New("no active quarto version detected") + } + return "", err + } + // the path should resolve to .../versions//bin/quarto + // could also consider filepath.SplitList + version := filepath.Base(filepath.Dir(filepath.Dir(path))) + if version == "." { + return "", errors.New(` + something went wrong with the active version detection, + please contact the developers`) + } + return version, nil +} + // GetInstalledVersions returns a map of installed versions where they key is the version // and the value is the path to the quarto executable func GetInstalledVersions() (map[string]string, error) { From 1caee05cb8b07b20f63634a78e68ccf8d0e91948 Mon Sep 17 00:00:00 2001 From: Devin Pastoor Date: Fri, 1 Jul 2022 14:47:07 -0400 Subject: [PATCH 04/10] refactor: align structure with install --- cmd/use.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/use.go b/cmd/use.go index 2c08fa5..0095955 100644 --- a/cmd/use.go +++ b/cmd/use.go @@ -45,9 +45,9 @@ func newUse(useOpts useOpts, version string) error { Options: versions, Description: func(value string, index int) string { if value == activeVersion { - return fmt.Sprintf("%s (active)", value) + return "**active**" } - return value + return "" }, }, &version, survey.WithPageSize(10)) if err != nil { From 7e906f13a2497ff7df6908d873b94e0b6bc63584 Mon Sep 17 00:00:00 2001 From: Devin Pastoor Date: Fri, 1 Jul 2022 14:54:49 -0400 Subject: [PATCH 05/10] refactor: minor tweak in error handling --- internal/config/fs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/fs.go b/internal/config/fs.go index 79d230f..c9f9a6b 100644 --- a/internal/config/fs.go +++ b/internal/config/fs.go @@ -49,7 +49,7 @@ func GetPathToVersionsDir() string { func GetActiveVersion() (string, error) { path, err := filepath.EvalSymlinks(GetPathToActiveQuartoExe()) if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, os.ErrNotExist) { return "", errors.New("no active quarto version detected") } return "", err From 89c076458fb20d43f0b8c9fb70da2a738e8bc623 Mon Sep 17 00:00:00 2001 From: Devin Pastoor Date: Fri, 1 Jul 2022 14:59:40 -0400 Subject: [PATCH 06/10] refactor: use new helper --- cmd/ls.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cmd/ls.go b/cmd/ls.go index 73e7dc6..884aac4 100644 --- a/cmd/ls.go +++ b/cmd/ls.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "os" - "path/filepath" "sort" "github.com/dpastoor/qvm/internal/config" @@ -36,10 +35,6 @@ func newLs(lsOpts lsOpts) error { fmt.Printf("%s | %s | %s\n", r.GetTagName(), createdAt.Format("2006-01-02"), r.GetName()) } } else { - activePath, err := filepath.EvalSymlinks(filepath.Join(config.GetPathToActiveBinDir(), "quarto")) - if err != nil && !errors.Is(err, os.ErrNotExist) { - return err - } entries, err := os.ReadDir(config.GetPathToVersionsDir()) if errors.Is(err, os.ErrNotExist) { fmt.Println("No installed quarto versions found") @@ -61,11 +56,14 @@ func newLs(lsOpts lsOpts) error { sort.Slice(entries, func(i, j int) bool { return entries[i].Name() > entries[j].Name() }) + // no need to worry about errors since just need to know version + // for matching below and won't match if doesn't exist + activeVersion, _ := config.GetActiveVersion() for _, e := range entries { if e.IsDir() { dinfo, _ := e.Info() name := e.Name() - if filepath.Base(filepath.Dir(filepath.Dir(activePath))) == e.Name() { + if activeVersion == e.Name() { name += " (active)" } else { name += " " From 2085b2899d91150e7ea06b3bd362653ac618814a Mon Sep 17 00:00:00 2001 From: Devin Pastoor Date: Fri, 1 Jul 2022 15:00:15 -0400 Subject: [PATCH 07/10] doc: update readme to current functionality and remove some idealistic functionality that doesn't exist --- README.md | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7e55ae1..9a8f6ef 100644 --- a/README.md +++ b/README.md @@ -94,8 +94,6 @@ which ones are available remotely? ``` qvm ls --remote -qvm ls --remote --since 2022-05-01 # releases since 2022-05-01, follows YYYY-MM-DD -qvm ls --remote -n 10 # latest 10 releases ``` ### installing versions @@ -111,8 +109,20 @@ running `qvm install` qvm install ``` - - +``` +qvm install +? Which version do you want to install? [Use arrows to move, type to filter] +> v0.9.637 + v0.9.636 - **installed** + v0.9.634 + v0.9.633 + v0.9.632 + v0.9.629 - **installed** + v0.9.628 + v0.9.626 + v0.9.624 + v0.9.622 +``` ```shell qvm install $QUARTO_VERSION $ANOTHER_QUARTO_VERSION @@ -134,15 +144,22 @@ qvm install latest qvm use $QUARTO_VERSION ``` -### using a version in a particular shell session +To interactively select a version, run `qvm use` -At any point can use a particular version in your shell session: - -```shell -qvm use $QUARTO_VERSION --local ``` - - +qvm use +? Which version do you want to use? [Use arrows to move, type to filter] +> v0.9.636 + v0.9.629 - **active** + v0.9.587 + v0.9.583 + v0.9.565 + v0.9.563 + v0.9.562 + v0.9.561 + v0.9.559 + v0.9.550 +``` ### programmatic support utilities ```shell From 6ca7abc3e6bc07051ce372879a73468c44751b44 Mon Sep 17 00:00:00 2001 From: Devin Pastoor Date: Fri, 1 Jul 2022 15:04:11 -0400 Subject: [PATCH 08/10] fixup: tap token location --- .goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 2b3970b..02980b0 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -80,8 +80,8 @@ brews: tap: owner: dpastoor name: homebrew-tap + token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}" folder: Formula - token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}" goarm: "7" test: | system "#{bin}/qvm -v" From d20291f1bab601218714a11ccf2b0e514f558070 Mon Sep 17 00:00:00 2001 From: Devin Pastoor Date: Fri, 1 Jul 2022 15:15:56 -0400 Subject: [PATCH 09/10] chore: attempt to switch to secret --- .goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 02980b0..5f78443 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -80,7 +80,7 @@ brews: tap: owner: dpastoor name: homebrew-tap - token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}" + token: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} folder: Formula goarm: "7" test: | From aa6c6c4f150f671f93eab4d5f59c79cf773445cf Mon Sep 17 00:00:00 2001 From: Devin Pastoor Date: Fri, 1 Jul 2022 15:34:54 -0400 Subject: [PATCH 10/10] chore: try again --- .github/workflows/build.yml | 2 +- .goreleaser.yml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bd5b3d3..880d901 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -89,6 +89,6 @@ jobs: - name: goreleaser-release if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} FURY_TOKEN: ${{ secrets.FURY_TOKEN }} run: task goreleaser \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml index 5f78443..074f46c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -80,7 +80,6 @@ brews: tap: owner: dpastoor name: homebrew-tap - token: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} folder: Formula goarm: "7" test: |