Skip to content

feat: support Windows #256

feat: support Windows

feat: support Windows #256

Workflow file for this run

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)
if: matrix.arch == 'x86_64'
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