Skip to content

Commit

Permalink
refactor!: core and cli installer (#118)
Browse files Browse the repository at this point in the history
**Features:**

- Introduce the `core-installer` feature to disable core installation.

**Refactors:**

- Transform `find_lib/resource` into methods of `Dirs`.
- Add a global `DIRS` variable to avoid pass it everywhere.
- Move constants to a separate module.

**BREAKING CHANGES:**

- Replace the `self` feature with `cli_installer`.
- Make `maa update` reject updating `MaaCore` installed at non-standard locations.
- Change Version JSON files to adopt multiple channels, resembling the version JSON of `MaaCore`.
- Remove deprecated field `channel` in `cli.toml`.
- Remove all installer-related environment variables. Users can now specify them either in the configuration file or as command-line arguments.
  • Loading branch information
wangl-cc authored Nov 28, 2023
1 parent c915139 commit cdbd4dc
Show file tree
Hide file tree
Showing 22 changed files with 2,111 additions and 903 deletions.
9 changes: 9 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ inputs:
arch:
description: 'Target architecture'
required: true
coverage:
description: 'Whether to install cargo-tarpaulin'
required: false
default: 'false'

runs:
using: 'composite'
Expand Down Expand Up @@ -48,3 +52,8 @@ runs:
echo "AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar" >> $GITHUB_ENV
echo "CFLAGS_aarch64_unknown_linux_gnu=--sysroot=/usr/aarch64-linux-gnu" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Install Cargo tarpaulin
if: fromJson(inputs.coverage)
uses: taiki-e/install-action@v2
with:
tool: cargo-tarpaulin
56 changes: 56 additions & 0 deletions .github/scripts/parse_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

set -e

CARGO_PKG_VERSION=$(yq -r '.package.version' maa-cli/Cargo.toml)
COMMIT_SHA=$(git rev-parse HEAD)

if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
echo "PR detected, marking version as alpha pre-release and skipping publish"
channel="alpha"
publish="false"
VERSION="$CARGO_PKG_VERSION-alpha.$(date +%s)"
elif [ "$GITHUB_EVENT_NAME" == "schedule" ]; then
echo "Scheduled event detected, marking version as alpha pre-release and publish to alpha channel"
# check if there are some new commits
channel="alpha"
pubulished_commit=$(yq -r ".details.commit" version/$channel.json)
last_commit="$COMMIT_SHA"
if [ "$pubulished_commit" == "$last_commit" ]; then
echo "No new commits, exiting, skipping all steps"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
VERSION="$CARGO_PKG_VERSION-alpha.$(date +%s)"
publish="true"
elif [ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]; then
echo "Workflow dispatch event detected, reading inputs"
beta=$(yq -r '.inputs.beta' "$GITHUB_EVENT_PATH")
if [ "$beta" == "true" ]; then
echo "Beta flag detected, marking version as beta pre-release and publish to beta channel"
beta_number=$(yq -r ".details.beta_number" version/beta.json)
VERSION="$CARGO_PKG_VERSION-beta.$beta_number"
channel="beta"
else
echo "No beta flag detected, marking version as stable release and publish to stable channel"
channel="stable"
fi
publish=$(yq -r '.inputs.publish' "$GITHUB_EVENT_PATH")
else
REF_VERSION=${GITHUB_REF#refs/tags/v}
if [ "$REF_VERSION" == "$GITHUB_REF" ]; then
echo "Version tag not matched, aborting"
exit 1
fi
echo "Tag detected, marking version as stable release and publish to stable channel"
channel="stable"
VERSION="$REF_VERSION"
fi
echo "Release version $VERSION to $channel channel and publish=$publish"
{
echo "channel=$channel"
echo "commit=$COMMIT_SHA"
echo "version=$VERSION"
echo "publish=$publish"
echo "skip=false"
} >> "$GITHUB_OUTPUT"
108 changes: 44 additions & 64 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
# Failed to cross compile ring on Windows
- os: windows-latest
arch: aarch64
env:
MAA_EXTRA_SHARE_NAME: maa-test
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -52,6 +54,7 @@ jobs:
with:
os: ${{ matrix.os }}
arch: ${{ matrix.arch }}
coverage: true
- name: Setup Cache
uses: Swatinem/rust-cache@v2
- name: Build (maa-cli)
Expand All @@ -65,91 +68,68 @@ jobs:
if: matrix.arch == 'x86_64'
run: |
cargo fmt --all -- --check
- name: Test (maa-cli)
if: matrix.arch == 'x86_64'
run: |
cargo test --package maa-cli --locked
- name: Test (maa-cli, no-default-features)
if: matrix.arch == 'x86_64'
run: |
cargo test --package maa-cli --no-default-features --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)"
MAA_RESOURCE_DIR="$(cargo run -- dir resource)"
ls -l "$MAA_CORE_DIR"
ls -l "$MAA_RESOURCE_DIR"
echo "MAA_CORE_DIR=$MAA_CORE_DIR" >> $GITHUB_ENV
echo "MAA_RESOURCE_DIR=$MAA_RESOURCE_DIR" >> $GITHUB_ENV
- 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)
cargo run -- install stable
ls -l "$(cargo run -- dir library)"
ls -l "$(cargo run -- dir resource)"
ls -l "$(cargo run -- dir cache)"
package_name=$(basename "$(ls "$(cargo run -- dir cache)")")
echo "Downloaded MaaCore package: $package_name"
version=${package_name#MAA-v}
version=${version%%-*}
if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Downloaded MaaCore version: $version"
echo "MAA_CORE_VERSION=v$version" >> "$GITHUB_ENV"
fi
echo "MAA_CORE_INSTALLED=true" >> "$GITHUB_ENV"
- name: Test
if: matrix.arch == 'x86_64'
timeout-minutes: 1
continue-on-error: ${{ matrix.os == 'windows-latest' }}
env:
MAA_CONFIG_DIR: ${{ github.workspace }}/config_examples
MAA_EXE: ${{ startsWith(matrix.os, 'windows') && 'maa.exe' || 'maa' }}
run: |
local_dir="local"
bin_dir="$local_dir/bin"
lib_dir="$local_dir/lib"
share_dir="$local_dir/share/maa"
mkdir -p "$local_dir"
mkdir -p "$bin_dir"
mkdir -p "$share_dir"
cp -v "target/$CARGO_BUILD_TARGET/debug/$MAA_EXE" "$bin_dir"
mv -v "$MAA_CORE_DIR" "$lib_dir"
mv -v "$MAA_RESOURCE_DIR" "$share_dir/resource"
ls -l "$local_dir"
ls -l "$local_dir/bin"
ls -l "$local_dir/lib"
ls -l "$share_dir"
$bin_dir/$MAA_EXE version
$bin_dir/$MAA_EXE run daily --dry-run --batch
- name: Cat MaaCore Log
cargo test
- name: Coverage
if: matrix.arch == 'x86_64'
run: |
cat "$(cargo run -- dir log)/asst.log"
cargo tarpaulin --all-features --workspace --timeout 120 --out xml ${{ github.run_attempt == 1 && '--skip-clean' || '' }}
- name: Upload to codecov.io
if: matrix.arch == 'x86_64'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

coverage:
name: Coverage
needs: build
features:
name: Build and Test (no default features)
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
features:
- --features core_installer
- --features cli_installer
- ""
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Cargo tarpaulin
uses: taiki-e/install-action@v2
- name: Setup Rust
uses: ./.github/actions/setup
with:
tool: cargo-tarpaulin
os: ${{ matrix.os }}
arch: x86_64
- name: Setup Cache
uses: Swatinem/rust-cache@v2
- name: Generate code coverage
run: |
cargo tarpaulin --all-features --workspace --timeout 120 --out xml ${{ github.run_attempt == 1 && '--skip-clean' || '' }}
- name: Upload to codecov.io
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
key: feature-${{ matrix.features }}
- name: Build
run: |
cargo build --package maa-cli --no-default-features ${{ matrix.features }} --locked
- name: Test
run: |
cargo test
Loading

0 comments on commit cdbd4dc

Please sign in to comment.