From 0c77be9eefec84c9525ef72e96e4a4b91b4aa807 Mon Sep 17 00:00:00 2001 From: Jackhr-arch <63526062+Jackhr-arch@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:01:33 +0000 Subject: [PATCH] try move to cargo-make --- .github/workflows/CI.yml | 155 +----------------- .github/workflows/pr.yml | 82 --------- .gitignore | 3 +- Cargo.toml | 4 +- Doc/clash_test/config.yaml | 8 + Makefile.toml | 65 ++++++++ src/bin/clashtui/tui/frontend/tabs/profile.rs | 14 +- .../clashtui/tui/frontend/tabs/profile/ops.rs | 4 +- src/bin/clashtui/tui/widget/list_popup.rs | 2 +- .../clashtui/utils/backend/impl_service.rs | 2 +- src/profile/map.rs | 4 +- src/webapi/impls.rs | 6 +- 12 files changed, 100 insertions(+), 249 deletions(-) delete mode 100644 .github/workflows/pr.yml create mode 100644 Doc/clash_test/config.yaml create mode 100644 Makefile.toml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e825a46..5f9d9dd 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 @@ -152,32 +33,14 @@ 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 @@ -185,7 +48,7 @@ jobs: if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest - needs: [build-linux, build-linux-arm64, build-windows] + needs: build permissions: contents: write diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index 2af8dd0..0000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: Pull Request - -on: - pull_request: - -env: - CARGO_TERM_COLOR: always - CLASHTUI_VERSION: ${{ github.head_ref }} - -jobs: - build-linux: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - 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 & - - - name: Download Dependencies - run: cargo fetch - - - name: Build - run: cargo build --bin clashtui --verbose - - - name: Run tests - run: cargo test --all --verbose - - - name: Build Version - run: cargo r --bin clashtui -- -V - - - name: Pre Upload - run: | - mkdir artifacts - mv ./target/debug/clashcli ./artifacts/clashcli.debug - - - name: upload artifacts - uses: actions/upload-artifact@v4 - with: - name: Linux_Build - path: artifacts - retention-days: 5 - - build-windows: - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - - - 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: Download Dependencies - run: cargo fetch - - - name: Build - run: | - cargo build --bin clashtui --verbose - - # - name: Run tests - # run: cargo test --all --verbose - - - name: Build Version - run: cargo r --bin clashtui -- -V - - - name: Pre Upload - run: | - mkdir artifacts - mv ./target/debug/clashcli.exe ./artifacts/clashcli.debug.exe - - - name: upload artifacts - uses: actions/upload-artifact@v4 - with: - name: Windows_Build - path: artifacts - retention-days: 5 diff --git a/.gitignore b/.gitignore index c4e99a4..04be088 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ target +artifacts .vscode -.local \ No newline at end of file +.local diff --git a/Cargo.toml b/Cargo.toml index 24dcef9..68b766b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -98,7 +98,7 @@ assets = [ '755', ], [ - '../README.md', + 'README.md', 'usr/share/doc/clashtui/README.md', '644', ], diff --git a/Doc/clash_test/config.yaml b/Doc/clash_test/config.yaml new file mode 100644 index 0000000..4679c63 --- /dev/null +++ b/Doc/clash_test/config.yaml @@ -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 \ No newline at end of file diff --git a/Makefile.toml b/Makefile.toml new file mode 100644 index 0000000..979ebe3 --- /dev/null +++ b/Makefile.toml @@ -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 +''' diff --git a/src/bin/clashtui/tui/frontend/tabs/profile.rs b/src/bin/clashtui/tui/frontend/tabs/profile.rs index 32d50ad..46a3986 100644 --- a/src/bin/clashtui/tui/frontend/tabs/profile.rs +++ b/src/bin/clashtui/tui/frontend/tabs/profile.rs @@ -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; } } diff --git a/src/bin/clashtui/tui/frontend/tabs/profile/ops.rs b/src/bin/clashtui/tui/frontend/tabs/profile/ops.rs index bbe6bbb..b9fb8b0 100644 --- a/src/bin/clashtui/tui/frontend/tabs/profile/ops.rs +++ b/src/bin/clashtui/tui/frontend/tabs/profile/ops.rs @@ -24,11 +24,11 @@ pub enum ProfileOp { /// > but I'll keep it Test(String, bool), /// ask for preview - /// + /// /// though this is asked by tab, but it will be handled at frontend Preview(String), /// ask for edit - /// + /// /// though this is asked by tab, but it will be handled at frontend Edit(String), } diff --git a/src/bin/clashtui/tui/widget/list_popup.rs b/src/bin/clashtui/tui/widget/list_popup.rs index 6f4cd42..7f3b051 100644 --- a/src/bin/clashtui/tui/widget/list_popup.rs +++ b/src/bin/clashtui/tui/widget/list_popup.rs @@ -39,7 +39,7 @@ impl Drawable for ListPopup { i.chars().skip(self.offset).collect::(), )) .style(Ra::Style::default()) - })); + })); f.render_stateful_widget( list.block( Raw::Block::default() diff --git a/src/bin/clashtui/utils/backend/impl_service.rs b/src/bin/clashtui/utils/backend/impl_service.rs index bb4f4c8..80a5dc0 100644 --- a/src/bin/clashtui/utils/backend/impl_service.rs +++ b/src/bin/clashtui/utils/backend/impl_service.rs @@ -39,4 +39,4 @@ impl BackEnd { sysproxy: sysp, }) } -} \ No newline at end of file +} diff --git a/src/profile/map.rs b/src/profile/map.rs index 7f52a8c..4d153bf 100644 --- a/src/profile/map.rs +++ b/src/profile/map.rs @@ -86,9 +86,7 @@ impl ProfileType { crate::backend::util::extract_domain(url).map(|s| s.to_owned()) } #[cfg(feature = "template")] - ProfileType::Generated(name) => { - Some(format!("From template {name}")) - } + ProfileType::Generated(name) => Some(format!("From template {name}")), } } pub fn into_inner(self) -> Option { diff --git a/src/webapi/impls.rs b/src/webapi/impls.rs index 3256354..5bae88b 100644 --- a/src/webapi/impls.rs +++ b/src/webapi/impls.rs @@ -85,7 +85,7 @@ mod tests { fn sym() -> ClashUtil { ClashUtil::new( "http://127.0.0.1:9090".to_string(), - None, + Some("test".to_owned()), "http://127.0.0.1:7890".to_string(), None, None, @@ -127,10 +127,10 @@ mod tests { let mut tf = std::fs::OpenOptions::new() .write(true) .create(true) - .open("test") + .open("/tmp/test") .unwrap(); std::io::copy(&mut r, &mut tf).unwrap(); drop(tf); - std::fs::remove_file("test").unwrap(); + std::fs::remove_file("/tmp/test").unwrap(); } }