|
| 1 | +name: Build & Release iOS and macOS Extensions |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - '**.swift' |
| 9 | + - 'ios/**' |
| 10 | + - 'mos/**' |
| 11 | + - '.github/workflows/build-and-release.yml' |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + draft: |
| 15 | + description: 'Create as draft (for testing)' |
| 16 | + required: true |
| 17 | + default: 'true' |
| 18 | + type: choice |
| 19 | + options: |
| 20 | + - 'true' |
| 21 | + - 'false' |
| 22 | + |
| 23 | +jobs: |
| 24 | + check-version: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + contents: read |
| 28 | + outputs: |
| 29 | + version: ${{ steps.extract.outputs.version }} |
| 30 | + tag_exists: ${{ steps.check_tag.outputs.exists }} |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + fetch-depth: 0 |
| 35 | + fetch-tags: true |
| 36 | + |
| 37 | + - name: Extract version from Xcode project |
| 38 | + id: extract |
| 39 | + run: | |
| 40 | + VERSION=$(grep -m1 'MARKETING_VERSION = ' ios/Flean.xcodeproj/project.pbxproj | awk -F ' = ' '{ gsub(/;/,"",$2); print $2; exit }') |
| 41 | + echo "version=v$VERSION" >> $GITHUB_OUTPUT |
| 42 | + echo "Detected version: v$VERSION" |
| 43 | +
|
| 44 | + - name: Check if tag exists |
| 45 | + id: check_tag |
| 46 | + run: | |
| 47 | + if git ls-remote --tags --exit-code origin "refs/tags/${{ steps.extract.outputs.version }}" >/dev/null 2>&1; then |
| 48 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 49 | + echo "Tag already exists!" |
| 50 | + else |
| 51 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 52 | + echo "Tag does not exist - ready to build" |
| 53 | + fi |
| 54 | +
|
| 55 | + build-and-release: |
| 56 | + needs: check-version |
| 57 | + if: needs.check-version.outputs.tag_exists == 'false' |
| 58 | + runs-on: macos-latest |
| 59 | + permissions: |
| 60 | + contents: write |
| 61 | + |
| 62 | + steps: |
| 63 | + - uses: actions/checkout@v4 |
| 64 | + |
| 65 | + # iOS Build |
| 66 | + - name: Build iOS App |
| 67 | + run: | |
| 68 | + cd ios |
| 69 | + mkdir -p build |
| 70 | +
|
| 71 | + xcodebuild build \ |
| 72 | + -project Flean.xcodeproj \ |
| 73 | + -target Flean \ |
| 74 | + -configuration Release \ |
| 75 | + -destination 'generic/platform=iOS' \ |
| 76 | + -skipPackagePluginValidation \ |
| 77 | + SYMROOT=build \ |
| 78 | + CODE_SIGN_IDENTITY="" \ |
| 79 | + CODE_SIGNING_REQUIRED=NO \ |
| 80 | + CODE_SIGN_ENTITLEMENTS="" |
| 81 | +
|
| 82 | + # Package the .app as a proper IPA (Payload/Flean.app zipped) |
| 83 | + APP_PATH=$(find build -name "Flean.app" -type d | head -1) |
| 84 | + if [ -z "$APP_PATH" ]; then |
| 85 | + echo "❌ Flean.app not found" |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | + mkdir -p build/ipa/Payload |
| 89 | + cp -r "$APP_PATH" build/ipa/Payload/ |
| 90 | + ( cd build/ipa && zip -r ../Flean.ipa Payload ) |
| 91 | + echo "✅ iOS build succeeded" |
| 92 | +
|
| 93 | + # macOS Build |
| 94 | + - name: Build macOS App |
| 95 | + run: | |
| 96 | + cd mos |
| 97 | + mkdir -p build |
| 98 | +
|
| 99 | + xcodebuild build \ |
| 100 | + -project Flean.xcodeproj \ |
| 101 | + -target Flean \ |
| 102 | + -configuration Release \ |
| 103 | + -skipPackagePluginValidation \ |
| 104 | + SYMROOT=build \ |
| 105 | + CODE_SIGN_IDENTITY="" \ |
| 106 | + CODE_SIGNING_REQUIRED=NO \ |
| 107 | + CODE_SIGN_ENTITLEMENTS="" |
| 108 | +
|
| 109 | + # Find and zip the .app into a fixed location matching the upload step |
| 110 | + APP_PATH=$(find build -name "Flean.app" -type d | head -1) |
| 111 | + if [ -z "$APP_PATH" ]; then |
| 112 | + echo "❌ Flean.app not found" |
| 113 | + exit 1 |
| 114 | + fi |
| 115 | +
|
| 116 | + # Create a zip whose top-level entry is Flean.app |
| 117 | + OUT_ZIP="$(pwd)/build/Flean.app.zip" |
| 118 | + APP_DIR="$(dirname "$APP_PATH")" |
| 119 | + APP_NAME="$(basename "$APP_PATH")" |
| 120 | + ( cd "$APP_DIR" && zip -r "$OUT_ZIP" "$APP_NAME" ) |
| 121 | + echo "✅ macOS build succeeded" |
| 122 | +
|
| 123 | + # Create tag |
| 124 | + - name: Create Git Tag |
| 125 | + run: | |
| 126 | + git config user.name "github-actions" |
| 127 | + git config user.email "github-actions@github.com" |
| 128 | + VERSION="${{ needs.check-version.outputs.version }}" |
| 129 | + # Create local tag (no-op if already exists locally from a shallow clone) |
| 130 | + git tag "$VERSION" 2>/dev/null || echo "Local tag $VERSION already exists, proceeding with push" |
| 131 | + # Push to remote; fail clearly if the tag was created by a concurrent run |
| 132 | + if ! git push origin "$VERSION"; then |
| 133 | + echo "::error::Tag $VERSION already exists on remote. A release for this version may already exist." |
| 134 | + exit 1 |
| 135 | + fi |
| 136 | +
|
| 137 | + # Create Release |
| 138 | + - name: Create Release |
| 139 | + uses: actions/create-release@v1 |
| 140 | + id: create_release |
| 141 | + env: |
| 142 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 143 | + with: |
| 144 | + tag_name: ${{ needs.check-version.outputs.version }} |
| 145 | + release_name: "Flean ${{ needs.check-version.outputs.version }}" |
| 146 | + draft: ${{ github.event.inputs.draft == 'true' }} |
| 147 | + prerelease: false |
| 148 | + |
| 149 | + # Upload iOS App |
| 150 | + - name: Upload iOS App |
| 151 | + uses: actions/upload-release-asset@v1 |
| 152 | + env: |
| 153 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 154 | + with: |
| 155 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 156 | + asset_path: ./ios/build/Flean.ipa |
| 157 | + asset_name: Flean.ipa |
| 158 | + asset_content_type: application/octet-stream |
| 159 | + |
| 160 | + # Upload macOS App |
| 161 | + - name: Upload macOS App |
| 162 | + uses: actions/upload-release-asset@v1 |
| 163 | + env: |
| 164 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 165 | + with: |
| 166 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 167 | + asset_path: ./mos/build/Flean.app.zip |
| 168 | + asset_name: Flean.app.zip |
| 169 | + asset_content_type: application/zip |
0 commit comments