Skip to content

Commit

Permalink
build: Update installer and upgrade scripts. (#707)
Browse files Browse the repository at this point in the history
* deps: Update to proto v0.3. (#706)

* Add tools page.

* Add hooks.

* Add blog post.

* Update proto.

* Bump version.

* docs: Fix missing truncate.

* build: Prepare v1 release.

* Add tag.

* Update installers.

* Update install scripts.

* Update upgrade command.

* Polish.

* More debugs.

* Fix ps1.
  • Loading branch information
milesj committed Mar 27, 2023
1 parent 8ca4238 commit cff4176
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 62 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 16 additions & 15 deletions crates/cli/src/commands/upgrade.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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);
}
};
Expand All @@ -56,36 +57,36 @@ 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());
}

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(&current_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")]
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn get_global_lookups(home_dir: &Path) -> Vec<PathBuf> {
"/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"),
Expand All @@ -31,6 +32,7 @@ fn get_global_lookups(home_dir: &Path) -> Vec<PathBuf> {
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"),
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 9 additions & 7 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions scripts/release/publishBinaryPackages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
32 changes: 21 additions & 11 deletions scripts/version/applyAndTagVersions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -90,14 +96,18 @@ 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(
versions.map(async (version) => {
await execa('git', ['tag', version]);
}),
);

if (cliVersion) {
await execa('git', ['tag', `v${cliVersion}`]);
}
}

async function resetGit() {
Expand Down Expand Up @@ -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!'));
}
Expand Down
4 changes: 2 additions & 2 deletions website/docs/commands/bin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,4 +17,4 @@ $ moon bin node
### Arguments

- `<tool>` - Name of the tool to query. Accepts "node", "npm", "pnpm", or "yarn".
- `<tool>` - Name of the tool to query.
22 changes: 13 additions & 9 deletions website/docs/install.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
10 changes: 6 additions & 4 deletions website/static/install.sh → website/static/install/moon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion website/static/install/proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit cff4176

Please sign in to comment.