Skip to content
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
23 changes: 19 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ on:
description: Release body markdown. Leave empty to use the fallback body.
required: false
default: ""
maapicli_tag:
description: Exact MaaXYZ/MaaPiCli release tag. Leave empty to use its latest release.
required: false
default: ""

permissions:
contents: write
contents: read

jobs:
meta:
Expand All @@ -55,6 +59,7 @@ jobs:
is_latest_framework: ${{ steps.meta.outputs.is_latest_framework }}
is_prerelease: ${{ steps.meta.outputs.is_prerelease }}
release_body: ${{ steps.meta.outputs.release_body }}
maapicli_tag: ${{ steps.meta.outputs.maapicli_tag }}
steps:
- id: meta
shell: bash
Expand All @@ -65,6 +70,7 @@ jobs:
source_sha="$(jq -r '.client_payload.source_sha // ""' "$GITHUB_EVENT_PATH")"
maa_framework_channel="$(jq -r '.client_payload.maa_framework_channel // .inputs.maa_framework_channel // "stable"' "$GITHUB_EVENT_PATH")"
maa_framework_version="$(jq -r '.client_payload.maa_framework_version // .inputs.maa_framework_version // ""' "$GITHUB_EVENT_PATH")"
maapicli_tag="$(jq -r '.client_payload.maapicli_tag // .inputs.maapicli_tag // ""' "$GITHUB_EVENT_PATH")"
is_latest_framework="false"
if [ "$maa_framework_version" = "latest" ]; then
maa_framework_channel="stable"
Expand Down Expand Up @@ -136,6 +142,7 @@ jobs:
echo "maa_framework_version=$maa_framework_version"
echo "is_latest_framework=$is_latest_framework"
echo "is_prerelease=$is_prerelease"
echo "maapicli_tag=$maapicli_tag"
echo "release_body<<__M9A_RELEASE_BODY__"
printf '%s\n' "$release_body"
echo "__M9A_RELEASE_BODY__"
Expand Down Expand Up @@ -216,8 +223,10 @@ jobs:
shell: bash
env:
PYTHONPATH: M9A/tools/ci
GH_TOKEN: ${{ github.token }}
MAAPICLI_TAG: ${{ needs.meta.outputs.maapicli_tag }}
run: |
./install/python/python.exe tools/ci/install_cli.py --source-dir M9A --deps-dir deps --output-dir install-cli --version "${{ needs.meta.outputs.tag }}" --platform win32
./install/python/python.exe tools/ci/install_cli.py --source-dir M9A --deps-dir deps --output-dir install-cli --version "${{ needs.meta.outputs.tag }}" --platform win32 --arch ${{ matrix.arch }} --maapicli-tag "$MAAPICLI_TAG"
cp -rpvn install/python/. install-cli/python/
rm -rf install-cli/deps 2>/dev/null || true

Expand Down Expand Up @@ -304,8 +313,10 @@ jobs:
shell: bash
env:
PYTHONPATH: M9A/tools/ci
GH_TOKEN: ${{ github.token }}
MAAPICLI_TAG: ${{ needs.meta.outputs.maapicli_tag }}
run: |
python3 tools/ci/install_cli.py --source-dir M9A --deps-dir deps --output-dir install-cli --version "${{ needs.meta.outputs.tag }}" --platform linux
python3 tools/ci/install_cli.py --source-dir M9A --deps-dir deps --output-dir install-cli --version "${{ needs.meta.outputs.tag }}" --platform linux --arch ${{ matrix.arch }} --maapicli-tag "$MAAPICLI_TAG"
cp -rpvn install/python/. install-cli/python/
rm -rf install-cli/deps 2>/dev/null || true
if [ -f "install-cli/M9A" ]; then chmod +x install-cli/M9A; fi
Expand Down Expand Up @@ -392,8 +403,10 @@ jobs:
shell: bash
env:
PYTHONPATH: M9A/tools/ci
GH_TOKEN: ${{ github.token }}
MAAPICLI_TAG: ${{ needs.meta.outputs.maapicli_tag }}
run: |
./install/python/bin/python3 tools/ci/install_cli.py --source-dir M9A --deps-dir deps --output-dir install-cli --version "${{ needs.meta.outputs.tag }}" --platform darwin
./install/python/bin/python3 tools/ci/install_cli.py --source-dir M9A --deps-dir deps --output-dir install-cli --version "${{ needs.meta.outputs.tag }}" --platform darwin --arch ${{ matrix.arch }} --maapicli-tag "$MAAPICLI_TAG"
cp -rpvn install/python/. install-cli/python/
if [ -f "install-cli/M9A" ]; then chmod +x install-cli/M9A; fi
rm -rf install-cli/deps 2>/dev/null || true
Expand All @@ -407,6 +420,8 @@ jobs:
if: ${{ needs.meta.outputs.tag != 'v0.0.0-local' }}
needs: [meta, windows, linux, macos]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v8
with:
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test packaging scripts

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- name: Set up pytest
run: |
python3 -m venv .venv
.venv/bin/pip install --quiet pytest

- name: Run tests
run: .venv/bin/python -m pytest tests -q
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,39 @@ version, and release notes.

1. `MAA1999/M9A` publishes a normal release.
2. The M9A workflow sends a `repository_dispatch` event to `MAA1999/m9a-cli`.
3. This repository clones the matching M9A ref, resolves MaaFramework from an exact version or the stable/beta/alpha channel, and
builds `PiCLI` artifacts.
3. This repository clones the matching M9A ref, resolves MaaFramework from an exact version or the stable/beta/alpha channel, takes the
MaaPiCli entrypoint from the `MAAXYZ/MaaPiCli` release assets, and builds `PiCLI` artifacts.
4. The artifacts are published to the same tag name in this repository, reusing
the release notes passed from `MAA1999/M9A`.

Manual runs are available through `workflow_dispatch`.

The entrypoint is no longer taken from the MaaFramework runtime bundle: that copy
lags the ProjectInterface revisions (MaaFramework v5.15.0-beta.1 still parsed
`welcome` as a single string, so an interface.json using the PI 2.10 array failed
to load), and MaaFramework is dropping MaaPiCli from its `MAA-*` packages anyway.
`--maapicli-tag` pins an exact MaaXYZ/MaaPiCli release; empty resolves the latest.

## Local Smoke Test

From this repository root:

```powershell
python tools/ci/install_cli.py --source-dir D:\02code\M9A --deps-dir D:\02code\M9A\deps --output-dir install-cli-smoke --version v0.0.0-local --platform win32
python tools/ci/install_cli.py --source-dir D:\02code\M9A --deps-dir D:\02code\M9A\deps --output-dir install-cli-smoke --version v0.0.0-local --platform win32 --arch x86_64
```

The command expects a prepared MaaFramework `deps` directory. CI downloads it
from `MaaXYZ/MaaFramework`. `--python-dir` defaults to `install/python`, which
`tools/ci/setup_embed_python.py` prepares.
`tools/ci/setup_embed_python.py` prepares. MaaPiCli is downloaded from
`MaaXYZ/MaaPiCli` into `install/maapicli` (set `GH_TOKEN` to avoid API rate
limits); pass `--maapicli-tag v5.14.3` to pin it.

The build strips the MaaFramework copy bundled in the embedded interpreter's `maa`
wheel -- the Agent reaches the flattened copy at the package root through
`MAAFW_BINARY_PATH` -- and then runs the packaged Agent once. A `--source-dir` that
predates the `agent/maafw_paths.py` helper is rejected before anything is stripped,
so a stale M9A ref cannot produce a package that only breaks on the user machine.

Finally the packaged CLI is started once against the packaged `interface.json` and
must reach the controller prompt, so a CLI build that cannot load the interface
fails before the artifact is uploaded.
118 changes: 118 additions & 0 deletions tests/test_install_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
from __future__ import annotations

import sys
from pathlib import Path

import pytest

sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tools" / "ci"))

import install_cli


def test_normalize_arch_maps_release_asset_names() -> None:
assert install_cli.normalize_arch("AMD64") == "x86_64"
assert install_cli.normalize_arch("x86_64") == "x86_64"
assert install_cli.normalize_arch("arm64") == "aarch64"
assert install_cli.normalize_arch("aarch64") == "aarch64"


def test_normalize_arch_rejects_unknown_machine() -> None:
with pytest.raises(RuntimeError):
install_cli.normalize_arch("mips")


def test_maapicli_asset_name_matches_release_assets() -> None:
assert (
install_cli.maapicli_asset_name("win32", "x86_64", "v5.14.3")
== "MAA-MaaPiCli-windows-x86_64-v5.14.3.zip"
)
assert (
install_cli.maapicli_asset_name("linux", "aarch64", "v5.14.3")
== "MAA-MaaPiCli-linux-aarch64-v5.14.3.zip"
)
assert (
install_cli.maapicli_asset_name("darwin", "arm64", "v5.14.3")
== "MAA-MaaPiCli-macos-aarch64-v5.14.3.zip"
)


def test_maapicli_asset_os_rejects_unknown_platform() -> None:
with pytest.raises(RuntimeError):
install_cli.maapicli_asset_os("freebsd")


def test_cli_binary_names_per_platform() -> None:
assert install_cli.cli_binary_name("win32") == "M9A.exe"
assert install_cli.cli_binary_name("linux") == "M9A"
assert install_cli.maapicli_binary_name("win32") == "MaaPiCli.exe"
assert install_cli.maapicli_binary_name("darwin") == "MaaPiCli"


def test_resolve_maapicli_tag_prefers_explicit_tag(tmp_path: Path) -> None:
# An explicit tag must not reach the releases API.
assert install_cli.resolve_maapicli_tag("v5.14.3") == "v5.14.3"


def test_maapicli_binary_path_finds_bin_layout(tmp_path: Path) -> None:
binary = tmp_path / "bin" / "MaaPiCli.exe"
binary.parent.mkdir()
binary.write_bytes(b"cli")

assert install_cli.maapicli_binary_path(tmp_path, "win32") == binary


def test_maapicli_binary_path_fails_when_missing(tmp_path: Path) -> None:
with pytest.raises(FileNotFoundError):
install_cli.maapicli_binary_path(tmp_path, "linux")


def test_install_maapicli_replaces_bundled_binary(tmp_path: Path) -> None:
maapicli_dir = tmp_path / "maapicli"
extracted = maapicli_dir / "bin" / "MaaPiCli.exe"
extracted.parent.mkdir(parents=True)
extracted.write_bytes(b"fixed cli")

output_dir = tmp_path / "install-cli"
output_dir.mkdir()
(output_dir / "M9A.exe").write_bytes(b"stale m9a")
(output_dir / "MaaPiCli.exe").write_bytes(b"bundled cli")

target = install_cli.install_maapicli(output_dir, maapicli_dir, "win32")

assert target == output_dir / "M9A.exe"
assert target.read_bytes() == b"fixed cli"
# The copy MaaFramework still bundles must not survive next to the entrypoint.
assert not (output_dir / "MaaPiCli.exe").exists()


def test_subprocess_env_drops_release_credentials(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("GH_TOKEN", "secret")
monkeypatch.setenv("GITHUB_TOKEN", "secret")
monkeypatch.setenv("PATH", "/usr/bin")

env = install_cli.subprocess_env_without_credentials()

assert "GH_TOKEN" not in env
assert "GITHUB_TOKEN" not in env
assert env["PATH"] == "/usr/bin"


def test_assert_interface_parse_output_accepts_controller_prompt() -> None:
install_cli.assert_interface_parse_output("### Select controller ###\n\n\t1. Controller.Adb\n")


def test_assert_interface_parse_output_rejects_schema_mismatch() -> None:
with pytest.raises(RuntimeError, match="json is not an InterfaceData"):
install_cli.assert_interface_parse_output(
'json is not an InterfaceData [error_key=welcome] [json={"welcome":["a"]}]'
)
with pytest.raises(RuntimeError):
install_cli.assert_interface_parse_output(
"[ERR] Failed to parse interface.json\n\nPress Enter to continue...\n"
)


def test_assert_interface_parse_output_rejects_missing_prompt() -> None:
with pytest.raises(RuntimeError, match="controller prompt"):
install_cli.assert_interface_parse_output("Loading...\n")
Loading
Loading