From 9a6663ba500b27441e790515c015f3444d2610fc Mon Sep 17 00:00:00 2001 From: luhc228 Date: Mon, 3 Jun 2024 17:43:04 +0800 Subject: [PATCH 1/4] feat: update ci action --- .github/workflows/ci.yml | 54 ++++++++++++++++---------------------- .github/workflows/lint.yml | 10 ++----- src/cli/mod.rs | 10 ------- src/main.rs | 3 --- 4 files changed, 25 insertions(+), 52 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a405949..c33cf6d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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') diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4cd5cef..1fa8c4f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/src/cli/mod.rs b/src/cli/mod.rs index ae177bc..6abbd64 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -11,8 +11,6 @@ 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), } #[derive(Parser, Debug)] @@ -24,11 +22,3 @@ pub struct InstallOpts { )] pub manifest: String, } - -#[derive(Parser, Debug)] -pub struct GitSSHOpts { - #[arg(long)] - user_name: String, - #[arg(long)] - user_email: String, -} diff --git a/src/main.rs b/src/main.rs index 63c461b..f9b44a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"); From 1743b336ef4027d42c4b104a337fabeffac94115 Mon Sep 17 00:00:00 2001 From: luhc228 Date: Mon, 3 Jun 2024 20:41:12 +0800 Subject: [PATCH 2/4] feat: add install sh --- shell/install.sh | 118 +++++++++++++++++++++++++++++++++++++++++++++++ src/cli/mod.rs | 11 +++++ 2 files changed, 129 insertions(+) create mode 100755 shell/install.sh diff --git a/shell/install.sh b/shell/install.sh new file mode 100755 index 0000000..f3c80d2 --- /dev/null +++ b/shell/install.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +# This file is based on: https://github.com/Schniz/fnm/blob/master/.ci/install.sh + +set -e + +VERSION="cli-v0.0.0-beta.5" +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://github.com/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 \ No newline at end of file diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 6abbd64..79cee4b 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -11,6 +11,9 @@ pub struct Cli { pub enum Commands { #[command(name = "install", about = "Install toolkits.")] Install(InstallOpts), + // TODO: Implement the command + // #[command(name = "list", about = "Show the toolkits Details.")] + // List(ListOpts), } #[derive(Parser, Debug)] @@ -22,3 +25,11 @@ pub struct InstallOpts { )] pub manifest: String, } + +#[derive(Parser, Debug)] +pub struct GitSSHOpts { + #[arg(long)] + user_name: String, + #[arg(long)] + user_email: String, +} From 6bf755001e79c17eef24f0687b3d3a631d6d7888 Mon Sep 17 00:00:00 2001 From: luhc228 Date: Mon, 3 Jun 2024 20:55:18 +0800 Subject: [PATCH 3/4] feat: update README --- README.md | 45 +++++++++++++++++++++++++++++++-------------- shell/install.sh | 2 +- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 101c24f..2fba769 100644 --- a/README.md +++ b/README.md @@ -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://github.com/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 -- --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 ``` -**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://github.com/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) @@ -52,6 +58,15 @@ $ ./toolkit install $ ./toolkit install --manifest ``` +**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 +``` + ## 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: @@ -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. diff --git a/shell/install.sh b/shell/install.sh index f3c80d2..8680bb2 100755 --- a/shell/install.sh +++ b/shell/install.sh @@ -4,7 +4,7 @@ set -e -VERSION="cli-v0.0.0-beta.5" +VERSION="cli-v0.0.0" OS="$(uname -s)" case "${OS}" in From 60761ef1d176b763c88ab2502fb7be71260b416f Mon Sep 17 00:00:00 2001 From: luhc228 Date: Mon, 3 Jun 2024 21:03:42 +0800 Subject: [PATCH 4/4] chore: update --- .pre-commit-config.yaml | 1 - README.md | 4 ++-- toolkits.manifest.json | 3 ++- toolkits.schema.json | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 148d04e..63a6492 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/README.md b/README.md index 2fba769..ddc225f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ curl -fsSL https://raw.githubusercontent.com/apptools-lab/AppToolkit/feat/cli/sh #### Parameters -`--install` +`--install` Install the recommended toolkits (for web development) `--manifest` @@ -31,7 +31,7 @@ Install the recommended toolkits (for web development) Install your toolkits by specifying the manifest file path. For example: ```shell -curl -fsSL https://raw.githubusercontent.com/apptools-lab/AppToolkit/feat/cli/shell/install.sh | bash -s -- --manifest https://the-remote-server/your-toolkits-manifest-path +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 diff --git a/toolkits.manifest.json b/toolkits.manifest.json index 2fbd575..c5b7ba1 100644 --- a/toolkits.manifest.json +++ b/toolkits.manifest.json @@ -103,4 +103,5 @@ ] } ] -} \ No newline at end of file +} + diff --git a/toolkits.schema.json b/toolkits.schema.json index 1bd32c8..815c0d1 100644 --- a/toolkits.schema.json +++ b/toolkits.schema.json @@ -87,4 +87,5 @@ } } } -} \ No newline at end of file +} +