Skip to content
Open
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
43 changes: 6 additions & 37 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,17 @@ jobs:
- name: Set up Xcode Version
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '26.6' # 与本地开发环境保持一致,避免 CI 随 runner 漂移
xcode-version: '26.6' # 与 PR 构建检查一致,避免 CI 随 runner 漂移

- name: Generate Build Number & Build IPA
id: build_ipa
env:
TAG_NAME: ${{ inputs.tag_name }}
run: |
# 1. 获取 Git 总提交次数作为构建编号 (Build Number)
BUILD_NUMBER=$(git rev-list --count HEAD)
echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV

TAG_NAME="${{ inputs.tag_name }}"
IPA_NAME="PiliPod ${TAG_NAME}+${BUILD_NUMBER}.ipa"
echo "IPA_NAME=$IPA_NAME" >> $GITHUB_ENV

echo "开始打包,版本号: ${TAG_NAME}, 构建号: ${BUILD_NUMBER}"

# 2. 自动检测是 Workspace 还是 Project
if [ -d "PiliPod.xcworkspace" ]; then
BUILD_CMD="-workspace PiliPod.xcworkspace"
else
BUILD_CMD="-project PiliPod.xcodeproj"
fi

# 3. 编译生成未签名的 Archive,并动态注入版本号
xcodebuild archive \
$BUILD_CMD \
-scheme PiliPod \
-configuration Release \
-archivePath build/PiliPod.xcarchive \
CODE_SIGNING_ALLOWED=NO \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGN_IDENTITY="" \
PROVISIONING_PROFILE_SPECIFIER="" \
MARKETING_VERSION="${TAG_NAME}" \
CURRENT_PROJECT_VERSION="${BUILD_NUMBER}"

# 4. 将解包出的 .app 文件夹包装为未签名的 .ipa 文件
mkdir -p build/Payload
cp -R build/PiliPod.xcarchive/Products/Applications/PiliPod.app build/Payload/
cd build
zip -r "$IPA_NAME" Payload

echo "IPA 导出成功: $IPA_NAME"
Scripts/build-app.sh "$TAG_NAME" "$BUILD_NUMBER"
printf 'BUILD_NUMBER=%s\nIPA_NAME=PiliPod %s+%s.ipa\n' \
"$BUILD_NUMBER" "$TAG_NAME" "$BUILD_NUMBER" >> "$GITHUB_ENV"

- name: Generate Custom Changelog
id: changelog
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Validate Pull Request

on:
pull_request:

permissions:
contents: read

jobs:
build:
runs-on: macos-26

steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up Xcode 26.6
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '26.6'

- name: Build unsigned IPA (Release)
run: Scripts/build-app.sh 1.0.0 1

- name: Compile for iOS Simulator (Debug)
run: |
xcodebuild -quiet build \
-project PiliPod.xcodeproj \
-scheme PiliPod \
-configuration Debug \
-destination 'generic/platform=iOS Simulator' \
-derivedDataPath build/DerivedData \
-clonedSourcePackagesDirPath build/SourcePackages \
CODE_SIGNING_ALLOWED=NO
56 changes: 56 additions & 0 deletions Scripts/build-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
set -euo pipefail

if [[ $# -lt 1 || $# -gt 2 ]]; then
printf '用法: %s <版本号,如 0.3.7> [构建号]\n' "$0" >&2
exit 2
fi

version=$1
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
printf '无效版本号: 需要 X.Y.Z 格式\n' >&2
exit 2
fi

project_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
if [[ $# -eq 2 ]]; then
build_number=$2
else
build_number=$(git -C "$project_root" rev-list --count HEAD)
fi
if [[ ! $build_number =~ ^[1-9][0-9]*$ ]]; then
printf '无效构建号: 需要正整数\n' >&2
exit 2
fi

build_dir="$project_root/build"
ipa_name="PiliPod ${version}+${build_number}.ipa"
mkdir -p "$build_dir"
staging_dir=$(mktemp -d "$build_dir/ipa.XXXXXX")
trap 'rm -rf "$staging_dir"' EXIT

printf '构建未签名 IPA:版本 %s,构建号 %s\n' "$version" "$build_number"
xcodebuild -quiet archive \
-project "$project_root/PiliPod.xcodeproj" \
-scheme PiliPod \
-configuration Release \
-destination 'generic/platform=iOS' \
-archivePath "$staging_dir/PiliPod.xcarchive" \
-derivedDataPath "$build_dir/DerivedData" \
-clonedSourcePackagesDirPath "$build_dir/SourcePackages" \
CODE_SIGNING_ALLOWED=NO \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGN_IDENTITY= \
PROVISIONING_PROFILE_SPECIFIER= \
"MARKETING_VERSION=$version" \
"CURRENT_PROJECT_VERSION=$build_number"

mkdir -p "$staging_dir/Payload"
ditto "$staging_dir/PiliPod.xcarchive/Products/Applications/PiliPod.app" \
"$staging_dir/Payload/PiliPod.app"
(
cd "$staging_dir"
zip -qry output.ipa Payload
)
mv -f "$staging_dir/output.ipa" "$build_dir/$ipa_name"
printf 'IPA 已生成:%s\n' "$build_dir/$ipa_name"
56 changes: 56 additions & 0 deletions Scripts/compile-and-run
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
set -euo pipefail

if [[ $# -gt 1 ]]; then
printf '用法: %s [iOS 模拟器 UDID]\n' "$0" >&2
exit 2
fi

project_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
build_dir="$project_root/build"

selection=$(xcrun simctl list devices available --json | /usr/bin/python3 -c '
import json
import sys

requested = sys.argv[1]
devices = [
device
for runtime, entries in json.load(sys.stdin)["devices"].items()
if runtime.startswith("com.apple.CoreSimulator.SimRuntime.iOS-")
for device in entries
]
if requested:
selected = next((device for device in devices if device["udid"] == requested), None)
else:
selected = next((device for device in devices if device["state"] == "Booted"), None)
if selected is None:
selected = next((device for device in devices if device["name"].startswith("iPhone")), None)
if selected is None:
selected = next(iter(devices), None)
if selected is None:
sys.exit("没有找到可用的 iOS 模拟器")
print(selected["udid"], selected["state"])
' "${1:-}")
read -r simulator_id simulator_state <<< "$selection"

if [[ $simulator_state != Booted ]]; then
xcrun simctl boot "$simulator_id"
fi
xcrun simctl bootstatus "$simulator_id" -b

xcodebuild -quiet build \
-project "$project_root/PiliPod.xcodeproj" \
-scheme PiliPod \
-configuration Debug \
-sdk iphonesimulator \
-destination "platform=iOS Simulator,id=$simulator_id" \
-derivedDataPath "$build_dir/DerivedData" \
-clonedSourcePackagesDirPath "$build_dir/SourcePackages" \
CODE_SIGNING_ALLOWED=NO

app_path="$build_dir/DerivedData/Build/Products/Debug-iphonesimulator/PiliPod.app"
bundle_id=$(plutil -extract CFBundleIdentifier raw -o - "$app_path/Info.plist")
xcrun simctl install "$simulator_id" "$app_path"
open -a Simulator --args -CurrentDeviceUDID "$simulator_id"
xcrun simctl launch "$simulator_id" "$bundle_id"