Skip to content

Commit

Permalink
try move to cargo-make
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackhr-arch committed Aug 30, 2024
1 parent 9878187 commit 0c77be9
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 249 deletions.
155 changes: 9 additions & 146 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,137 +8,18 @@ env:
CARGO_TERM_COLOR: always

jobs:
build-linux:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Mihomo
run: |
wget --output-document mihomo.gz https://github.com/MetaCubeX/mihomo/releases/download/v1.18.4/mihomo-linux-amd64-v1.18.4.gz
gunzip mihomo.gz
chmod +x mihomo
nohup ./mihomo -d Example -f Example/basic_clash_config.yaml &
build:
runs-on: ${{ matrix.os }}

- name: Cache Target
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
uses: actions/cache@v4
with:
path: |
./target
~/.cargo
key: ci-${{ runner.os }}-${{ hashFiles('./Cargo.lock') }}
restore-keys: |
ci-${{ runner.os }}-${{ hashFiles('./Cargo.lock') }}
ci-${{ runner.os }}-
- name: Download Dependencies
run: cargo fetch

- name: Run tests
if: false
run: cargo test --all --verbose

- name: Build
run: |
cargo build --bin clashtui --all-features --verbose --locked
cargo build --bin clashtui --all-features --release --locked
- name: Build Version
run: cargo run --bin clashtui --all-features -- -V

- name: Pre Upload
run: |
mkdir artifacts
mv ./target/release/clashtui ./artifacts/clashtui.release
mv ./target/debug/clashtui ./artifacts/clashtui.debug
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: Linux_Build
path: artifacts
retention-days: 5

build-linux-arm64:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Mihomo
if: false
# ignore as it's same as linux
run: |
wget --output-document mihomo.gz https://github.com/MetaCubeX/mihomo/releases/download/v1.18.4/mihomo-linux-amd64-v1.18.4.gz
gunzip mihomo.gz
chmod +x mihomo
nohup ./mihomo -d Example -f Example/basic_clash_config.yaml &
- name: Cache Target
if: false
# ignore as it's only built in a release
uses: actions/cache@v4
with:
path: |
./target
~/.cargo
key: ci-${{ runner.os }}-arm64-${{ hashFiles('./Cargo.lock') }}
restore-keys: |
ci-${{ runner.os }}-arm64-${{ hashFiles('./Cargo.lock') }}
ci-${{ runner.os }}-arm64-
- name: Download Dependencies
run: |
rustup target add aarch64-unknown-linux-gnu
cargo install cross
cargo fetch
- name: Run tests
if: false
# ignore as it's same as linux
run: cargo test --all --verbose

- name: Build
run: |
cross build --bin clashtui --target=aarch64-unknown-linux-gnu --all-features --verbose --locked
cross build --bin clashtui --target=aarch64-unknown-linux-gnu --all-features --release --locked
- name: Build Version
run: echo "Refer to build-linux"

- name: Pre Upload
run: |
mkdir artifacts
mv ./target/aarch64-unknown-linux-gnu/release/clashtui ./artifacts/clashtui.arm64.release
mv ./target/aarch64-unknown-linux-gnu/debug/clashtui ./artifacts/clashtui.arm64.debug
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: Linux_Arm64_Build
path: artifacts
retention-days: 5

build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Mihomo
run: |
curl -L https://github.com/MetaCubeX/mihomo/releases/download/v1.18.4/mihomo-windows-amd64-v1.18.4.zip --output mihomo.zip
7z x mihomo.zip
mihomo-windows-amd64.exe -d Example -f Example/basic_clash_config.yaml &
- name: Cache Target
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
uses: actions/cache@v4
Expand All @@ -152,40 +33,22 @@ jobs:
ci-${{ runner.os }}-
- name: Download Dependencies
run: cargo fetch

- name: Check
run: cargo check --all-features --verbose

# - name: Run tests
# run: cargo test --all --verbose

- name: Build
run: |
cargo build --bin clashtui --all-features --verbose
cargo build --bin clashtui --all-features --release
- name: Build Version
run: cargo run --bin clashtui --all-features -- -V

- name: Pre Upload
run: |
mkdir artifacts
mv ./target/release/clashtui.exe ./artifacts/clashtui.release.exe
mv ./target/debug/clashtui.exe ./artifacts/clashtui.debug.exe
cargo install --debug cargo-make
cargo make ci
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: Windows_Build
name: artifacts
path: artifacts
retention-days: 5

release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest

needs: [build-linux, build-linux-arm64, build-windows]
needs: build

permissions:
contents: write
Expand Down
82 changes: 0 additions & 82 deletions .github/workflows/pr.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
artifacts
.vscode
.local
.local
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ serde = { version = "^1.0.208", features = ["derive"] }
minreq = { version = "^2.12.0", features = ["proxy", "https"] }
serde_json = "^1.0.125"
serde_yaml = "0.9.34"
futures = {version = "0.3.30", default-features = false}
futures = { version = "0.3.30", default-features = false }

[dependencies.tokio]
version = "^1.39.0"
Expand Down Expand Up @@ -98,7 +98,7 @@ assets = [
'755',
],
[
'../README.md',
'README.md',
'usr/share/doc/clashtui/README.md',
'644',
],
Expand Down
8 changes: 8 additions & 0 deletions Doc/clash_test/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mode: rule
mixed-port: 7890
allow-lan: false
log-level: debug
ipv6: true

secret: test
external-controller: 127.0.0.1:9090
65 changes: 65 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

[env]
# use for build arm64 in docker
CROSS_CONTAINER_IN_CONTAINER = true


[tasks.ci]
dependencies = ["setup_mihomo", "ci-flow"]
script = ["rm mihomo", "rm Doc/clash_test/cache.db"]

[tasks.setup_mihomo.windows]
script = '''
curl --output mihomo.zip -L https://github.com/MetaCubeX/mihomo/releases/download/v1.18.4/mihomo-windows-amd64-v1.18.4.zip
7z x mihomo.zip
mihomo-windows-amd64.exe -d Doc/clash_test -f Doc/clash_test/config.yaml &
'''
[tasks.setup_mihomo.linux]
script = '''
curl --output mihomo.gz -L https://github.com/MetaCubeX/mihomo/releases/download/v1.18.4/mihomo-linux-amd64-v1.18.4.gz
gunzip mihomo.gz
chmod +x mihomo
nohup ./mihomo -d Doc/clash_test -f Doc/clash_test/config.yaml > /dev/null &
'''


[tasks.release.windows]
dependencies = ["clear-artifacts", "amd64"]
script_runner = "@shell"
script = [
"mkdir artifacts",
"cp target/release/clashtui.exe artifacts/clashtui.release.exe",
"cp target/debug/clashtui.exe artifacts/clashtui.debug.exe",
]
[tasks.release.linux]
dependencies = ["clear-artifacts", "arm64", "amd64", "build_deb"]
script = '''
mkdir artifacts
cp target/debian/*.deb artifacts/clashtui.deb
cp target/release/clashtui artifacts/clashtui.release
cp target/debug/clashtui artifacts/clashtui.debug
cp target/aarch64-unknown-linux-gnu/release/clashtui artifacts/clashtui.arm64.release
cp target/aarch64-unknown-linux-gnu/debug/clashtui artifacts/clashtui.arm64.debug
'''

[tasks.clear-artifacts]
script_runner = "@shell"
script = ["rm -r artifacts"]

[tasks.build_deb]
install_crate = "cargo-deb"
command = "cargo"
args = ["deb", "--", "--bin", "clashtui", "--all-features"]

[tasks.arm64]
install_crate = "cross"
script = '''
cross build --bin clashtui --all-features --target=aarch64-unknown-linux-gnu
cross build --bin clashtui --all-features --release --target=aarch64-unknown-linux-gnu
'''

[tasks.amd64]
script = '''
cargo build --bin clashtui --all-features
cargo build --bin clashtui --all-features --release
'''
14 changes: 6 additions & 8 deletions src/bin/clashtui/tui/frontend/tabs/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,17 @@ impl TabCont for ProfileTab {
// require a refresh
self.is_profiles_inited = false;
self.popup_content.replace(PopMsg::Prompt(
["Done".to_string()]
.into_iter()
.chain(result)
.collect(),
["Done".to_string()].into_iter().chain(result).collect(),
));
}
CallBack::ProfileInit(content, times) => {
if !self.is_profiles_inited {
self.profiles.set_items(content);
self.profiles.set_extras(times.into_iter().map(|t| {
t.map( display_duration)
.unwrap_or("Never/Err".to_string())
}));
self.profiles.set_extras(
times
.into_iter()
.map(|t| t.map(display_duration).unwrap_or("Never/Err".to_string())),
);
self.is_profiles_inited = true;
}
}
Expand Down
Loading

0 comments on commit 0c77be9

Please sign in to comment.