Skip to content

Commit 72910a2

Browse files
authored
feat: add install.sh (#94)
* feat: update ci action * feat: add install sh * feat: update README * chore: update
1 parent a53e50b commit 72910a2

File tree

9 files changed

+181
-61
lines changed

9 files changed

+181
-61
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
name: Tests and release
1+
name: Tests and Release
22

33
on:
4-
# push:
5-
# branches:
6-
# - main
7-
# tags-ignore:
8-
# - '**'
9-
# pull_request:
4+
# [push]
105
workflow_dispatch
116

127
jobs:
138
test:
14-
name: ${{ matrix.platform.os_name }} with rust ${{ matrix.toolchain }}
9+
name: "unit tests"
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, macos-13, windows-latest]
14+
steps:
15+
- uses: hecrj/setup-rust-action@v2
16+
- uses: Swatinem/rust-cache@v2
17+
- uses: actions/checkout@v4
18+
- name: Run tests
19+
run: cargo test --verbose
20+
21+
build_and_release:
22+
name: ${{ matrix.platform.os_name }} build and release
1523
runs-on: ${{ matrix.platform.os }}
24+
needs: test
25+
if: (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
1626
strategy:
17-
fail-fast: false
1827
matrix:
1928
platform:
2029
- os_name: windows-x86_64
@@ -33,53 +42,36 @@ jobs:
3342
target: aarch64-apple-darwin
3443
bin: toolkit
3544
name: toolkit-macOS-aarch64.zip
36-
skip_tests: true
37-
toolchain: [stable]
3845
steps:
3946
- uses: actions/checkout@v4
40-
- name: Cache cargo & target directories
41-
uses: Swatinem/rust-cache@v2
42-
with:
43-
key: "v2"
44-
- name: Run tests
45-
uses: houseabsolute/actions-rust-cross@v0
46-
with:
47-
command: "test"
48-
target: ${{ matrix.platform.target }}
49-
toolchain: ${{ matrix.toolchain }}
50-
args: "--locked --release"
51-
if: ${{ !matrix.platform.skip_tests }}
47+
- uses: Swatinem/rust-cache@v2
5248
- name: Build binary
5349
uses: houseabsolute/actions-rust-cross@v0
5450
with:
5551
command: "build"
5652
target: ${{ matrix.platform.target }}
57-
toolchain: ${{ matrix.toolchain }}
5853
args: "--locked --release"
5954
strip: true
60-
if: (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
6155
# Windows
6256
- name: Move binary to bin directory
6357
run: |
6458
cd target/${{ matrix.platform.target }}/release
6559
7z a ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }}
66-
if: matrix.platform.os == 'windows-latest' && (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
60+
if: matrix.platform.os == 'windows-latest'
6761
# Macos & Linux
6862
- name: Move binary to bin directory
6963
run: |
7064
cd target/${{ matrix.platform.target }}/release
7165
zip ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }}
72-
if: matrix.platform.os != 'windows-latest' && (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
66+
if: matrix.platform.os != 'windows-latest'
7367
- name: Publish release binary
7468
uses: actions/upload-artifact@v4
7569
with:
7670
name: toolkit-${{ matrix.platform.os_name }}
77-
path: toolkit-*
78-
if: (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
71+
path: ${{ matrix.platform.name }}
7972
- name: Publish GitHub release
8073
uses: softprops/action-gh-release@v2
8174
with:
8275
draft: true
83-
files: "toolkit-*"
76+
files: ${{ matrix.platform.name }}
8477
body_path: CHANGELOG.md
85-
if: (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')

.github/workflows/lint.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
name: Lint
22

3-
on:
4-
# push:
5-
# branches:
6-
# - main
7-
# tags-ignore:
8-
# - '**'
9-
# pull_request:
10-
workflow_dispatch
3+
on: [push]
4+
115
concurrency:
126
group: ${{ github.workflow }}-${{ github.ref }}
137
cancel-in-progress: true

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ repos:
55
rev: v3.2.0
66
hooks:
77
- id: trailing-whitespace
8-
- id: end-of-file-fixer
98
- id: check-yaml
109
- id: check-added-large-files
1110
- id: check-merge-conflict

README.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,42 @@ Toolkit is a CLI that helps you to initialize your development environment faste
1414

1515
## Quick Start
1616

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

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

21-
### 2. Extract the Zip
24+
#### Parameters
2225

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

25-
### 3. Run the Toolkit
29+
`--manifest`
2630

27-
#### Windows
31+
Install your toolkits by specifying the manifest file path. For example:
2832

2933
```shell
30-
# cd the directory where the `toolkit` file is located
31-
$ cd .\Downloads
34+
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
35+
```
3236

37+
```shell
3338
# install the recommended toolkits(for web development)
3439
$ .\toolkit.exe install
3540
# install your custom toolkits by specifying the manifest file path
3641
$ .\toolkit.exe install --manifest <your-manifest-path>
3742
```
3843

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

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

43-
```shell
44-
# cd the directory where the `toolkit` file is located.
45-
$ cd ~/Downloads
50+
**Macos and Linux**
4651

52+
```shell
4753
$ chmod +x toolkit
4854

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

61+
**Windows**
62+
63+
```shell
64+
# install the default toolkits (for web development)
65+
$ .\toolkit.exe install
66+
# install your toolkits by specifying the manifest file path
67+
$ .\toolkit.exe install --manifest <your-manifest-path>
68+
```
69+
5570
## Customization
5671

5772
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
105120
$ ./toolkit install --manifest https://the-remote-server/your-toolkits-manifest-path
106121
```
107122

108-
> 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.
123+
## Contribution
124+
125+
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.

shell/install.sh

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/bash
2+
3+
# This file is based on: https://github.com/Schniz/fnm/blob/master/.ci/install.sh
4+
5+
set -e
6+
7+
VERSION="cli-v0.0.0"
8+
OS="$(uname -s)"
9+
10+
case "${OS}" in
11+
MINGW* | Win*) OS="Windows" ;;
12+
esac
13+
14+
if [ -d "$HOME/.toolkit" ]; then
15+
INSTALL_DIR="$HOME/.toolkit"
16+
elif [ -n "$XDG_DATA_HOME" ]; then
17+
INSTALL_DIR="$XDG_DATA_HOME/toolkit"
18+
elif [ "$OS" = "Darwin" ]; then
19+
INSTALL_DIR="$HOME/Library/Application Support/toolkit"
20+
else
21+
INSTALL_DIR="$HOME/.local/share/toolkit"
22+
fi
23+
24+
# Parse Flags
25+
parse_args() {
26+
while [[ $# -gt 0 ]]; do
27+
key="$1"
28+
29+
case $key in
30+
--install)
31+
COMMAND="install"
32+
shift # past argument
33+
;;
34+
--list)
35+
COMMAND="list"
36+
shift # past argument
37+
;;
38+
--manifest)
39+
MANIFEST_PATH="$2"
40+
shift # past argument
41+
shift # past value
42+
;;
43+
*)
44+
echo "Unrecognized argument $key"
45+
exit 1
46+
;;
47+
esac
48+
done
49+
}
50+
51+
set_filename() {
52+
if [ "$OS" = "Linux" ]; then
53+
# TODO: Support Linux
54+
# Based on https://stackoverflow.com/a/45125525
55+
case "$(uname -m)" in
56+
arm | armv7*)
57+
FILENAME="toolkit-linux-arm32"
58+
;;
59+
aarch* | armv8*)
60+
FILENAME="toolkit-linux-arm64"
61+
;;
62+
*)
63+
FILENAME="toolkit-linux"
64+
esac
65+
elif [ "$OS" = "Darwin" ]; then
66+
case "$(uname -m)" in
67+
arm64)
68+
FILENAME="toolkit-macOS-aarch64"
69+
;;
70+
*)
71+
FILENAME="toolkit-macOS-x86_64"
72+
esac
73+
elif [ "$OS" = "Windows" ]; then
74+
FILENAME="toolkit-Windows-x86_64"
75+
else
76+
echo "OS $OS is not supported."
77+
echo "If you think that's a bug - please file an issue"
78+
exit 1
79+
fi
80+
}
81+
82+
download_toolkit() {
83+
URL="https://github.com/apptools-lab/AppToolkit/releases/download/$VERSION/$FILENAME.zip"
84+
85+
DOWNLOAD_DIR=$(mktemp -d)
86+
87+
echo "Downloading $URL..."
88+
89+
mkdir -p "$INSTALL_DIR" &>/dev/null
90+
91+
if ! curl --progress-bar --fail -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME.zip"; then
92+
echo "Download failed. Check that the release/filename are correct."
93+
exit 1
94+
fi
95+
96+
unzip -q "$DOWNLOAD_DIR/$FILENAME.zip" -d "$DOWNLOAD_DIR"
97+
98+
if [ -f "$DOWNLOAD_DIR/toolkit" ]; then
99+
mv "$DOWNLOAD_DIR/toolkit" "$INSTALL_DIR/toolkit"
100+
else
101+
mv "$DOWNLOAD_DIR/$FILENAME/toolkit" "$INSTALL_DIR/toolkit"
102+
fi
103+
104+
chmod u+x "$INSTALL_DIR/toolkit"
105+
}
106+
107+
setup_shell() {
108+
if [ -z "$MANIFEST_PATH" ]; then
109+
"$INSTALL_DIR/toolkit" $COMMAND
110+
else
111+
"$INSTALL_DIR/toolkit" $COMMAND --manifest "$MANIFEST_PATH"
112+
fi
113+
}
114+
115+
parse_args "$@"
116+
set_filename
117+
download_toolkit
118+
setup_shell

src/cli/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ pub struct Cli {
1111
pub enum Commands {
1212
#[command(name = "install", about = "Install toolkits.")]
1313
Install(InstallOpts),
14-
#[command(name = "git-ssh", about = "Generate Git SSH secret key")]
15-
GitSSH(GitSSHOpts),
14+
// TODO: Implement the command
15+
// #[command(name = "list", about = "Show the toolkits Details.")]
16+
// List(ListOpts),
1617
}
1718

1819
#[derive(Parser, Debug)]

src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ async fn main() -> anyhow::Result<()> {
1010
Commands::Install(opts) => {
1111
install(&opts.manifest).await?;
1212
}
13-
Commands::GitSSH(opts) => {
14-
println!("GitSSH: {:?}", opts);
15-
}
1613
},
1714
None => {
1815
eprintln!("No command provided");

toolkits.manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,5 @@
103103
]
104104
}
105105
]
106-
}
106+
}
107+

toolkits.schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,5 @@
8787
}
8888
}
8989
}
90-
}
90+
}
91+

0 commit comments

Comments
 (0)