From b9a4a88460fa3234ca33b62875b45b990c783cb4 Mon Sep 17 00:00:00 2001 From: "Zeno.Chen" Date: Thu, 24 Sep 2026 16:10:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(ci):=20=E6=A0=A1=E9=AA=8C=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E7=89=88=E6=9C=AC=E5=B9=B6=E8=A1=A5=E5=85=85=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 41 ++++----------------------- Scripts/build-app.sh | 56 +++++++++++++++++++++++++++++++++++++ Scripts/compile-and-run | 56 +++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 36 deletions(-) create mode 100755 Scripts/build-app.sh create mode 100755 Scripts/compile-and-run diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f4d60a..9145922 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,44 +27,13 @@ jobs: - 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 diff --git a/Scripts/build-app.sh b/Scripts/build-app.sh new file mode 100755 index 0000000..65d6892 --- /dev/null +++ b/Scripts/build-app.sh @@ -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" diff --git a/Scripts/compile-and-run b/Scripts/compile-and-run new file mode 100755 index 0000000..00b7ff4 --- /dev/null +++ b/Scripts/compile-and-run @@ -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" From aba90b59a2d28c1c43496ebb4e40ef05a429f888 Mon Sep 17 00:00:00 2001 From: "Zeno.Chen" Date: Fri, 25 Sep 2026 21:44:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?ci:=20=E4=B8=BA=20PR=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20Xcode=2026.6=20=E6=9E=84=E5=BB=BA=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 2 +- .github/workflows/ci.yml | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9145922..43c5219 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ 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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..942003b --- /dev/null +++ b/.github/workflows/ci.yml @@ -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