From ac0723ab635bb93e4e78307df69d212a62d0538f Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Mon, 25 Sep 2023 10:34:56 -0400 Subject: [PATCH] chore(build): add `maccatalyst` as a build target (#1701) * Add `maccatalyst` as a build target. * Remove debug log. * Fix step name. * Fix xcode build command. --- .github/workflows/build_and_test_debug.yml | 33 ++++++++++++++ src/build/get_build_parameters.mjs | 2 +- src/cordova/apple/README.md | 6 +-- src/cordova/build.action.mjs | 52 +++++++++++++--------- src/cordova/setup.action.mjs | 2 + src/cordova/test.action.mjs | 6 ++- 6 files changed, 75 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build_and_test_debug.yml b/.github/workflows/build_and_test_debug.yml index e028a99bd4..144cf98b5e 100644 --- a/.github/workflows/build_and_test_debug.yml +++ b/.github/workflows/build_and_test_debug.yml @@ -156,6 +156,39 @@ jobs: xcode_archive_path: ./output/coverage/apple/ios/TestResult.xcresult flags: unittests, apple, ios + maccatalyst_debug_build: + name: Mac Catalyst Debug Build + runs-on: macos-13 + timeout-minutes: 20 + needs: web_test + steps: + - name: Display XCode + run: xcode-select --print-path + + - name: Checkout + uses: actions/checkout@v2.3.4 + + - name: Install Node + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: npm + + - name: Install NPM Dependencies + run: npm ci + + - name: Test OutlineAppleLib + run: npm run action cordova/test maccatalyst + + - name: Build Mac Catalyst Client + run: npm run action cordova/build maccatalyst + + - uses: codecov/codecov-action@v3 + with: + xcode: true + xcode_archive_path: ./output/coverage/apple/maccatalyst/TestResult.xcresult + flags: unittests, apple, maccatalyst + android_debug_build: name: Android Debug Build runs-on: ubuntu-20.04 diff --git a/src/build/get_build_parameters.mjs b/src/build/get_build_parameters.mjs index 29c931546b..b897650184 100644 --- a/src/build/get_build_parameters.mjs +++ b/src/build/get_build_parameters.mjs @@ -14,7 +14,7 @@ import minimist from 'minimist'; -const VALID_PLATFORMS = ['linux', 'windows', 'ios', 'macos', 'android', 'browser']; +const VALID_PLATFORMS = ['linux', 'windows', 'ios', 'macos', 'maccatalyst', 'android', 'browser']; const VALID_BUILD_MODES = ['debug', 'release']; const MS_PER_HOUR = 1000 * 60 * 60; diff --git a/src/cordova/apple/README.md b/src/cordova/apple/README.md index 7d367fc443..a0fd2353fd 100644 --- a/src/cordova/apple/README.md +++ b/src/cordova/apple/README.md @@ -18,7 +18,7 @@ You will need: The XCode project is created by Cordova. To create the project and open it on XCode, use `npm run action cordova/setup $PLATFORM`, then open the XCode workspace file (not the project). -For the **iOS** client: +For the **iOS** client and **Mac Catalyst** client: ```sh npm run action cordova/build ios && open ./src/cordova/apple/ios.xcworkspace @@ -138,7 +138,7 @@ You can kill the app and extension with the [`pkill` command](https://man7.org/l pkill -9 Outline VpnExtension ``` -Sometimes the processes will not die, even with `-9`. For the Outline process, you may need to kill its parent process, usually `debugserver`. +Sometimes the processes will not die, even with `-9`. For the Outline process, you may need to kill its parent process, usually `debugserver`. You can check running processes with the [`pgrep` command](https://man7.org/linux/man-pages/man1/pgrep.1.html): ```sh @@ -185,7 +185,7 @@ You may want to also delete the VPN configurations: 1. Press *Remove Configuration…* and confirm -#### Restart +#### Restart If all fails, restart your device. That usually takes care of the issue. diff --git a/src/cordova/build.action.mjs b/src/cordova/build.action.mjs index 093959e9df..2847258f26 100644 --- a/src/cordova/build.action.mjs +++ b/src/cordova/build.action.mjs @@ -26,7 +26,7 @@ import {getBuildParameters} from '../build/get_build_parameters.mjs'; import {downloadHttpsFile} from '../build/download_file.mjs'; /** - * @description Builds the parameterized cordova binary (ios, macos, android). + * @description Builds the parameterized cordova binary (ios, macos, maccatalyst, android). * * @param {string[]} parameters */ @@ -62,25 +62,49 @@ export async function main(...parameters) { ); case 'ios' + 'debug': case 'macos' + 'debug': + case 'maccatalyst' + 'debug': return appleDebug(platform); case 'ios' + 'release': case 'macos' + 'release': + case 'maccatalyst' + 'release': return appleRelease(platform); } } +function getXcodeBuildArgs(platform) { + let destination, workspaceFilename; + switch (platform) { + case 'macos': + destination = 'generic/platform=macOS'; + workspaceFilename = 'macos.xcworkspace'; + break; + case 'maccatalyst': + destination = 'generic/platform=macOS,variant=Mac Catalyst'; + workspaceFilename = 'ios.xcworkspace'; + break; + case 'ios': + default: + destination = 'generic/platform=iOS'; + workspaceFilename = 'ios.xcworkspace'; + break; + } + return [ + '-workspace', + path.join(getRootDir(), 'src', 'cordova', 'apple', workspaceFilename), + '-scheme', + 'Outline', + '-destination', + destination, + ]; +} + async function appleDebug(platform) { console.warn(`WARNING: building "${platform}" in [DEBUG] mode. Do not publish this build!!`); return spawnStream( 'xcodebuild', 'clean', - '-workspace', - path.join(getRootDir(), 'src', 'cordova', 'apple', `${platform}.xcworkspace`), - '-scheme', - 'Outline', - '-destination', - platform === 'ios' ? 'generic/platform=iOS' : 'generic/platform=macOS', + ...getXcodeBuildArgs(platform), 'build', '-configuration', 'Debug', @@ -90,19 +114,7 @@ async function appleDebug(platform) { } async function appleRelease(platform) { - return spawnStream( - 'xcodebuild', - 'clean', - '-workspace', - path.join(getRootDir(), 'src', 'cordova', 'apple', `${platform}.xcworkspace`), - '-scheme', - 'Outline', - '-destination', - platform === 'ios' ? 'generic/platform=iOS' : 'generic/platform=macOS', - 'archive', - '-configuration', - 'Release' - ); + return spawnStream('xcodebuild', 'clean', ...getXcodeBuildArgs(platform), 'archive', '-configuration', 'Release'); } async function androidDebug(verbose) { diff --git a/src/cordova/setup.action.mjs b/src/cordova/setup.action.mjs index ac6ff7560e..e4c9ca4400 100644 --- a/src/cordova/setup.action.mjs +++ b/src/cordova/setup.action.mjs @@ -55,10 +55,12 @@ export async function main(...parameters) { console.warn('NOTE: You must open the Outline.zip file after building to upload to the Play Store.'); return androidRelease(versionName, buildNumber, verbose); case 'ios' + 'debug': + case 'maccatalyst' + 'debug': return appleIosDebug(verbose); case 'macos' + 'debug': return appleMacOsDebug(verbose); case 'ios' + 'release': + case 'maccatalyst' + 'release': return appleIosRelease(versionName, buildNumber, verbose); case 'macos' + 'release': return appleMacOsRelease(versionName, buildNumber, verbose); diff --git a/src/cordova/test.action.mjs b/src/cordova/test.action.mjs index 4b520dc4df..8a7faef60e 100644 --- a/src/cordova/test.action.mjs +++ b/src/cordova/test.action.mjs @@ -25,6 +25,8 @@ import {spawnStream} from '../build/spawn_stream.mjs'; const APPLE_ROOT = path.join(getRootDir(), 'src', 'cordova', 'apple'); const APPLE_LIBRARY_NAME = 'OutlineAppleLib'; +const SUPPORTED_PLATFORMS = new Set(['ios', 'macos', 'maccatalyst']); + /** * @description Tests the parameterized cordova binary (ios, macos). * @@ -35,8 +37,8 @@ export async function main(...parameters) { _: [outlinePlatform], } = minimist(parameters); - if (outlinePlatform !== 'macos' && outlinePlatform !== 'ios') { - throw new Error('Testing is only currently supported for Apple platforms.'); + if (!SUPPORTED_PLATFORMS.has(outlinePlatform)) { + throw new Error('Testing is only currently supported for platforms: ' + Array.from(SUPPORTED_PLATFORMS)); } if (os.platform() !== 'darwin') {