feat: support Windows #258
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: [ "main" ] | |
paths: | |
- "maa-cli/**" | |
- "maa-sys/**" | |
- "Cargo.toml" | |
- "Cargo.lock" | |
- ".github/workflows/ci.yml" | |
pull_request: | |
branches: [ "main" ] | |
paths: | |
- "maa-cli/**" | |
- "maa-sys/**" | |
- "Cargo.toml" | |
- "Cargo.lock" | |
- ".github/workflows/ci.yml" | |
env: | |
CARGO_TERM_COLOR: always | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
lint: | |
name: Lint | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Rust | |
run: rustup component add clippy rustfmt | |
- name: Lint (clippy) | |
run: cargo clippy --all-targets --all-features -- -D warnings | |
- name: Lint (rustfmt) | |
run: cargo fmt --all --check | |
build: | |
name: Build and test | |
needs: lint | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: | |
- ubuntu-latest | |
- macos-latest | |
- windows-latest | |
arch: | |
- x86_64 | |
- aarch64 | |
exclude: | |
# Failed to cross compile ring on Windows | |
- os: windows-latest | |
arch: aarch64 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install Cross | |
if: matrix.os == 'ubuntu-latest' && matrix.arch == 'aarch64' | |
uses: taiki-e/install-action@v2 | |
with: | |
tool: cross | |
- name: Setup environment | |
run: | | |
OS=${{ matrix.os }} | |
ARCH=${{ matrix.arch }} | |
if [ "$OS" = "macos-latest" ]; then | |
CARGO_CMD=cargo | |
CARGO_BUILD_TARGET="${ARCH}-apple-darwin" | |
rustup target add $CARGO_BUILD_TARGET | |
elif [ "$OS" = "windows-latest" ]; then | |
CARGO_CMD=cargo | |
CARGO_BUILD_TARGET="${ARCH}-pc-windows-msvc" | |
rustup target add $CARGO_BUILD_TARGET | |
else | |
if [ "$ARCH" = "aarch64" ]; then | |
CARGO_CMD=cross | |
else | |
CARGO_CMD=cargo | |
fi | |
CARGO_BUILD_TARGET="${ARCH}-unknown-linux-gnu" | |
fi | |
echo "CARGO_CMD=$CARGO_CMD" >> $GITHUB_ENV | |
echo "CARGO_BUILD_TARGET=$CARGO_BUILD_TARGET" >> $GITHUB_ENV | |
- name: Build (maa-cli) | |
run: | | |
$CARGO_CMD build --package maa-cli --locked | |
- name: Test (maa-cli) | |
if: matrix.arch == 'x86_64' || matrix.os == 'ubuntu-latest' | |
run: | | |
$CARGO_CMD test --package maa-cli --locked | |
- name: Install MaaCore | |
if: matrix.arch == 'x86_64' | |
env: | |
MAA_API_URL: https://github.com/MaaAssistantArknights/MaaRelease/raw/main/MaaAssistantArknights/api/version | |
run: | | |
cargo run -- install beta -t0 | |
- name: Show installation | |
if: matrix.arch == 'x86_64' | |
run: | | |
MAA_CORE_DIR="$(cargo run -- dir lib)" | |
RESOURCE_DIR="$(cargo run -- dir resource)" | |
cd "$MAA_CORE_DIR" || exit 1 | |
ls -l "$MAA_CORE_DIR" | |
cd "$RESOURCE_DIR" || exit 1 | |
ls -l "$RESOURCE_DIR" | |
echo "MAA_CORE_DIR=$MAA_CORE_DIR" >> $GITHUB_ENV | |
- name: Setup PATH | |
if: matrix.os == 'windows-latest' | |
shell: | |
pwsh | |
run: | | |
"$env:MAA_CORE_DIR" | Out-File -FilePath $env:GITHUB_PATH -Append | |
- 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 | |
- 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 | |
coverage: | |
name: Coverage | |
needs: build | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: | |
- ubuntu-latest | |
- macos-latest | |
- windows-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Cargo tarpaulin | |
uses: taiki-e/install-action@v2 | |
with: | |
tool: cargo-tarpaulin | |
- name: Generate code coverage | |
run: | | |
cargo tarpaulin --all-features --workspace --timeout 120 --out xml | |
- name: Upload to codecov.io | |
uses: codecov/codecov-action@v3 | |
with: | |
fail_ci_if_error: true |