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

refactor!: core and cli installer #118

Merged
merged 39 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b054974
refactor: core and cli installer
wangl-cc Nov 19, 2023
628f5c0
refactor: add a global DIRS variable
wangl-cc Nov 25, 2023
757db5a
fix
wangl-cc Nov 25, 2023
4b53bd7
test: remove separate default tests
wangl-cc Nov 25, 2023
8bcfc27
test: cache default config in tests
wangl-cc Nov 25, 2023
e58d357
fix
wangl-cc Nov 25, 2023
3d7aa72
fix
wangl-cc Nov 25, 2023
fd587c9
improve dirs
wangl-cc Nov 25, 2023
a19c862
test: add some test that rely on MaaCore installation
wangl-cc Nov 27, 2023
8cf3730
fix
wangl-cc Nov 27, 2023
3b0f433
fix
wangl-cc Nov 27, 2023
b581a3f
fix
wangl-cc Nov 27, 2023
6c520e8
fix
wangl-cc Nov 27, 2023
a42a3bf
test: move test for env var to serde module to aviod interference
wangl-cc Nov 27, 2023
fa38553
ci: get version from installed package
wangl-cc Nov 27, 2023
0cae390
fix: add missing 'v' prefix to MAA_CORE_VERSION
wangl-cc Nov 27, 2023
dfec0ad
show download cache directory in CI
wangl-cc Nov 27, 2023
7d17ca4
use ls to glob the package name instead
wangl-cc Nov 27, 2023
4904f74
test: add some test for Ensure
wangl-cc Nov 27, 2023
cd7bfe6
fix ci
wangl-cc Nov 27, 2023
542113c
fix and remove all isntaller related env vars
wangl-cc Nov 27, 2023
3f59b38
tests: remove dry_run test
wangl-cc Nov 27, 2023
88fab03
ci: upload coverage to codecov.io
wangl-cc Nov 27, 2023
95b2428
fix: only upload coverage for x86_64
wangl-cc Nov 27, 2023
75142af
fix: default cli components
wangl-cc Nov 27, 2023
964e032
test: add some missing tests
wangl-cc Nov 27, 2023
ce89aba
test: use `MAA_CORE_INSTALLED` to indicate the MaaCore is installed
wangl-cc Nov 27, 2023
1249cf9
ci: release workflow for new version format
wangl-cc Nov 28, 2023
91b36ec
fix: file path in release workflow
wangl-cc Nov 28, 2023
61aa695
fix: fix parse_version.sh
wangl-cc Nov 28, 2023
78c220c
fix
wangl-cc Nov 28, 2023
8fb3a18
fix
wangl-cc Nov 28, 2023
0da5a03
fix
wangl-cc Nov 28, 2023
445da8a
fix
wangl-cc Nov 28, 2023
18ccb47
move update_version.sh to release.yml
wangl-cc Nov 28, 2023
af7636f
fix
wangl-cc Nov 28, 2023
48903e2
ci: pass commit sha to release job
wangl-cc Nov 28, 2023
b3eab88
fix
wangl-cc Nov 28, 2023
577af96
ci: commit all json files
wangl-cc Nov 28, 2023
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
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