Skip to content

refactor: 适配新版PI #328

refactor: 适配新版PI

refactor: 适配新版PI #328

Workflow file for this run

name: install
on:
push:
tags:
- "v*"
branches:
- "**"
paths:
- ".github/workflows/install.yml"
- "assets/**"
- "**.py"
pull_request:
branches:
- "**"
paths:
- ".github/workflows/install.yml"
- "assets/**"
- "**.py"
workflow_dispatch:
permissions:
contents: write
actions: write
packages: write
jobs:
meta:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: set_tag
run: |
# 检查标签格式
is_release=${{ startsWith(github.ref, 'refs/tags/v') }}
tag=$(git describe --tags --match "v*" ${{ github.ref }} || true)
if [[ $tag != v* ]]; then
tag=$(curl -sX GET "https://api.github.com/repos/${{ github.repository }}/releases/latest" --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | awk '/tag_name/{print $4}' FS='["]')
if [[ $tag != v* ]]; then
tag="v0.0.0"
fi
tag=$(date "+$tag-%y%m%d-$(git rev-parse --short HEAD)")
fi
if ! $($is_release) ; then
prefix=${tag%-*-*}
suffix=${tag#$prefix-}
tag="$prefix-ci.$suffix"
fi
# 检查是否为预发布版本
is_prerelease=false
if [[ $tag =~ .*alpha.* || $tag =~ .*beta.* || $tag =~ .*rc.* || $tag =~ .*dev.* || $tag =~ .*-ci.* ]]; then
is_prerelease=true
echo "This is a pre-release version"
fi
echo tag=$tag | tee -a $GITHUB_OUTPUT
echo is_release=$is_release | tee -a $GITHUB_OUTPUT
echo is_prerelease=$is_prerelease | tee -a $GITHUB_OUTPUT
outputs:
tag: ${{ steps.set_tag.outputs.tag }}
is_release: ${{ steps.set_tag.outputs.is_release }}
is_prerelease: ${{ steps.set_tag.outputs.is_prerelease }}
install:
needs: meta
runs-on: ubuntu-latest
strategy:
matrix:
os: [win, macos, linux, android]
arch: [aarch64, x86_64]
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
submodules: true
# 下载 MaaFramework(所有变体都需要)
- name: Download MaaFramework
uses: robinraju/release-downloader@v1.10 # 更新到最新版本
with:
repository: MaaXYZ/MaaFramework
fileName: "MAA-${{ matrix.os }}-${{ matrix.arch }}*"
latest: true
out-file-path: "deps"
extract: true
token: ${{ secrets.GITHUB_TOKEN }}
# 下载 MFAAvalonia(GUI 版本,Android 不支持)
- name: Download MFAAvalonia
if: matrix.os != 'android'
id: download_mfa
uses: robinraju/release-downloader@v1.10
with:
repository: MaaXYZ/MFAAvalonia
fileName: "MFAAvalonia-*-${{ (matrix.os == 'win' && 'win') || (matrix.os == 'macos' && 'osx') || (matrix.os == 'linux' && 'linux') }}-${{ (matrix.arch == 'x86_64' && 'x64') || (matrix.arch == 'aarch64' && 'arm64') }}*"
latest: true
out-file-path: "MFA"
extract: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Clean up MFAAvalonia archive
if: matrix.os != 'android'
shell: bash
run: |
ARCHIVE_FILE_PATH="${{ fromJson(steps.download_mfa.outputs.downloaded_files)[0] }}"
rm -f "${ARCHIVE_FILE_PATH}"
echo "Archive cleanup command executed for MFAAvalonia."
- name: Remove built-in runtime in MFA
if: matrix.os != 'android'
shell: bash
run: |
rm -rf MFA/runtimes
# 下载 MXU(替代 UI,Android 不支持,Linux 仅 x86_64)
- name: Download MXU
if: matrix.os != 'android' && (matrix.os != 'linux' || matrix.arch == 'x86_64')
id: download_mxu
uses: robinraju/release-downloader@v1.10
with:
repository: MistEO/MXU
fileName: "MXU-${{ matrix.os }}-${{ matrix.arch }}*"
latest: true
out-file-path: "MXU"
extract: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Clean up MXU archive
if: matrix.os != 'android' && (matrix.os != 'linux' || matrix.arch == 'x86_64')
shell: bash
run: |
ARCHIVE_FILE_PATH="${{ fromJson(steps.download_mxu.outputs.downloaded_files)[0] }}"
rm -f "${ARCHIVE_FILE_PATH}"
echo "Archive cleanup command executed for MXU."
- name: Install jsonc dependency
run: pip install json-with-comments
# 生成主版本(MFAA 版本)到 install 目录
- name: Install main version (MFAA)
if: matrix.os != 'android'
run: |
python ./tools/install.py ${{ needs.meta.outputs.tag }} ${{ matrix.os }} ${{ matrix.arch }}
# 复制 MFA 文件到 install 目录(重命名可执行文件)
if [[ "${{ matrix.os }}" != "android" && -d "MFA" ]]; then
echo "Copying MFA files to install directory..."
mkdir -p install
rsync -av --ignore-existing MFA/ install/
if [[ "${{ matrix.os }}" == "win" ]]; then
if [ -f "install/MFAAvalonia.exe" ]; then
mv install/MFAAvalonia.exe install/MRA.exe
fi
elif [[ "${{ matrix.os }}" == "macos" ]]; then
if [ -f "install/MFAAvalonia" ]; then
mv install/MFAAvalonia install/MRA
elif [ -d "install/MFAAvalonia.app" ]; then
mv install/MFAAvalonia.app install/MRA.app
fi
elif [[ "${{ matrix.os }}" == "linux" ]]; then
if [ -f "install/MFAAvalonia" ]; then
mv install/MFAAvalonia install/MRA
fi
fi
# 复制图标
if [ -f "logo.ico" ]; then
cp logo.ico install/logo.ico
fi
# 复制文档
if [ -d "docs/zh_cn" ]; then
mkdir -p install/docs
cp -r docs/zh_cn/. install/docs/
fi
fi
# 生成 CLI 版本到 install-cli 目录
- name: Install CLI version
run: |
python ./tools/install_cli.py ${{ needs.meta.outputs.tag }} ${{ matrix.os }} ${{ matrix.arch }}
# 可选:复制文档到 CLI 版本(如果需要)
if [ -d "docs/zh_cn" ]; then
mkdir -p install-cli/docs
cp -r docs/zh_cn/. install-cli/docs/
fi
if [ -f "logo.ico" ]; then
cp logo.ico install-cli/logo.ico
fi
# 生成 MXU 版本到 install-mxu 目录
- name: Install MXU version
if: matrix.os != 'android' && (matrix.os != 'linux' || matrix.arch == 'x86_64')
run: |
python ./tools/install_mxu.py ${{ needs.meta.outputs.tag }} ${{ matrix.os }} ${{ matrix.arch }}
# 复制 MXU 可执行文件到 install-mxu 并重命名为 MRA
if [ -d "MXU" ]; then
mkdir -p install-mxu
if [[ "${{ matrix.os }}" == "win" ]]; then
if [ -f "MXU/mxu.exe" ]; then
cp MXU/mxu.exe install-mxu/MRA.exe
fi
else
if [ -f "MXU/mxu" ]; then
cp MXU/mxu install-mxu/MRA
chmod +x install-mxu/MRA
fi
fi
# 复制图标和文档
if [ -f "logo.ico" ]; then
cp logo.ico install-mxu/logo.ico
fi
if [ -d "docs/zh_cn" ]; then
mkdir -p install-mxu/docs
cp -r docs/zh_cn/. install-mxu/docs/
fi
fi
# 上传三个不同的 artifact
- uses: actions/upload-artifact@v4
if: matrix.os != 'android'
with:
name: MRA-${{ matrix.os }}-${{ matrix.arch }}-MFAA
path: "install"
- uses: actions/upload-artifact@v4
with:
name: MRA-${{ matrix.os }}-${{ matrix.arch }}-PiCLI
path: "install-cli"
- uses: actions/upload-artifact@v4
if: matrix.os != 'android' && (matrix.os != 'linux' || matrix.arch == 'x86_64')
with:
name: MRA-${{ matrix.os }}-${{ matrix.arch }}-MXU
path: "install-mxu"
changelog:
name: Generate changelog
needs: meta
runs-on: ubuntu-latest
outputs:
release_body: ${{ steps.git-cliff.outputs.content }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate a changelog
uses: orhun/git-cliff-action@v4
id: git-cliff
with:
config: .github/cliff.toml
args: >-
-vv --latest --strip header
${{ needs.meta.outputs.is_prerelease == 'false' && '--tag-pattern "^v[0-9]+\\.[0-9]+\\.[0-9]+$"' || '' }}
env:
OUTPUT: CHANGES.md
GITHUB_REPO: ${{ github.repository }}
release:
if: ${{ needs.meta.outputs.is_release == 'true' }}
needs: [meta, install, changelog]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: assets
- run: |
cd assets
for f in *; do
(cd $f && zip -r ../$f-${{ needs.meta.outputs.tag }}.zip .)
done
- uses: softprops/action-gh-release@v2.2.2
with:
files: assets/*.zip
tag_name: ${{ needs.meta.outputs.tag }}
body: ${{ needs.changelog.outputs.release_body }}
draft: false
prerelease: ${{ needs.meta.outputs.is_prerelease == 'true' }}
# Mirror酱为第三方分发服务,新项目默认关闭
# 若有需要请联系 Mirror酱 开通,直接自行开启是无法使用的
# https://mirrorchyan.com/
- name: Trigger MirrorChyanUploading
if: ${{ github.repository_owner == 'Saratoga-Official' }}
shell: bash
run: |
gh workflow run --repo $GITHUB_REPOSITORY mirrorchyan_release.yml -f tag=${{ needs.meta.outputs.tag }}
gh workflow run --repo $GITHUB_REPOSITORY mirrorchyan_release_note.yml -f tag=${{ needs.meta.outputs.tag }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}