Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't use current_exe impl from maa_cli mod #78

Merged
merged 20 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: cargo fmt --all --check

build:
name: Build and test
name: Build and Test
needs: lint
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -101,6 +101,10 @@ jobs:
if: matrix.arch == 'x86_64' || matrix.os == 'ubuntu-latest'
run: |
$CARGO_CMD test --package maa-cli --locked
- name: Test (maa-cli, no-default-features)
if: matrix.arch == 'x86_64' || matrix.os == 'ubuntu-latest'
run: |
$CARGO_CMD test --package maa-cli --no-default-features --locked
- name: Install MaaCore
if: matrix.arch == 'x86_64'
env:
Expand All @@ -117,20 +121,44 @@ jobs:
cd "$RESOURCE_DIR" || exit 1
ls -l "$RESOURCE_DIR"
echo "MAA_CORE_DIR=$MAA_CORE_DIR" >> $GITHUB_ENV
- name: Try run with MaaCore
if: matrix.arch == 'x86_64'
env:
MAA_CONFIG_DIR: ${{ github.workspace }}/config_examples
run: |
cargo run -- version
cargo run -- run daily --dry-run --batch
echo "RESOURCE_DIR=$RESOURCE_DIR" >> $GITHUB_ENV
- name: Test (maa-sys, static)
# It seems rust needs a static library to check the linking.
# Without this, we can not build maa-sys on Windows.
# https://stackoverflow.com/questions/63394094/rust-linker-seeks-a-lib-rather-than-a-dll
if: matrix.arch == 'x86_64' && matrix.os != 'windows-latest'
run: |
cargo test --package maa-sys --locked
- name: Run with MaaCore (default path)
if: matrix.arch == 'x86_64'
timeout-minutes: 1
continue-on-error: ${{ matrix.os == 'windows-latest' }}
env:
MAA_CONFIG_DIR: ${{ github.workspace }}/config_examples
run: |
cargo run -- version
cargo run -- run daily --dry-run --batch
- name: Run with MaaCore (relative path)
if: matrix.arch == 'x86_64'
timeout-minutes: 1
continue-on-error: ${{ matrix.os == 'windows-latest' }}
env:
MAA_CONFIG_DIR: ${{ github.workspace }}/config_examples
run: |
target_dir="target/${CARGO_BUILD_TARGET}"
lib_dir="$target_dir/lib"
share_dir="$target_dir/share/maa"
mv "$MAA_CORE_DIR" "$lib_dir"
ls -l "$lib_dir"
mkdir -p "$share_dir"
mv "$RESOURCE_DIR" "$share_dir/resource"
ls -l "$share_dir"
cargo run -- version
cargo run -- run daily --dry-run --batch
- name: Cat MaaCore Log if failed
if: failure()
run: |
cat "$(cargo run -- dir log)/asst.log"

coverage:
name: Coverage
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions maa-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sha2 = "0.10.7"
digest = "0.10.7"
signal-hook = "0.3.17"
clap_complete = { version = "4.4" }
dunce = "1.0.4"

[dependencies.chrono]
version = "0.4.31"
Expand Down
7 changes: 2 additions & 5 deletions maa-cli/src/installer/maa_cli.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use super::{
download::{download, Checker},
extract::Archive,
maa_core::current_exe,
};

use crate::dirs::{Dirs, Ensure};

use std::{
env::{consts::EXE_SUFFIX, var_os},
path::{Path, PathBuf},
path::Path,
};

use anyhow::{bail, Context, Result};
Expand Down Expand Up @@ -57,10 +58,6 @@ pub fn update(dirs: &Dirs) -> Result<()> {
Ok(())
}

pub fn current_exe() -> std::io::Result<PathBuf> {
std::env::current_exe()?.canonicalize()
}

fn get_metadata() -> Result<VersionJSON> {
let metadata_url = if let Some(url) = var_os("MAA_CLI_API") {
url.into_string().unwrap()
Expand Down
8 changes: 7 additions & 1 deletion maa-cli/src/installer/maa_core.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is used to download and extract prebuilt packages of maa-core.

use super::{download::download_mirrors, extract::Archive, maa_cli::current_exe};
use super::{download::download_mirrors, extract::Archive};

use crate::{
dirs::{Dirs, Ensure},
Expand All @@ -18,6 +18,7 @@ use std::{

use anyhow::{anyhow, bail, Context, Result};
use clap::ValueEnum;
use dunce::canonicalize;
use semver::Version;
use serde::Deserialize;
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -337,3 +338,8 @@ pub fn find_resource(dirs: &Dirs) -> Option<PathBuf> {

None
}

pub fn current_exe() -> Result<PathBuf> {
let path = std::env::current_exe()?;
Ok(canonicalize(path)?)
}