diff --git a/.github/workflows/moon.yml b/.github/workflows/moon.yml index fa1478afc53..d343953f7a4 100644 --- a/.github/workflows/moon.yml +++ b/.github/workflows/moon.yml @@ -8,9 +8,7 @@ on: pull_request: paths: - .github/workflows/moon.yml - - .moon/workspace.yml - - .moon/tasks.yml - - .moon/toolchain.yml + - .moon/*.yml - crates/** - packages/** - website/** diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index b078cd84fa7..e7f17fb8f37 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -37,28 +37,28 @@ jobs: steps: - uses: actions/checkout@v3 # Unix - - run: bash ./website/static/install.sh + - run: bash ./website/static/install/moon.sh if: ${{ runner.os != 'Windows' }} - - run: bash ./website/static/install.sh '0.20.0' + - run: bash ./website/static/install/moon.sh '0.26.0' if: ${{ runner.os != 'Windows' }} - run: bash ./website/static/install/proto.sh if: ${{ runner.os != 'Windows' }} env: SHELL: bash - - run: bash ./website/static/install/proto.sh '0.1.8' + - run: bash ./website/static/install/proto.sh '0.2.1' if: ${{ runner.os != 'Windows' }} env: SHELL: bash # Windows - - run: pwsh.exe ./website/static/install.ps1 + - run: pwsh.exe ./website/static/install/moon.ps1 if: ${{ runner.os == 'Windows' }} - - run: pwsh.exe ./website/static/install.ps1 '0.20.0' + - run: pwsh.exe ./website/static/install/moon.ps1 '0.26.0' if: ${{ runner.os == 'Windows' }} - run: pwsh.exe ./website/static/install/proto.ps1 if: ${{ runner.os == 'Windows' }} env: SHELL: powershell - - run: pwsh.exe ./website/static/install/proto.ps1 '0.1.8' + - run: pwsh.exe ./website/static/install/proto.ps1 '0.2.1' if: ${{ runner.os == 'Windows' }} env: SHELL: powershell diff --git a/crates/cli/src/commands/upgrade.rs b/crates/cli/src/commands/upgrade.rs index ba6719a31ac..597d7f68b59 100644 --- a/crates/cli/src/commands/upgrade.rs +++ b/crates/cli/src/commands/upgrade.rs @@ -1,9 +1,10 @@ +use crate::app::BIN_NAME; use crate::helpers::{create_progress_bar, AnyError}; use bytes::Buf; use itertools::Itertools; use moon_launchpad::check_version; use moon_logger::error; -use moon_utils::{fs, semver::Version}; +use moon_utils::{fs, path::get_home_dir, semver::Version}; use proto::ProtoError; use std::{ env::{self, consts}, @@ -29,7 +30,7 @@ pub async fn upgrade() -> Result<(), AnyError> { return Ok(()); } Err(err) => { - error!("Failed to get current version of the cli from remote: {err}"); + error!("Failed to get current version of moon from remote: {err}"); return Err(err); } }; @@ -56,18 +57,22 @@ pub async fn upgrade() -> Result<(), AnyError> { } }; - let bin_path = env::current_exe()?; + let current_bin_path = env::current_exe()?; + let bin_dir = get_home_dir() + .expect("Invalid home directory.") + .join(".moon") + .join("bin"); // We can only upgrade moon if it's installed under .moon - let upgradeable = bin_path + let upgradeable = current_bin_path .components() .contains(&Component::Normal(".moon".as_ref())); if !upgradeable { return Err(format!( - "moon can only upgrade itself when installed in the ~/.moon directory.\n\ + "moon can only upgrade itself when installed in the ~/.moon directory.\n\ moon is currently installed at: {}", - bin_path.to_string_lossy() + current_bin_path.to_string_lossy() ) .into()); } @@ -75,17 +80,13 @@ pub async fn upgrade() -> Result<(), AnyError> { let done = create_progress_bar(format!("Upgrading moon to version {new_version}...")); // Move the old binary to a versioned path - let ver_path = bin_path - .parent() - .unwrap() - .parent() - .unwrap() - .join(version) - .join(fs::file_name(&bin_path)); + let versioned_bin_path = bin_dir.join(version).join(BIN_NAME); - fs::create_dir_all(ver_path.parent().unwrap())?; - fs::rename(&bin_path, ver_path)?; + fs::create_dir_all(versioned_bin_path.parent().unwrap())?; + fs::rename(¤t_bin_path, versioned_bin_path)?; + // Download the new binary + let bin_path = bin_dir.join(BIN_NAME); let mut file = File::create(bin_path)?; #[cfg(target_family = "unix")] diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index ddaefc7cc02..a26a332bfca 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -17,6 +17,7 @@ fn get_global_lookups(home_dir: &Path) -> Vec { "/usr/local/bin".into(), home_dir.join(".moon"), // Node + home_dir.join(".proto/tools"), home_dir.join(".nvm/versions/node"), home_dir.join(".nodenv/versions"), home_dir.join(".fnm/node-versions"), @@ -31,6 +32,7 @@ fn get_global_lookups(home_dir: &Path) -> Vec { vec![ home_dir.join(".moon"), // Node + home_dir.join(".proto\\tools"), home_dir.join(".nvm\\versions\\node"), home_dir.join(".nodenv\\versions"), home_dir.join(".fnm\\node-versions"), diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 956271d7f17..27fe4dbea07 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Unreleased + +#### 💥 Breaking + +- Updated the installer scripts and the `moon upgrade` command to install the `moon` binary to + `~/.moon/bin`. + ## 0.26.6 #### 🐞 Fixes diff --git a/packages/cli/README.md b/packages/cli/README.md index a5b13951741..3166c57f8a1 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -1,7 +1,7 @@ # @moonrepo/cli The official CLI for [moon](https://moonrepo.dev), a task runner and repo management tool for the -web ecosystem, written in Rust! Supports JavaScript, TypeScript, Bash, and Batch. +web ecosystem, written in Rust! Supports JavaScript, TypeScript, Bash, and much more! - [Documentation](https://moonrepo.dev/docs) - [Getting started](https://moonrepo.dev/docs/install) @@ -12,18 +12,20 @@ web ecosystem, written in Rust! Supports JavaScript, TypeScript, Bash, and Batch moon can be installed with bash: -```bash -curl -fsSL https://moonrepo.dev/install.sh | bash +```shell +curl -fsSL https://moonrepo.dev/install/moon.sh | bash ``` Or with npm, pnpm, or yarn. -```bash -# Install the dependency +```shell yarn add --dev @moonrepo/cli +``` + +Once installed, initialize moon in your repository. -# Initialize moon in the repo -npx @moonrepo/cli init +```shell +moon init ``` ## Usage diff --git a/scripts/release/publishBinaryPackages.sh b/scripts/release/publishBinaryPackages.sh index d1f5014fad7..7f93029f49f 100755 --- a/scripts/release/publishBinaryPackages.sh +++ b/scripts/release/publishBinaryPackages.sh @@ -22,9 +22,8 @@ for package in packages/cli packages/core-*; do done # Set the tag to use for GitHub releases -name=$(cat packages/cli/package.json | jq -r '.name') version=$(cat packages/cli/package.json | jq -r '.version') -tag="$name@$version" +tag="v$version" echo "NPM_TAG_NAME=$tag" >> $GITHUB_ENV export NPM_TAG_NAME="$tag" diff --git a/scripts/version/applyAndTagVersions.mjs b/scripts/version/applyAndTagVersions.mjs index 2046c949be1..8e3a31ae600 100644 --- a/scripts/version/applyAndTagVersions.mjs +++ b/scripts/version/applyAndTagVersions.mjs @@ -57,15 +57,21 @@ async function removeLocalBuilds() { try { await Promise.all( - ['linux-x64-gnu', 'linux-x64-musl', 'macos-arm64', 'macos-x64', 'windows-x64-msvc'].map( - async (target) => { - const binPath = `packages/core-${target}/moon${target.includes('windows') ? '.exe' : ''}`; - - if (existsSync(binPath)) { - await fs.unlink(binPath); - } - }, - ), + [ + 'linux-arm64-gnu', + 'linux-arm64-musl', + 'linux-x64-gnu', + 'linux-x64-musl', + 'macos-arm64', + 'macos-x64', + 'windows-x64-msvc', + ].map(async (target) => { + const binPath = `packages/core-${target}/moon${target.includes('windows') ? '.exe' : ''}`; + + if (existsSync(binPath)) { + await fs.unlink(binPath); + } + }), ); if (existsSync('target/release')) { @@ -90,7 +96,7 @@ async function createCommit(versions) { await execa('git', ['commit', '-m', commit], { stdio: 'inherit' }); } -async function createTags(versions) { +async function createTags(versions, cliVersion) { console.log('Creating git tags'); await Promise.all( @@ -98,6 +104,10 @@ async function createTags(versions) { await execa('git', ['tag', version]); }), ); + + if (cliVersion) { + await execa('git', ['tag', `v${cliVersion}`]); + } } async function resetGit() { @@ -149,7 +159,7 @@ async function run() { // Create git commit and tags await createCommit(diff); - await createTags(diff); + await createTags(diff, nextVersions['@moonrepo/cli']); console.log(chalk.green('Created commit and tags!')); } diff --git a/website/docs/commands/bin.mdx b/website/docs/commands/bin.mdx index f8eb0d306a4..d878890de4b 100644 --- a/website/docs/commands/bin.mdx +++ b/website/docs/commands/bin.mdx @@ -8,7 +8,7 @@ respectively. ```shell $ moon bin node -/Users/example/.moon/tools/node/x.x.x/bin/node +/Users/example/.proto/tools/node/x.x.x/bin/node ``` > A tool is considered "not configured" when not in use, for example, querying yarn/pnpm when the @@ -17,4 +17,4 @@ $ moon bin node ### Arguments -- `` - Name of the tool to query. Accepts "node", "npm", "pnpm", or "yarn". +- `` - Name of the tool to query. diff --git a/website/docs/install.mdx b/website/docs/install.mdx index 047126fa9d7..fcd94b3b12d 100644 --- a/website/docs/install.mdx +++ b/website/docs/install.mdx @@ -23,29 +23,33 @@ scripts to download and install moon. In a terminal that supports Bash, run: +```shell +curl -fsSL https://moonrepo.dev/install/moon.sh | bash ``` -curl -fsSL https://moonrepo.dev/install.sh | bash -``` -This will install moon to `~/.moon/tools/moon` and create a symlink in `/usr/local/bin`. On WSL, we -prepand the `PATH` environment variable. +This will install moon to `~/.moon/bin` and create a symlink in `/usr/local/bin`. If the symlink +fails, you'll need to set the `PATH` manually in your shell. + +```shell +export PATH="$HOME/.moon/bin:$PATH" +``` ### Windows In Powershell or Windows Terminal, run: -``` -irm https://moonrepo.dev/install.ps1 | iex +```shell +irm https://moonrepo.dev/install/moon.ps1 | iex ``` -This will install moon to `~\.moon\tools\moon` and prepend to the `PATH` environment variable for -the current session. To persist across sessions, update `PATH` manually. +This will install moon to `~\.moon\bin` and prepend to the `PATH` environment variable for the +current session. To persist across sessions, update `PATH` manually. ### Homebrew Install with Homebrew: -``` +```shell brew tap moonrepo/tap brew install moonrepo/tap/moon ``` diff --git a/website/static/install.ps1 b/website/static/install/moon.ps1 similarity index 89% rename from website/static/install.ps1 rename to website/static/install/moon.ps1 index 96fffd73524..3e66eb6d5ea 100755 --- a/website/static/install.ps1 +++ b/website/static/install/moon.ps1 @@ -15,11 +15,13 @@ if ($Args.Length -eq 1) { $DownloadUrl = if ($Version -eq "latest") { "https://github.com/moonrepo/moon/releases/latest/download/${Target}" +} elseif ($Version -like "0*") { + "https://github.com/moonrepo/moon/releases/download/%40moonrepo%2Fcli%40${Version}/${Target}" } else { - "https://github.com/moonrepo/moon/releases/download/%40moonrepo%2Fcli%40/${Version}/${Target}" + "https://github.com/moonrepo/moon/releases/download/v${Version}/${Target}" } -$InstallDir = "${Home}\.moon\tools\moon\${Version}" +$InstallDir = "${Home}\.moon\bin" $BinPath = "${InstallDir}\moon.exe" if (!(Test-Path $InstallDir)) { diff --git a/website/static/install.sh b/website/static/install/moon.sh similarity index 87% rename from website/static/install.sh rename to website/static/install/moon.sh index 8a023005ba7..2ccf2755585 100755 --- a/website/static/install.sh +++ b/website/static/install/moon.sh @@ -45,11 +45,13 @@ fi if [ $# -eq 0 ]; then download_url="https://github.com/moonrepo/moon/releases/latest/download/${target}" -else +elif [[ $version == 0* ]]; then download_url="https://github.com/moonrepo/moon/releases/download/%40moonrepo%2Fcli%40${1}/${target}" +else + download_url="https://github.com/moonrepo/moon/releases/download/v${1}/${target}" fi -install_dir="$HOME/.moon/tools/moon/$version" +install_dir="$HOME/.moon/bin" bin_path="$install_dir/$bin" if [ ! -d "$install_dir" ]; then @@ -64,9 +66,9 @@ echo "Successfully installed moon to $bin_path" if ln -sf "$bin_path" "/usr/local/bin/$bin" &> /dev/null; then echo "Run 'moon --help' to get started!" else - echo "Manually update PATH in your shell to get started!" + echo "Manually update PATH in your shell to get started!" echo - echo " export PATH=\"$install_dir:\$PATH\"" + echo " export PATH=\"\$HOME/.moon/bin:\$PATH\"" fi echo diff --git a/website/static/install/proto.sh b/website/static/install/proto.sh index 5ef72aa9da7..6dae0e4a5d8 100755 --- a/website/static/install/proto.sh +++ b/website/static/install/proto.sh @@ -83,7 +83,7 @@ rm -rf "$download_file" "$temp_dir" # Run setup script to update shells -PROTO_LOG=error +export PROTO_LOG=error $bin_path setup echo "Successfully installed proto to $bin_path"