|
| 1 | +name: Build and Release TrollScript |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: # 手动触发 |
| 5 | + |
| 6 | +env: |
| 7 | + XCODE_VERSION: '16.2' |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + runs-on: macos-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + # 1. 拉取当前 Release 仓库 |
| 15 | + - name: Checkout Release Repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + token: ${{ secrets.GH_TOKEN }} |
| 20 | + |
| 21 | + # 2. 使用 GH_TOKEN 拉取私有仓库 TROLLSTORE |
| 22 | + - name: Checkout Private TrollScript Repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + repository: ${{ secrets.TROLLSTORE }} |
| 26 | + token: ${{ secrets.GH_TOKEN }} |
| 27 | + path: TrollScript-Private |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + # 3. 设置 Xcode 环境 |
| 31 | + - name: Select Xcode Version |
| 32 | + run: | |
| 33 | + sudo xcode-select -s /Applications/Xcode_${{ env.XCODE_VERSION }}.app/Contents/Developer |
| 34 | + xcodebuild -version |
| 35 | + |
| 36 | + - name: Install Dependencies |
| 37 | + run: | |
| 38 | + brew install ldid |
| 39 | + brew install make |
| 40 | + |
| 41 | + # 4. 进入私有仓库目录,运行 build-tipa.sh |
| 42 | + - name: Build TrollScript |
| 43 | + working-directory: TrollScript-Private |
| 44 | + run: | |
| 45 | + chmod +x scripts/build-tipa.sh |
| 46 | + ./scripts/build-tipa.sh |
| 47 | + |
| 48 | + # 5. 复制 release 文件夹到本项目 |
| 49 | + - name: Copy Build Artifacts to Release Repository |
| 50 | + run: | |
| 51 | + mkdir -p release |
| 52 | + cp -r TrollScript-Private/release/* release/ |
| 53 | + |
| 54 | + echo "📦 Build artifacts:" |
| 55 | + ls -la release/ |
| 56 | + |
| 57 | + # 6. 获取私有仓库最后 tag 的 commit 信息 |
| 58 | + - name: Get Version Info from Private Repository |
| 59 | + id: version |
| 60 | + working-directory: TrollScript-Private |
| 61 | + run: | |
| 62 | + # 获取最新 tag |
| 63 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 64 | + if [ -z "$LATEST_TAG" ]; then |
| 65 | + LATEST_TAG="v0.0.0-$(git rev-parse --short HEAD)" |
| 66 | + echo "⚠️ No tag found, using: $LATEST_TAG" |
| 67 | + fi |
| 68 | + |
| 69 | + # 获取 tag 对应的 commit 信息 |
| 70 | + if git rev-parse "$LATEST_TAG" >/dev/null 2>&1; then |
| 71 | + COMMIT_MSG=$(git log -1 --pretty=format:"%B" "$LATEST_TAG" 2>/dev/null || echo "New release") |
| 72 | + else |
| 73 | + COMMIT_MSG=$(git log -1 --pretty=format:"%B" 2>/dev/null || echo "New release") |
| 74 | + fi |
| 75 | + |
| 76 | + COMMIT_SHORT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") |
| 77 | + COMMIT_HASH=$(git rev-parse HEAD 2>/dev/null || echo "") |
| 78 | + |
| 79 | + echo "release_tag=$LATEST_TAG" >> $GITHUB_OUTPUT |
| 80 | + echo "commit_short=$COMMIT_SHORT" >> $GITHUB_OUTPUT |
| 81 | + echo "commit_hash=$COMMIT_HASH" >> $GITHUB_OUTPUT |
| 82 | + |
| 83 | + # 处理多行 commit 消息 |
| 84 | + EOF_MARKER=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) |
| 85 | + echo "commit_msg<<$EOF_MARKER" >> $GITHUB_OUTPUT |
| 86 | + echo "$COMMIT_MSG" >> $GITHUB_OUTPUT |
| 87 | + echo "$EOF_MARKER" >> $GITHUB_OUTPUT |
| 88 | + |
| 89 | + echo "📌 Release Tag: $LATEST_TAG" |
| 90 | + echo "📌 Commit: $COMMIT_SHORT" |
| 91 | + echo "📌 Commit Message:" |
| 92 | + echo "$COMMIT_MSG" |
| 93 | + |
| 94 | + # 7. 创建 Release Notes |
| 95 | + - name: Create Release Notes |
| 96 | + run: | |
| 97 | + RELEASE_TAG="${{ steps.version.outputs.release_tag }}" |
| 98 | + COMMIT_MSG="${{ steps.version.outputs.commit_msg }}" |
| 99 | + COMMIT_SHORT="${{ steps.version.outputs.commit_short }}" |
| 100 | + |
| 101 | + cat > release-notes.md << EOF |
| 102 | + **TrollScript $RELEASE_TAG** |
| 103 | + |
| 104 | + ## 📋 $(date -u '+%Y-%m-%d %H:%M:%S UTC') 更新内容 |
| 105 | + |
| 106 | + $COMMIT_MSG |
| 107 | + |
| 108 | + --- |
| 109 | + |
| 110 | + > Commit: \`$COMMIT_SHORT\` |
| 111 | + EOF |
| 112 | + |
| 113 | + echo "📝 Release Notes:" |
| 114 | + cat release-notes.md |
| 115 | + |
| 116 | + - name: Upload Build Artifact |
| 117 | + uses: actions/upload-artifact@v4 |
| 118 | + with: |
| 119 | + name: TrollScript-${{ steps.version.outputs.release_tag }} |
| 120 | + path: release/*.tipa |
| 121 | + retention-days: 30 |
| 122 | + |
| 123 | + # 8. 在本项目创建 Tag 并提交到 Release |
| 124 | + - name: Create GitHub Release |
| 125 | + env: |
| 126 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 127 | + run: | |
| 128 | + RELEASE_TAG="${{ steps.version.outputs.release_tag }}" |
| 129 | + |
| 130 | + # 查找 TIPA 文件 |
| 131 | + TIPA_FILE=$(find ./release -name "*.tipa" ! -name "*_latest.tipa" 2>/dev/null | head -1 || echo "") |
| 132 | + LATEST_FILE="./release/TrollScript_latest.tipa" |
| 133 | + |
| 134 | + if [ -z "$TIPA_FILE" ]; then |
| 135 | + echo "❌ No TIPA file found" |
| 136 | + exit 1 |
| 137 | + fi |
| 138 | + |
| 139 | + echo "📦 Found TIPA: $TIPA_FILE" |
| 140 | + |
| 141 | + # 准备上传文件 |
| 142 | + UPLOAD_FILES="$TIPA_FILE" |
| 143 | + [ -f "$LATEST_FILE" ] && UPLOAD_FILES="$UPLOAD_FILES $LATEST_FILE" |
| 144 | + |
| 145 | + # 删除已存在的 release(如果有) |
| 146 | + if gh release view "$RELEASE_TAG" &>/dev/null; then |
| 147 | + echo "⚠️ Release $RELEASE_TAG exists, deleting..." |
| 148 | + gh release delete "$RELEASE_TAG" --yes || true |
| 149 | + # 删除对应的 tag |
| 150 | + git push origin :refs/tags/$RELEASE_TAG 2>/dev/null || true |
| 151 | + fi |
| 152 | + |
| 153 | + # 创建新 release(会自动创建 tag) |
| 154 | + gh release create "$RELEASE_TAG" \ |
| 155 | + $UPLOAD_FILES \ |
| 156 | + --title "🧙 TrollScript $RELEASE_TAG" \ |
| 157 | + --notes-file release-notes.md \ |
| 158 | + --draft=false \ |
| 159 | + --prerelease=false |
| 160 | + |
| 161 | + echo "✅ Release $RELEASE_TAG created!" |
| 162 | + |
| 163 | + # 更新 latest release |
| 164 | + echo "📌 Updating latest release..." |
| 165 | + if gh release view "latest" &>/dev/null; then |
| 166 | + gh release delete "latest" --yes || true |
| 167 | + git push origin :refs/tags/latest 2>/dev/null || true |
| 168 | + fi |
| 169 | + |
| 170 | + gh release create "latest" \ |
| 171 | + "$LATEST_FILE" \ |
| 172 | + --title "🧙 TrollScript Latest $RELEASE_TAG" \ |
| 173 | + --notes-file release-notes.md \ |
| 174 | + --draft=false \ |
| 175 | + --prerelease=false |
| 176 | + |
| 177 | + echo "✅ Latest release updated!" |
0 commit comments