Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trunk-io/cli #13989

Closed
Gowiem opened this issue Jul 24, 2023 · 19 comments
Closed

Add trunk-io/cli #13989

Gowiem opened this issue Jul 24, 2023 · 19 comments

Comments

@Gowiem
Copy link
Contributor

Gowiem commented Jul 24, 2023

Overview

I would like to add a package for trunk: https://docs.trunk.io/docs/overview

Suggested package name: trunk-io/cli

I would be interested to do this work, but with the way the installation is done, I'm unsure what the best way to do so is.

Their install process is to run: curl https://get.trunk.io -fsSL | bash. Here is the script from that endpoint / installer:

$ curl https://get.trunk.io -fsSL

```bash
#!/bin/bash

set -euo pipefail

check_mark="\033[1;32m✔\033[0m"
header() { echo -e "\n\033[1m$1\033[0m"; }

header "Welcome to Trunk!\n"
echo " This will download and install the latest Trunk Launcher. When you run 'trunk'"
echo " you'll really be running the Trunk Launcher, which figures out which version of"
echo " Trunk to run depending on which repo you're in and downloads it if needed. The"
echo " first time you use Trunk in a repo it will download the latest version."

header "\nThis script will install\n"
echo -e " \033[4m/usr/local/bin/trunk\033[0m\n"

header "Downloading and Installing\n"

echo "  Downloading Trunk Launcher..."
tmp_file=$(mktemp)
curl -fsSL https://trunk.io/releases/trunk -o "${tmp_file}"
echo -e "\033[1A ${check_mark} Downloading Trunk Launcher... done"

echo "   Installing Trunk Launcher (requires sudo access)..."
chmod +x "${tmp_file}"
$(command -v sudo || true) bash -c "mkdir -p /usr/local/bin && mv ${tmp_file} /usr/local/bin/trunk"
echo -e " ${check_mark} Installing Trunk Launcher... done\n"

# Keep this in sync with init.cc
header "Next Steps\n"
echo -e " 1. \033[1mInitialize trunk in a repo\033[0m"
echo -e "    \033[0;90mRun \033[0;36mtrunk init\033[0;90m to setup trunk in a git repo\033[0m\n"
echo -e " 2. \033[1mRead documentation\033[0m"
echo -e "    \033[0;90mOur documentation can be found at \033[0;4mhttps://docs.trunk.io\033[0m\n"
echo -e " 3. \033[1mGet help and give feedback\033[0m"
echo -e "    \033[0;90mJoin the trunk community at \033[0;4mhttps://slack.trunk.io\033[0m"

All curl -fsSL https://trunk.io/releases/trunk outputs is another, much larger bash file sadly.

Are there any similar packages to this one that I could use as inspiration for this contribution?

References

@suzuki-shunsuke
Copy link
Member

suzuki-shunsuke commented Jul 24, 2023

Thank you for opening the issue.

I'm not familiar with this tool, so I'm checking it. 📝

  • There is a GitHub Organization https:/trunk-io , but there is no repository for CLI

Suggested package name: trunk-io/cli

It looks good.

$ curl https://get.trunk.io -fsSL | bash

Welcome to Trunk!

 This will download and install the latest Trunk Launcher. When you run 'trunk'
 you'll really be running the Trunk Launcher, which figures out which version of
 Trunk to run depending on which repo you're in and downloads it if needed. The
 first time you use Trunk in a repo it will download the latest version.


This script will install

 /usr/local/bin/trunk


Downloading and Installing

 ✔ Downloading Trunk Launcher... done
   Installing Trunk Launcher (requires sudo access)...
 ✔ Installing Trunk Launcher... done


Next Steps

 1. Initialize trunk in a repo
    Run trunk init to setup trunk in a git repo

 2. Read documentation
    Our documentation can be found at https://docs.trunk.io

 3. Get help and give feedback
    Join the trunk community at https://slack.trunk.io
$ trunk init
BusyBox v1.36.1 (2023-06-02 00:42:02 UTC) multi-call binary.
BusyBox v1.36.1 (2023-06-02 00:42:02 UTC) multi-call binary.
⡿ Downloading Trunk 1.12.3...
✔ Downloading Trunk 1.12.3... done
✔ Verifying Trunk sha256... done
✔ Unpacking Trunk... done

env: can't execute '/root/.cache/trunk/cli/1.12.3-linux-x86_64/trunk': No such file or directory
a7af56822531:/workspace/foo# echo $?
127

It seems the script downloads an asset and unarchive it into ~/.cache/trunk/cli.

So maybe aqua can download assets from download_url directly.

a7af56822531:/workspace/foo# cat /usr/local/bin/trunk  | grep URL | grep http
    readonly URL="https://trunk.io/releases/${dl_version}/trunk-${dl_version}-${PLATFORM}.tar.gz"
      readonly URL="https://trunk.io/releases/${dl_version}/trunk-${dl_version}-${PLATFORM}.tar.gz"
      readonly URL="https://trunk.io/releases/trunk-${dl_version}.${KERNEL}.tar.gz"
  • https://trunk.io/releases/${dl_version}/trunk-${dl_version}-${PLATFORM}.tar.gz
  • https://trunk.io/releases/trunk-${dl_version}.${KERNEL}.tar.gz
KERNEL=$(uname | tr "[:upper:]" "[:lower:]")
if [[ ${KERNEL} == mingw64* || ${KERNEL} == msys* ]]; then
  KERNEL="mingw"
fi
PLATFORM="${KERNEL}-${MACHINE}"
MACHINE=$(uname -m)
  if sort --help 2>&1 | grep BusyBox; then
    readonly URL="https://trunk.io/releases/${dl_version}/trunk-${dl_version}-${PLATFORM}.tar.gz"
  else
    if [[ "$(printf "%s\n%s\n" "${TRUNK_NEW_URL_VERSION}" "${dl_version}" |
      sort --version-sort |
      head -n 1 || true)" == "${TRUNK_NEW_URL_VERSION}"* ]]; then
      readonly URL="https://trunk.io/releases/${dl_version}/trunk-${dl_version}-${PLATFORM}.tar.gz"
    else
      readonly URL="https://trunk.io/releases/trunk-${dl_version}.${KERNEL}.tar.gz"
    fi
  fi
✘ Trunk is only supported on Linux (x64_64), MacOS (x86_64, arm64), and Windows (x86_64). See https://docs.trunk.io for more info.
supported_envs:
  - darwin
  - amd64

@suzuki-shunsuke
Copy link
Member

This is still work in progress, but I could install trunk 1.12.3 by aqua.

$ trunk --help
INFO[0000] download and unarchive the package            aqua_version= env=darwin/arm64 exe_name=trunk package=trunk-io/cli package_name=trunk-io/cli package_version=1.12.3 program=aqua registry=standard
usage
  trunk [flags] [subcommand]

flags
  -h, --help                  usage information
      --version               the version
      --monitor               enable the trunk daemon to monitor file changes in your repo
      --ci                    run in continuous integration mode
      --no-progress           don't show progress updates
      --ci-progress           rate limit progress updates to every 30s (implied by --ci)
      --action_timeout        timeout for downloads, lint runs, etc
  -v, --verbose               output details about what's happening under the hood

subcommands
  init                        setup trunk in this repo
  check                       universal code checker
  fmt                         universal code formatter
  merge                       submit a pull request to merge (https://app.trunk.io/merge)
  login                       login to trunk.io
  logout                      logout from trunk.io
  upgrade                     upgrade trunk and its linters to the latest releases
  plugins                     manage plugins
  git-hooks                   manage git hooks
  actions                     workflow automation for your repo
  run                         run a specified trunk action
  deinit                      deinit trunk from this repo

extended subcommands
  whoami                      print who you're logged in as
  config                      config management
  cache                       cache management
  daemon                      daemon management
  install                     download & install enabled runtimes/linters
  show-announcements          show /trunk announcements


learn more
  docs                        https://docs.trunk.io
  help/feedback               https://slack.trunk.io

But I'm not sure if aqua really can support trunk yet. I'll take a look further.

@suzuki-shunsuke
Copy link
Member

Hmm. Binary download isn't recommended.

https://docs.trunk.io/docs/install#binary-download-not-recommended

Binary download (not recommended)
You can directly download the trunk binary. **We don't recommend this mode of operation because your ability to version the tool through trunk.yaml will not function when launching trunk directly from a downloaded binary.
Regardless you can bypass the launcher support by downloading the prebuilt binaries here:

@suzuki-shunsuke
Copy link
Member

Oh, I see.
trunk assumes to manage trunk version in trunk.yaml.
trunk /usr/local/bin/trunk gets the version of trunk from trunk.yaml and installs the version and invoke it.
So Binary download isn't recommended.

aqua can support trunk, but you need to manage the version of trunk in aqua.yaml and the version in trunk.yaml is ignored.

@Gowiem
Copy link
Contributor Author

Gowiem commented Jul 24, 2023

@suzuki-shunsuke got it -- thanks for walking through your process.

I feel like I could see two packages here:

  1. Installing the trunk CLI wrapper that versions itself via trunk.yaml and aqua is just the delivery mechanism to get that wrapper installed so a project can stay consistent and everything necessary is installed with a single aqua install. Versioning of this package could be a simple 1.0.0 or something, but it would basically be a no-op.

  2. Install the actual trunk CLI binary as you've setup in feat(trunk-io/cli): add trunk #14003 and manage the version there. I think this could be done for completeness since that is the way aqua is intended to manage packages, but I will say that trunk's auto-upgrade functionality and their ability to be continually be backwards compatible is very nice so far in my own usage and I'm personally more interested in option number 1.

Would you be open to a package that just did the wrapper install? I'd be happy to put that together if so.

Thanks for the help on this!

@suzuki-shunsuke
Copy link
Member

As for the option 1, the package name should be trunk-io/cli-wrapper or something rather than trunk-io/cli
because it's a wrapper script and the versioning is different from trunk itself.

Versioning of this package could be a simple 1.0.0 or something, but it would basically be a no-op.

This is the problem to install the wrapper by aqua.
aqua is a version manager so the package's download URL must be different by version.
The download URL https://get.trunk.io doesn't include the version.

@Gowiem
Copy link
Contributor Author

Gowiem commented Jul 25, 2023

@suzuki-shunsuke how would you like to manage that version problem for the wrapper since it's not versioned? I really think there is value in installing it via aqua so aqua can be an all encompassing package / version manager solution, but I obviously get their is a purity to managing the version that this package would go against. What are you thoughts on that?

@suzuki-shunsuke
Copy link
Member

suzuki-shunsuke commented Jul 25, 2023

aqua can't manage everything for now because aqua has some limitation.
You can use aqua combined with other solution such as Homebrew.
If you want a one command to install all tools you can write a wrapper command by shell script or Make or something.

But I understand demands to manage everything by aqua.
It's definitely ideal.
We are exposing some limitation to aqua, but we can consider releasing some of them gradually according to demands.

But at the same time we should be careful to extend aqua capability. Otherwise, aqua would get complicated and be difficult to maintain. Adding new features has always risks.

As for unversioned tools, we have ever given up them.
But I think we can consider it when we have time.
We have a lot of feature requests so it may be difficult to handle it soon, but we can add this to Back log.

@suzuki-shunsuke
Copy link
Member

I created an issue about this. About aqua's features, it's better to discuss in aqua's Issues or Discussions so that everyone can find the discussion.

@TylerJang27
Copy link

👋 Hi from Trunk! Sorry I didn't see this thread sooner, but wanted to call out a few things that might make integration here easier.

Option 1 as you've described is most in line with Trunk's own execution model, and it sounds like this approach mostly works within aqua.

Installing the trunk CLI wrapper that versions itself via trunk.yaml and aqua is just the delivery mechanism to get that wrapper installed

As you correctly divined, our install URL https://get.trunk.io grabs a version of our launcher/wrapper, which is used to download and invoke our binary directly. Some Trunk functionality, including managing upgrades of linters and the binary itself is dependent on using this launcher to read the cli.version field in .trunk/trunk.yaml.

It sounds like the integration of the trunk-io/cli-wrapper or trunk-io/trunk-launcher is blocked on having a version-specific URL? Fortunately, we do host this in a versioned way, at the URL https://trunk.io/releases/launcher/{version}/trunk, for example. The launcher is kept relatively static and should only occasionally require updates, unlike the CLI binary itself, which is released on about a weekly cadence.

I'm not sure if this URL will be able to integrate well with renovate and your auto-upgrades, but hopefully it should unblock at least some of this.

@suzuki-shunsuke
Copy link
Member

suzuki-shunsuke commented Nov 9, 2023

Hi @TylerJang27 ,
Thank you for your comment.
Oh, https://trunk.io/releases/launcher/{version}/trunk is useful. Thank you!

aqua supports getting the latest version and the list of versions of each package from GitHub Releases and tags.
So if trunk launcher is hosted at GitHub Repository and versioned with GitHub Releases and tags, that's great.

I searched the script in GitHub Organization https:/trunk-io with the phrase TRUNK_LAUNCHER_VERSION then I found the script.

So I thought this is the source of https://trunk.io/releases/launcher/{version}/trunk, but there are two issues.

  1. The latest version of https:/trunk-io/breakpoint is v1.2.8, but the version in the script is 1.2.6
  2. The latest version of https:/trunk-io/breakpoint is v1.2.8, but https://trunk.io/releases/launcher/1.2.8/trunk isn't found

This means the version of https:/trunk-io/breakpoint is different from the version of trunk launcher.

Could you tell us how the source of trunk launcher and it's version is managed?

@TylerJang27
Copy link

The trunk launcher version is managed internally and is not provided through any GitHub Releases at the moment, however we do have this npm package version of it, which may also be useful. The breakpoint version is at 1.2.8 by coincidence. The latest launcher version is 1.2.7 (and is also always the value of TRUNK_LAUNCHER_VERSION in the latest script at https://trunk.io/releases/trunk)

With that being said, renovate is definitely something that's on our radar. We don't have work planned at the moment to add any renovate-specific integrations, but we may revisit this in the future for the sake of upgrading our trunk.yaml linters as well.

@suzuki-shunsuke
Copy link
Member

I see. Thank you.
Renovate supports npm Datasource, so I guess we can update trunk launcher with Renovate Regex Manager.
aqua has the official Renovate Preset, so we would be able to update trunk launcher with Renovate.

Let me confirm just in case. trunk launcher should be installed into $PATH as the command trunk, right?

@suzuki-shunsuke
Copy link
Member

I created a pull request to install trunk launcher with aqua.

@TylerJang27
Copy link

Yep, the npm package will always be updated after the URL exists (so either the download URL or npm install should be sufficient). We also have a powershell launcher (https://trunk.io/releases/launcher/{version}/trunk.ps1) for support on Windows (when bash is not present), although that hasn't made it into the npm package yet.

And yes, the trunk launcher should be installed into $PATH as trunk.

@suzuki-shunsuke
Copy link
Member

Sounds good. Thank you!

I created a pull request to update trunk launcher with Renovate.

It worked well. 👍

BTW, I'm just curious about how you found this issue. Did you guys talk about aqua somewhere?

@suzuki-shunsuke
Copy link
Member

suzuki-shunsuke commented Nov 9, 2023

aqua-registry v4.81.0 and aqua-renovate-config 1.12.0 are out 🎉

You can install trunk launcher with aqua and update it with Renovate!

@TylerJang27
Copy link

Awesome! Thanks for moving on this so quickly! @Gowiem first brought aqua to our attention at Trunk, which I'll now be closing this issue :)

@suzuki-shunsuke
Copy link
Member

Oh, I see. Thank you for your help!
I close this issue now.

scottames referenced this issue in scottames/dots Nov 11, 2023
….0 (#131)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
|
[aquaproj/aqua-renovate-config](https://togithub.com/aquaproj/aqua-renovate-config)
| minor | `1.11.0` -> `1.12.0` |

---

### Release Notes

<details>
<summary>aquaproj/aqua-renovate-config
(aquaproj/aqua-renovate-config)</summary>

###
[`v1.12.0`](https://togithub.com/aquaproj/aqua-renovate-config/releases/tag/1.12.0)

[Compare
Source](https://togithub.com/aquaproj/aqua-renovate-config/compare/1.11.0...1.12.0)

#### Features


[#&#8203;444](https://togithub.com/aquaproj/aqua-renovate-config/issues/444)
Support trunk-io/launcher

-
[https:/aquaproj/aqua-registry/issues/13989#issuecomment-1802998523](https://togithub.com/aquaproj/aqua-registry/issues/13989#issuecomment-1802998523)
-
[https:/aquaproj/aqua-registry/pull/17141](https://togithub.com/aquaproj/aqua-registry/pull/17141)
-   https:/aquaproj/aqua-registry/releases/tag/v4.81.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 4pm on thursday" in timezone
America/Los_Angeles, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/scottames/dots).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants