From a73bd279beafc0f551813ad3192a902e85a5c80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=B6=E6=9D=96?= Date: Sun, 29 Dec 2024 20:32:29 +0800 Subject: [PATCH] Update Project.swift to include app versioning and build number placeholder; modify GitHub Actions workflow to set build number dynamically. Remove outdated Homebrew update workflow file. This enhances version management and streamlines the release process. --- .github/workflows/release.yml | 13 ++- .github/workflows/update-homebrew.yml | 131 -------------------------- Project.swift | 20 ++-- 3 files changed, 20 insertions(+), 144 deletions(-) delete mode 100644 .github/workflows/update-homebrew.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 29ffffe..b7bd93c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,6 +31,11 @@ jobs: - name: Generate Xcode Project run: | + # 生成基于时间戳的构建号(格式:YYYYMMDDHHmm) + BUILD_NUMBER=$(date "+%Y%m%d%H%M") + # 替换 Project.swift 中的占位符 + sed -i '' "s/@BUILD_NUMBER@/$BUILD_NUMBER/g" Project.swift + echo "Build number set to: $BUILD_NUMBER" tuist generate --no-open - name: Build App @@ -56,11 +61,6 @@ jobs: "DanceKunKun.dmg" \ "DerivedData/Build/Products/Release/DanceKunKun.app" - - name: Create Source Archives - run: | - zip -r "DanceKunKun-${{ github.ref_name }}-src.zip" . \ - -x "*.git*" -x "build/*" -x "*.xcodeproj/*" -x "*.xcworkspace/*" -x "*.dmg" -x "DerivedData/*" - - name: Generate Checksums run: | echo "### DanceKunKun ${{ github.ref_name }}" > checksums.txt @@ -70,7 +70,7 @@ jobs: echo "" >> checksums.txt echo "### SHA-256 Checksums" >> checksums.txt echo "\`\`\`" >> checksums.txt - shasum -a 256 DanceKunKun.dmg "DanceKunKun-${{ github.ref_name }}-src.zip" >> checksums.txt + shasum -a 256 DanceKunKun.dmg >> checksums.txt echo "\`\`\`" >> checksums.txt - name: Release @@ -79,7 +79,6 @@ jobs: with: files: | DanceKunKun.dmg - DanceKunKun-${{ github.ref_name }}-src.zip checksums.txt body_path: checksums.txt draft: false diff --git a/.github/workflows/update-homebrew.yml b/.github/workflows/update-homebrew.yml deleted file mode 100644 index 2d63092..0000000 --- a/.github/workflows/update-homebrew.yml +++ /dev/null @@ -1,131 +0,0 @@ -name: Update Homebrew Tap - -on: - workflow_run: - workflows: ["Build and Release"] - types: - - completed - -jobs: - update-tap: - runs-on: macos-14 - if: ${{ github.event.workflow_run.conclusion == 'success' }} - steps: - - name: Checkout tap - uses: actions/checkout@v4 - with: - repository: ygsgdbd/homebrew-tap - token: ${{ secrets.TAP_TOKEN }} - path: homebrew-tap - - - name: Get release info - id: release - run: | - # 获取最新的 release 信息 - RELEASE_INFO=$(curl -s https://api.github.com/repos/ygsgdbd/DanceKunKun/releases/latest) - VERSION=$(echo "$RELEASE_INFO" | jq -r .tag_name | sed 's/^v//') - DOWNLOAD_URL=$(echo "$RELEASE_INFO" | jq -r '.assets[] | select(.name=="DanceKunKun.dmg") | .browser_download_url') - - echo "version=$VERSION" >> $GITHUB_OUTPUT - - # 下载并验证文件 - HTTP_STATUS=$(curl -L -s -o DanceKunKun.dmg -w "%{http_code}" "$DOWNLOAD_URL") - - if [ "$HTTP_STATUS" != "200" ]; then - echo "::error::Failed to download DMG file. HTTP status: $HTTP_STATUS" - exit 1 - fi - - # 计算 SHA256 - SHA256=$(shasum -a 256 DanceKunKun.dmg | cut -d ' ' -f 1) - if [ -z "$SHA256" ]; then - echo "::error::Failed to calculate SHA256" - exit 1 - fi - echo "sha256=$SHA256" >> $GITHUB_OUTPUT - - # 输出信息用于调试 - echo "Version: $VERSION" - echo "SHA256: $SHA256" - - - name: Verify tap directory - run: | - cd homebrew-tap - mkdir -p Casks - if [ ! -d "Casks" ]; then - echo "::error::Failed to create Casks directory" - exit 1 - fi - - - name: Update formula - run: | - cd homebrew-tap - cat > Casks/dancekunkun.rb << EOL - cask "dancekunkun" do - version "${{ steps.release.outputs.version }}" - sha256 "${{ steps.release.outputs.sha256 }}" - - url "https://github.com/ygsgdbd/DanceKunKun/releases/download/v#{version}/DanceKunKun.dmg" - name "DanceKunKun" - desc "A fun macOS menu bar app featuring a dancing Cai Xukun that grooves to your CPU usage" - homepage "https://github.com/ygsgdbd/DanceKunKun" - - auto_updates false - depends_on macos: ">= :ventura" - - app "DanceKunKun.app" - - zap trash: [ - "~/Library/Application Support/DanceKunKun", - "~/Library/Preferences/top.ygsgdbd.DanceKunKun.plist", - "~/Library/Caches/top.ygsgdbd.DanceKunKun" - ] - end - EOL - - - name: Verify formula - run: | - cd homebrew-tap - if [ ! -f "Casks/dancekunkun.rb" ]; then - echo "::error::Formula file was not created" - exit 1 - fi - - # 简单的语法检查 - ruby -c Casks/dancekunkun.rb || { - echo "::error::Ruby syntax check failed" - exit 1 - } - - - name: Commit and push changes - run: | - cd homebrew-tap - git config user.name "GitHub Action Bot" - git config user.email "github-actions[bot]@users.noreply.github.com" - - # 检查是否有变更 - if git diff --quiet; then - echo "No changes to commit" - exit 0 - fi - - git add Casks/dancekunkun.rb - git commit -m "Update dancekunkun to ${{ steps.release.outputs.version }}" - - # 添加重试逻辑 - MAX_RETRIES=3 - RETRY_COUNT=0 - while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do - if git push; then - echo "Successfully pushed changes" - exit 0 - fi - RETRY_COUNT=$((RETRY_COUNT+1)) - if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then - echo "Push failed, retrying in 5 seconds..." - sleep 5 - fi - done - - echo "::error::Failed to push changes after $MAX_RETRIES attempts" - exit 1 \ No newline at end of file diff --git a/Project.swift b/Project.swift index 613085a..16c9cf7 100644 --- a/Project.swift +++ b/Project.swift @@ -1,5 +1,9 @@ import ProjectDescription +// MARK: - Version +let appVersion = "0.1.3" // 应用版本号 +let buildVersion = "@BUILD_NUMBER@" // 构建版本号占位符,会被 GitHub Actions 替换 + let project = Project( name: "DanceKunKun", options: .options( @@ -10,7 +14,9 @@ let project = Project( base: [ "SWIFT_VERSION": "5.9", "DEVELOPMENT_LANGUAGE": "zh-Hans", - "SWIFT_EMIT_LOC_STRINGS": "YES" + "SWIFT_EMIT_LOC_STRINGS": "YES", + "MARKETING_VERSION": SettingValue(stringLiteral: appVersion), + "CURRENT_PROJECT_VERSION": SettingValue(stringLiteral: buildVersion) ], configurations: [ .debug(name: "Debug"), @@ -28,15 +34,17 @@ let project = Project( "LSUIElement": true, // 设置为纯菜单栏应用 "CFBundleDevelopmentRegion": "zh-Hans", // 设置默认开发区域为简体中文 "CFBundleLocalizations": ["zh-Hans", "zh-Hant", "en"], // 支持的语言列表 - "AppleLanguages": ["zh-Hans"] // 设置默认语言为简体中文 + "AppleLanguages": ["zh-Hans"], // 设置默认语言为简体中文 + "NSHumanReadableCopyright": "Copyright © 2024 ygsgdbd. All rights reserved.", + "LSApplicationCategoryType": "public.app-category.utilities", + "LSMinimumSystemVersion": "13.0", + "CFBundleShortVersionString": .string(appVersion), // 市场版本号 + "CFBundleVersion": .string(buildVersion) // 构建版本号 ]), sources: ["DanceKunKun/Sources/**"], resources: [ "DanceKunKun/Resources/**", - .folderReference(path: "DanceKunKun/Resources/zh-Hans.lproj"), - .folderReference(path: "DanceKunKun/Resources/zh-Hant.lproj"), - .folderReference(path: "DanceKunKun/Resources/en.lproj"), - .folderReference(path: "DanceKunKun/Assets"), + .folderReference(path: "DanceKunKun/Assets") ] ) ]