name: Build CLI release on: repository_dispatch: types: [m9a-release] workflow_dispatch: inputs: tag: description: Release tag to publish in this repository. required: false default: v0.0.0-local source_repo: description: M9A source repository. required: false default: MAA1999/M9A source_ref: description: M9A ref, tag, branch, or SHA to package. required: false default: main maa_framework_version: description: Exact MaaFramework release tag. Overrides the channel when non-empty. required: false default: "" maa_framework_channel: description: MaaFramework release channel used when no exact version is set. required: false type: choice options: - stable - beta - alpha default: stable is_prerelease: description: Publish as prerelease. required: false default: "true" release_body: 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 jobs: meta: runs-on: ubuntu-latest outputs: tag: ${{ steps.meta.outputs.tag }} source_repo: ${{ steps.meta.outputs.source_repo }} source_ref: ${{ steps.meta.outputs.source_ref }} source_sha: ${{ steps.meta.outputs.source_sha }} maa_framework_version: ${{ steps.meta.outputs.maa_framework_version }} maa_framework_channel: ${{ steps.meta.outputs.maa_framework_channel }} 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 run: | tag="$(jq -r '.client_payload.tag // .inputs.tag // "v0.0.0-local"' "$GITHUB_EVENT_PATH")" source_repo="$(jq -r '.client_payload.source_repo // .inputs.source_repo // "MAA1999/M9A"' "$GITHUB_EVENT_PATH")" source_ref="$(jq -r '.client_payload.source_ref // .client_payload.tag // .inputs.source_ref // "main"' "$GITHUB_EVENT_PATH")" 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" maa_framework_version="" fi if [ -z "$maa_framework_version" ]; then case "$maa_framework_channel" in stable) is_latest_framework="true" ;; beta|alpha) maa_framework_version="$(python3 - "$maa_framework_channel" <<'PY' import json import re import subprocess import sys channel = sys.argv[1] releases = json.loads( subprocess.check_output( ["gh", "api", "repos/MaaXYZ/MaaFramework/releases?per_page=100"], text=True, ) ) def maturity(tag): if re.search(r"(?:^|[.-])alpha(?:[.-]|$)", tag, re.IGNORECASE): return "alpha" if re.search(r"(?:^|[.-])(?:beta|rc)(?:[.-]|$)", tag, re.IGNORECASE): return "beta" return "stable" priority = {"stable": 2, "beta": 1, "alpha": 0} for release in releases: if not release.get("draft") and priority[maturity(release["tag_name"])] >= priority[channel]: print(release["tag_name"]) break else: raise SystemExit(f"No MaaFramework release found for channel {channel}") PY )" ;; *) echo "Unsupported MaaFramework channel: $maa_framework_channel" >&2 exit 1 ;; esac fi is_prerelease="$(jq -r 'if .client_payload.is_prerelease != null then .client_payload.is_prerelease elif .inputs.is_prerelease != null then .inputs.is_prerelease else empty end' "$GITHUB_EVENT_PATH")" if [ -z "$is_prerelease" ]; then if [[ "$tag" == *-* ]]; then is_prerelease="true" else is_prerelease="false" fi fi release_body="$(jq -r '.client_payload.release_body // .inputs.release_body // ""' "$GITHUB_EVENT_PATH")" if [ -z "$release_body" ]; then release_body="$(printf 'M9A CLI package release.\n\nSource: `%s`\nRef: `%s`' "$source_repo" "$source_ref")" fi { echo "tag=$tag" echo "source_repo=$source_repo" echo "source_ref=$source_ref" echo "source_sha=$source_sha" echo "maa_framework_channel=$maa_framework_channel" 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__" } | tee -a "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ github.token }} windows: needs: meta strategy: fail-fast: false matrix: include: - arch: x86_64 runner: windows-latest - arch: aarch64 runner: windows-11-arm runs-on: ${{ matrix.runner }} steps: - uses: actions/checkout@v7 - name: Checkout M9A source shell: bash run: | git init M9A git -C M9A remote add origin "https://github.com/${{ needs.meta.outputs.source_repo }}.git" if ! git -C M9A fetch --depth 1 origin "${{ needs.meta.outputs.source_ref }}"; then if [ -z "${{ needs.meta.outputs.source_sha }}" ]; then echo "Failed to fetch source_ref and source_sha is empty." exit 1 fi git -C M9A fetch --depth 1 origin "${{ needs.meta.outputs.source_sha }}" fi git -C M9A checkout --detach FETCH_HEAD git -C M9A submodule update --init --recursive --depth 1 - name: Download MaaFramework uses: robinraju/release-downloader@v1 with: repository: MaaXYZ/MaaFramework fileName: "MAA-win-${{ matrix.arch }}*" tag: ${{ needs.meta.outputs.maa_framework_version }} out-file-path: deps extract: true latest: ${{ needs.meta.outputs.is_latest_framework }} - name: Setup embedded Python shell: bash run: | python tools/ci/setup_embed_python.py - name: Install Python dependencies shell: bash run: | cd M9A ../install/python/python.exe ../tools/ci/download_deps.py --deps-dir ../install/deps cd .. python -c " import tomllib with open('M9A/pyproject.toml', 'rb') as f: d = tomllib.load(f) with open('requirements.txt', 'w') as out: for dep in d['project']['dependencies']: out.write(dep + '\n') " ./install/python/python.exe -m pip install -U -r requirements.txt --no-warn-script-location --find-links install/deps --no-index rm -f requirements.txt - name: Download drop_core module shell: bash env: PRIVATE_REPO_TOKEN: ${{ secrets.PRIVATE_REPO_TOKEN }} run: | cd M9A ../install/python/python.exe tools/ci/download_drop_core.py --os windows --arch ${{ matrix.arch }} || echo "drop_core download skipped" - name: Build CLI package shell: bash env: PYTHONPATH: M9A/tools/ci GH_TOKEN: ${{ github.token }} 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 --arch ${{ matrix.arch }} --maapicli-tag "${{ needs.meta.outputs.maapicli_tag }}" cp -rpvn install/python/. install-cli/python/ rm -rf install-cli/deps 2>/dev/null || true - uses: actions/upload-artifact@v7 with: name: M9A-win-${{ matrix.arch }}-${{ needs.meta.outputs.tag }}-PiCLI path: install-cli linux: needs: meta strategy: fail-fast: false matrix: include: - arch: x86_64 runner: ubuntu-latest # Native arm64 runner: the aarch64 interpreter, its wheels and the dependency # download all follow the host architecture. - arch: aarch64 runner: ubuntu-24.04-arm runs-on: ${{ matrix.runner }} steps: - uses: actions/checkout@v7 - name: Checkout M9A source shell: bash run: | git init M9A git -C M9A remote add origin "https://github.com/${{ needs.meta.outputs.source_repo }}.git" if ! git -C M9A fetch --depth 1 origin "${{ needs.meta.outputs.source_ref }}"; then if [ -z "${{ needs.meta.outputs.source_sha }}" ]; then echo "Failed to fetch source_ref and source_sha is empty." exit 1 fi git -C M9A fetch --depth 1 origin "${{ needs.meta.outputs.source_sha }}" fi git -C M9A checkout --detach FETCH_HEAD git -C M9A submodule update --init --recursive --depth 1 - name: Download MaaFramework uses: robinraju/release-downloader@v1 with: repository: MaaXYZ/MaaFramework fileName: "MAA-linux-${{ matrix.arch }}*" tag: ${{ needs.meta.outputs.maa_framework_version }} out-file-path: deps extract: true latest: ${{ needs.meta.outputs.is_latest_framework }} - name: Setup embedded Python shell: bash env: # gh / urllib both need a token here: the release lookup hits the GitHub API. GH_TOKEN: ${{ github.token }} run: | python3 tools/ci/setup_embed_python.py if [ -f ./install/python/bin/python3 ]; then chmod +x ./install/python/bin/python3; fi - name: Install Python dependencies shell: bash run: | cd M9A ../install/python/bin/python3 ../tools/ci/download_deps.py --deps-dir ../install/deps cd .. python3 -c " import tomllib with open('M9A/pyproject.toml', 'rb') as f: d = tomllib.load(f) with open('requirements.txt', 'w') as out: for dep in d['project']['dependencies']: out.write(dep + '\n') " ./install/python/bin/python3 -m pip install -U -r requirements.txt --no-warn-script-location --find-links install/deps --no-index rm -f requirements.txt - name: Download drop_core module shell: bash env: PRIVATE_REPO_TOKEN: ${{ secrets.PRIVATE_REPO_TOKEN }} run: | python3 tools/ci/download_drop_core.py --os linux --arch ${{ matrix.arch }} || echo "drop_core download skipped" - name: Build CLI package shell: bash env: PYTHONPATH: M9A/tools/ci GH_TOKEN: ${{ github.token }} run: | 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 "${{ needs.meta.outputs.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 - uses: actions/upload-artifact@v7 with: name: M9A-linux-${{ matrix.arch }}-${{ needs.meta.outputs.tag }}-PiCLI path: install-cli macos: needs: meta strategy: fail-fast: false matrix: include: - arch: x86_64 runner: macos-15-intel - arch: aarch64 runner: macos-latest runs-on: ${{ matrix.runner }} steps: - uses: actions/checkout@v7 - name: Checkout M9A source shell: bash run: | git init M9A git -C M9A remote add origin "https://github.com/${{ needs.meta.outputs.source_repo }}.git" if ! git -C M9A fetch --depth 1 origin "${{ needs.meta.outputs.source_ref }}"; then if [ -z "${{ needs.meta.outputs.source_sha }}" ]; then echo "Failed to fetch source_ref and source_sha is empty." exit 1 fi git -C M9A fetch --depth 1 origin "${{ needs.meta.outputs.source_sha }}" fi git -C M9A checkout --detach FETCH_HEAD git -C M9A submodule update --init --recursive --depth 1 - name: Download MaaFramework uses: robinraju/release-downloader@v1 with: repository: MaaXYZ/MaaFramework fileName: "MAA-macos-${{ matrix.arch }}*" tag: ${{ needs.meta.outputs.maa_framework_version }} out-file-path: deps extract: true latest: ${{ needs.meta.outputs.is_latest_framework }} - name: Setup embedded Python shell: bash env: # gh / urllib both need a token here: the release lookup hits the GitHub API. GH_TOKEN: ${{ github.token }} run: | python3 tools/ci/setup_embed_python.py if [ -f ./install/python/bin/python3 ]; then chmod +x ./install/python/bin/python3; fi - name: Install Python dependencies shell: bash run: | cd M9A ../install/python/bin/python3 ../tools/ci/download_deps.py --deps-dir ../install/deps cd .. python3 -c " import tomllib with open('M9A/pyproject.toml', 'rb') as f: d = tomllib.load(f) with open('requirements.txt', 'w') as out: for dep in d['project']['dependencies']: out.write(dep + '\n') " ./install/python/bin/python3 -m pip install -U -r requirements.txt --no-warn-script-location --find-links install/deps --no-index rm -f requirements.txt - name: Download drop_core module shell: bash env: PRIVATE_REPO_TOKEN: ${{ secrets.PRIVATE_REPO_TOKEN }} run: | cd M9A ../install/python/bin/python3 tools/ci/download_drop_core.py --os darwin --arch ${{ matrix.arch }} || echo "drop_core download skipped" - name: Build CLI package shell: bash env: PYTHONPATH: M9A/tools/ci GH_TOKEN: ${{ github.token }} 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 --arch ${{ matrix.arch }} --maapicli-tag "${{ needs.meta.outputs.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 - uses: actions/upload-artifact@v7 with: name: M9A-macos-${{ matrix.arch }}-${{ needs.meta.outputs.tag }}-PiCLI path: install-cli release: if: ${{ needs.meta.outputs.tag != 'v0.0.0-local' }} needs: [meta, windows, linux, macos] runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v8 with: path: release-assets - name: Process artifacts shell: bash run: | cd release-assets for f in *; do if [[ -d "$f" && "$f" == *"win"* ]]; then (cd "$f" && zip -r "../$f.zip" .) rm -rf "$f" elif [[ -d "$f" ]]; then if [[ -f "$f/M9A" ]]; then chmod +x "$f/M9A"; fi tar -czf "$f.tar.gz" "$f" rm -rf "$f" fi done - name: Publish release uses: softprops/action-gh-release@v3 with: files: release-assets/* tag_name: ${{ needs.meta.outputs.tag }} prerelease: ${{ needs.meta.outputs.is_prerelease == 'true' }} body: ${{ needs.meta.outputs.release_body }}