Release MacOS #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release MacOS | |
on: | |
schedule: | |
- cron: '0 0 * * *' # 每天 UTC 时间 00:00 触发 | |
workflow_dispatch: # 允许手动触发 | |
jobs: | |
localization: | |
runs-on: macos-latest # 使用 MacOS 作为运行环境 | |
timeout-minutes: 30 # 设置超时时间为 30 分钟 | |
env: | |
APP_FILE: app-macos.asar # 定义 app.asar 文件名 | |
APP_CRACK_FILE: app-macos-crack.asar # 定义 app-crack.asar 文件名 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.8' | |
- name: Install required Python packages | |
run: | | |
python -m pip install --upgrade pip | |
- name: Download and mount Termius.dmg | |
id: download_termius | |
shell: bash | |
run: | | |
set -e # 启用错误检查 | |
echo "下载 Termius.dmg..." | |
curl -L -o Termius.dmg https://termi.us/mac-download || { echo "::error::下载 Termius.dmg 失败"; exit 1; } | |
# 创建临时挂载点 | |
temp_mount_point=$(mktemp -d) | |
echo "临时挂载点: $temp_mount_point" | |
# 挂载 .dmg 文件 | |
echo "挂载 Termius.dmg..." | |
hdiutil attach Termius.dmg -mountpoint "$temp_mount_point" -quiet -nobrowse || { echo "::error::挂载 Termius.dmg 失败"; exit 1; } | |
# 查找 Termius.app 的路径 | |
termius_app_path="$temp_mount_point/Termius.app" | |
if [ ! -d "$termius_app_path" ]; then | |
echo "::error::未找到 Termius.app" | |
exit 1 | |
fi | |
# 获取 Termius 版本号 | |
info_plist_path="$termius_app_path/Contents/Info.plist" | |
if [ -f "$info_plist_path" ]; then | |
termius_version=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "$info_plist_path") | |
if [ -n "$termius_version" ]; then | |
echo "Termius 版本: $termius_version" | |
echo "TERMIUS_VERSION=$termius_version" >> $GITHUB_ENV | |
else | |
echo "::error::无法从 Info.plist 获取版本号" | |
exit 1 | |
fi | |
else | |
echo "::error::未找到 Info.plist" | |
exit 1 | |
fi | |
# 卸载 .dmg 文件 | |
echo "卸载 Termius.dmg..." | |
hdiutil detach "$temp_mount_point" -quiet || echo "::warning::卸载 Termius.dmg 失败" | |
# 清理临时挂载点 | |
rm -rf "$temp_mount_point" | |
echo "临时挂载点已清理" | |
- name: Get latest Termius version from GitHub Releases | |
id: get_github_version | |
shell: bash | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 使用 GitHub Token | |
run: | | |
set -e # 启用错误检查 | |
echo "获取 GitHub 最新版本..." | |
# 获取最新 Release 信息 | |
response=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${{ github.repository }}/releases/latest") | |
echo "API URL: https://api.github.com/repos/${{ github.repository }}/releases/latest" | |
echo "API 响应: $response" | |
github_version=$(echo "$response" | jq -r '.tag_name // "0.0.0"') | |
github_version=$(echo "$github_version" | sed 's/v//') | |
echo "GitHub 最新版本: $github_version" | |
echo "GITHUB_VERSION=$github_version" >> $GITHUB_ENV | |
- name: Compare versions | |
id: compare_versions | |
shell: bash | |
run: | | |
set -e # 启用错误检查 | |
echo "比较版本号..." | |
if [ "$(printf '%s\n' "$TERMIUS_VERSION" "$GITHUB_VERSION" | sort -V | tail -n1)" == "$TERMIUS_VERSION" ] && [ "$TERMIUS_VERSION" != "$GITHUB_VERSION" ]; then | |
echo "Termius 版本 ($TERMIUS_VERSION) 高于 GitHub Release 版本 ($GITHUB_VERSION)。继续工作流。" | |
echo "CONTINUE_WORKFLOW=true" >> $GITHUB_ENV | |
else | |
echo "Termius 版本 ($TERMIUS_VERSION) 低于或等于 GitHub Release 版本 ($GITHUB_VERSION)。退出工作流。" | |
echo "CONTINUE_WORKFLOW=false" >> $GITHUB_ENV | |
fi | |
- name: Install Termius | |
if: env.CONTINUE_WORKFLOW == 'true' | |
shell: bash | |
run: | | |
set -e # 启用错误检查 | |
echo "安装 Termius..." | |
# 挂载 .dmg 文件 | |
temp_mount_point=$(mktemp -d) | |
hdiutil attach Termius.dmg -mountpoint "$temp_mount_point" -quiet -nobrowse || { echo "::error::挂载 Termius.dmg 失败"; exit 1; } | |
# 安装 Termius.app | |
termius_app_path=$(find "$temp_mount_point" -name "Termius.app" -type d -maxdepth 3) | |
if [ -z "$termius_app_path" ]; then | |
echo "::error::未找到 Termius.app" | |
exit 1 | |
fi | |
cp -R "$termius_app_path" /Applications/ || { echo "::error::安装 Termius.app 失败"; exit 1; } | |
# 卸载 .dmg 文件 | |
hdiutil detach "$temp_mount_point" -quiet || echo "::warning::卸载 Termius.dmg 失败" | |
rm -rf "$temp_mount_point" | |
- name: Install asar | |
if: env.CONTINUE_WORKFLOW == 'true' | |
shell: bash | |
run: | | |
set -e # 启用错误检查 | |
echo "安装 asar..." | |
npm install -g asar || { echo "::error::安装 asar 失败"; exit 1; } | |
echo "asar 安装成功" | |
- name: Generate and prepare assets | |
if: env.CONTINUE_WORKFLOW == 'true' | |
shell: bash | |
run: | | |
set -e # 启用错误检查 | |
echo "生成资源文件..." | |
# 创建临时目录 | |
temp_dir=$(mktemp -d) | |
echo "临时目录: $temp_dir" | |
# 定义源文件路径 | |
source_path="/Applications/Termius.app/Contents/Resources/app.asar" | |
# 定义生成文件的函数 | |
function generate_asset { | |
local script_args=$1 | |
local dest_file_name=$2 | |
# 生成 .asar 文件 | |
sudo python lang.py $script_args || { echo "::error::生成 $dest_file_name 失败"; exit 1; } | |
# 将生成的 .asar 文件复制到临时目录 | |
dest_path="$temp_dir/$dest_file_name" | |
cp "$source_path" "$dest_path" | |
echo "已将 $dest_file_name 复制到临时目录: $dest_path" | |
} | |
# 生成 app.asar 和 app-crack.asar | |
generate_asset "-R" "$APP_FILE" | |
generate_asset "-RK" "$APP_CRACK_FILE" | |
# 保存临时目录路径到环境变量 | |
echo "TEMP_DIR=$temp_dir" >> $GITHUB_ENV | |
- name: Update Release Notes with version | |
if: env.CONTINUE_WORKFLOW == 'true' | |
shell: bash | |
run: | | |
set -e # 启用错误检查 | |
echo "更新 Release Notes..." | |
# 读取 RELEASE_NOTES.md 文件内容 | |
release_notes=$(cat ./RELEASE_NOTES.md) | |
# 定义版本号变量 | |
release_version="v$TERMIUS_VERSION" | |
# 替换版本号占位符 | |
updated_release_notes=$(echo "$release_notes" | sed "s/{{VERSION}}/$release_version/g") | |
# 将更新后的内容保存到环境变量 | |
echo "UPDATED_RELEASE_NOTES<<EOF" >> $GITHUB_ENV | |
echo "$updated_release_notes" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Create Release and Upload Assets | |
if: env.CONTINUE_WORKFLOW == 'true' | |
uses: ncipollo/release-action@v1 | |
with: | |
allowUpdates: true | |
tag: v${{ env.TERMIUS_VERSION }} # 使用 Termius 版本号作为标签 | |
body: ${{ env.UPDATED_RELEASE_NOTES }} # 使用更新后的 Release Notes | |
draft: true # 创建 Draft Release | |
prerelease: false | |
artifacts: ${{ env.TEMP_DIR }}/* # 上传所有临时目录中的文件 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Clean up | |
if: always() | |
shell: bash | |
run: | | |
if [ -d "$TEMP_DIR" ]; then | |
echo "清理临时目录: $TEMP_DIR" | |
rm -rf "$TEMP_DIR" | |
fi |