Skip to content

Commit

Permalink
feat: add install.sh (#94)
Browse files Browse the repository at this point in the history
* feat: update ci action

* feat: add install sh

* feat: update README

* chore: update
  • Loading branch information
luhc228 authored Jun 3, 2024
1 parent a53e50b commit 72910a2
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 61 deletions.
54 changes: 23 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
name: Tests and release
name: Tests and Release

on:
# push:
# branches:
# - main
# tags-ignore:
# - '**'
# pull_request:
# [push]
workflow_dispatch

jobs:
test:
name: ${{ matrix.platform.os_name }} with rust ${{ matrix.toolchain }}
name: "unit tests"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-13, windows-latest]
steps:
- uses: hecrj/setup-rust-action@v2
- uses: Swatinem/rust-cache@v2
- uses: actions/checkout@v4
- name: Run tests
run: cargo test --verbose

build_and_release:
name: ${{ matrix.platform.os_name }} build and release
runs-on: ${{ matrix.platform.os }}
needs: test
if: (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
strategy:
fail-fast: false
matrix:
platform:
- os_name: windows-x86_64
Expand All @@ -33,53 +42,36 @@ jobs:
target: aarch64-apple-darwin
bin: toolkit
name: toolkit-macOS-aarch64.zip
skip_tests: true
toolchain: [stable]
steps:
- uses: actions/checkout@v4
- name: Cache cargo & target directories
uses: Swatinem/rust-cache@v2
with:
key: "v2"
- name: Run tests
uses: houseabsolute/actions-rust-cross@v0
with:
command: "test"
target: ${{ matrix.platform.target }}
toolchain: ${{ matrix.toolchain }}
args: "--locked --release"
if: ${{ !matrix.platform.skip_tests }}
- uses: Swatinem/rust-cache@v2
- name: Build binary
uses: houseabsolute/actions-rust-cross@v0
with:
command: "build"
target: ${{ matrix.platform.target }}
toolchain: ${{ matrix.toolchain }}
args: "--locked --release"
strip: true
if: (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
# Windows
- name: Move binary to bin directory
run: |
cd target/${{ matrix.platform.target }}/release
7z a ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }}
if: matrix.platform.os == 'windows-latest' && (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
if: matrix.platform.os == 'windows-latest'
# Macos & Linux
- name: Move binary to bin directory
run: |
cd target/${{ matrix.platform.target }}/release
zip ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }}
if: matrix.platform.os != 'windows-latest' && (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
if: matrix.platform.os != 'windows-latest'
- name: Publish release binary
uses: actions/upload-artifact@v4
with:
name: toolkit-${{ matrix.platform.os_name }}
path: toolkit-*
if: (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
path: ${{ matrix.platform.name }}
- name: Publish GitHub release
uses: softprops/action-gh-release@v2
with:
draft: true
files: "toolkit-*"
files: ${{ matrix.platform.name }}
body_path: CHANGELOG.md
if: (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
10 changes: 2 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
name: Lint

on:
# push:
# branches:
# - main
# tags-ignore:
# - '**'
# pull_request:
workflow_dispatch
on: [push]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand Down
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ repos:
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict
Expand Down
45 changes: 31 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,42 @@ Toolkit is a CLI that helps you to initialize your development environment faste

## Quick Start

### 1. Download the Toolkit
**Windows Users NOTE: Currently, you may need to follow the installation instructions to install toolkits manually.**
### Using a script (For MacOS and Linux)

You can download the toolkit CLI from the [release page](https:/apptools-lab/AppToolkit/releases).
```shell
curl -fsSL https://raw.githubusercontent.com/apptools-lab/AppToolkit/feat/cli/shell/install.sh | bash -s -- --install
```

### 2. Extract the Zip
#### Parameters

Extract the zip file to your local directory. Then you will get the `toolkit` binary file(macOS) or `toolkit.exe` file(Windows).
`--install`
Install the recommended toolkits (for web development)

### 3. Run the Toolkit
`--manifest`

#### Windows
Install your toolkits by specifying the manifest file path. For example:

```shell
# cd the directory where the `toolkit` file is located
$ cd .\Downloads
curl -fsSL https://raw.githubusercontent.com/apptools-lab/AppToolkit/feat/cli/shell/install.sh | bash -s -- --install --manifest https://the-remote-server/your-toolkits-manifest-path
```

```shell
# install the recommended toolkits(for web development)
$ .\toolkit.exe install
# install your custom toolkits by specifying the manifest file path
$ .\toolkit.exe install --manifest <your-manifest-path>
```

**NOTE: Currently, you may need to follow the installtion instructions to install toolkits manually on Windows system.**
### Using a release binary

#### Macos
1. Download the [latest release](https:/apptools-lab/AppToolkit/releases) binary for your system
2. Unzip the downloaded file
3. Run the following commands in your terminal

```shell
# cd the directory where the `toolkit` file is located.
$ cd ~/Downloads
**Macos and Linux**

```shell
$ chmod +x toolkit

# install the default toolkits (for web development)
Expand All @@ -52,6 +58,15 @@ $ ./toolkit install
$ ./toolkit install --manifest <your-manifest-path>
```

**Windows**

```shell
# install the default toolkits (for web development)
$ .\toolkit.exe install
# install your toolkits by specifying the manifest file path
$ .\toolkit.exe install --manifest <your-manifest-path>
```

## Customization

You can customize your toolkits which to be installed in a json file. Here is a [json schema](./toolkits.schema.json) for you to follow and you can get the hint in the popular IDEs like Visual Studio Code, IntelliJ and so on. For Example:
Expand Down Expand Up @@ -105,4 +120,6 @@ $ .\toolkit.exe install --manifest https://the-remote-server/your-toolkits-manif
$ ./toolkit install --manifest https://the-remote-server/your-toolkits-manifest-path
```

> Toolkit is still in the early stage of development, and we are working hard to improve it. If you have any suggestions or ideas, please feel free to submit an issue or PR.
## Contribution

Toolkit is still in the early stage of development, and we are working hard to improve it. If you have any suggestions or ideas, please feel free to submit an issue or PR.
118 changes: 118 additions & 0 deletions shell/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/bin/bash

# This file is based on: https:/Schniz/fnm/blob/master/.ci/install.sh

set -e

VERSION="cli-v0.0.0"
OS="$(uname -s)"

case "${OS}" in
MINGW* | Win*) OS="Windows" ;;
esac

if [ -d "$HOME/.toolkit" ]; then
INSTALL_DIR="$HOME/.toolkit"
elif [ -n "$XDG_DATA_HOME" ]; then
INSTALL_DIR="$XDG_DATA_HOME/toolkit"
elif [ "$OS" = "Darwin" ]; then
INSTALL_DIR="$HOME/Library/Application Support/toolkit"
else
INSTALL_DIR="$HOME/.local/share/toolkit"
fi

# Parse Flags
parse_args() {
while [[ $# -gt 0 ]]; do
key="$1"

case $key in
--install)
COMMAND="install"
shift # past argument
;;
--list)
COMMAND="list"
shift # past argument
;;
--manifest)
MANIFEST_PATH="$2"
shift # past argument
shift # past value
;;
*)
echo "Unrecognized argument $key"
exit 1
;;
esac
done
}

set_filename() {
if [ "$OS" = "Linux" ]; then
# TODO: Support Linux
# Based on https://stackoverflow.com/a/45125525
case "$(uname -m)" in
arm | armv7*)
FILENAME="toolkit-linux-arm32"
;;
aarch* | armv8*)
FILENAME="toolkit-linux-arm64"
;;
*)
FILENAME="toolkit-linux"
esac
elif [ "$OS" = "Darwin" ]; then
case "$(uname -m)" in
arm64)
FILENAME="toolkit-macOS-aarch64"
;;
*)
FILENAME="toolkit-macOS-x86_64"
esac
elif [ "$OS" = "Windows" ]; then
FILENAME="toolkit-Windows-x86_64"
else
echo "OS $OS is not supported."
echo "If you think that's a bug - please file an issue"
exit 1
fi
}

download_toolkit() {
URL="https:/apptools-lab/AppToolkit/releases/download/$VERSION/$FILENAME.zip"

DOWNLOAD_DIR=$(mktemp -d)

echo "Downloading $URL..."

mkdir -p "$INSTALL_DIR" &>/dev/null

if ! curl --progress-bar --fail -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME.zip"; then
echo "Download failed. Check that the release/filename are correct."
exit 1
fi

unzip -q "$DOWNLOAD_DIR/$FILENAME.zip" -d "$DOWNLOAD_DIR"

if [ -f "$DOWNLOAD_DIR/toolkit" ]; then
mv "$DOWNLOAD_DIR/toolkit" "$INSTALL_DIR/toolkit"
else
mv "$DOWNLOAD_DIR/$FILENAME/toolkit" "$INSTALL_DIR/toolkit"
fi

chmod u+x "$INSTALL_DIR/toolkit"
}

setup_shell() {
if [ -z "$MANIFEST_PATH" ]; then
"$INSTALL_DIR/toolkit" $COMMAND
else
"$INSTALL_DIR/toolkit" $COMMAND --manifest "$MANIFEST_PATH"
fi
}

parse_args "$@"
set_filename
download_toolkit
setup_shell
5 changes: 3 additions & 2 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ pub struct Cli {
pub enum Commands {
#[command(name = "install", about = "Install toolkits.")]
Install(InstallOpts),
#[command(name = "git-ssh", about = "Generate Git SSH secret key")]
GitSSH(GitSSHOpts),
// TODO: Implement the command
// #[command(name = "list", about = "Show the toolkits Details.")]
// List(ListOpts),
}

#[derive(Parser, Debug)]
Expand Down
3 changes: 0 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ async fn main() -> anyhow::Result<()> {
Commands::Install(opts) => {
install(&opts.manifest).await?;
}
Commands::GitSSH(opts) => {
println!("GitSSH: {:?}", opts);
}
},
None => {
eprintln!("No command provided");
Expand Down
3 changes: 2 additions & 1 deletion toolkits.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@
]
}
]
}
}

3 changes: 2 additions & 1 deletion toolkits.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@
}
}
}
}
}

0 comments on commit 72910a2

Please sign in to comment.