Skip to content

Commit

Permalink
refactor!: Remove unused APIs (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jan 13, 2023
1 parent 4d67e31 commit a08cd19
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 369 deletions.
4 changes: 0 additions & 4 deletions .github/ISSUE_TEMPLATE.md

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/functional-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Functional Tests

on: [pull_request]


jobs:
test:
strategy:
matrix:
include:
- xcodeVersion: 11.7
osVersion: macos-11
- xcodeVersion: 12.4
osVersion: macos-11
- xcodeVersion: 13.4
osVersion: macos-12
- xcodeVersion: 14.2
osVersion: macos-12

env:
CI: true
_FORCE_LOGS: 1
# https://github.com/actions/runner-images/tree/main/images/macos
runs-on: ${{ matrix.osVersion }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: lts/*
check-latest: true
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "${{ matrix.xcodeVersion }}"
- run: npm install
name: Install dev dependencies
- run: npm run e2e-test
name: Run e2e tests on Xcode@${{ matrix.xcodeVersion }}
26 changes: 0 additions & 26 deletions .github/workflows/node.js.yml

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/publish.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 18.x
uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: lts/*
check-latest: true
- run: npm install --no-package-lock
name: Install dev dependencies
- run: npm run build
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Unit Tests

on: [pull_request, push]


jobs:
prepare_matrix:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.generate-matrix.outputs.versions }}
steps:
- name: Generate Node.js versions matrix
id: generate-matrix
run: |
sudo apt-get install -y lynx
lynx -dump https://endoflife.date/nodejs | grep -E -o '[0-9]+ \(LTS\)' | grep -E -o '([0-9]+)' > eol.list
cat eol.list
lts1=$(cat eol.list | head -1)
lts2=$(cat eol.list | head -2 | tail -1)
lts3=$(cat eol.list | head -3 | tail -1)
VERSIONS="[$lts1, $lts2, $lts3]"
echo ::set-output name=versions::${VERSIONS}
test:
needs:
- prepare_matrix
strategy:
matrix:
node-version: ${{ fromJSON(needs.prepare_matrix.outputs.versions) }}
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm i -g npm
name: Update NPM
- run: npm install --no-package-lock
name: Install dev dependencies
- run: npm run lint
name: Run linter
- run: npm run test
name: Run unit tests
36 changes: 7 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ appium-xcode
[![Release](https://github.com/appium/appium-xcode/actions/workflows/publish.js.yml/badge.svg?branch=master)](https://github.com/appium/appium-xcode/actions/workflows/publish.js.yml)

ES7 module for interacting with Xcode and Xcode-related functions.
Used by [Appium](github.com/appium/appium)
Used by various [Appium](github.com/appium/appium) drivers.

API
===
Expand All @@ -17,50 +17,28 @@ Most functions are memoized, so after they are called once, they will simply ret

Some functions have an auto-retry built into them, they will retry silently a number of times. This is because the Xcode commands sometimes just flake and return bad values (or don't return).

To clear the memoized values, call `clearInternalCache`

### getPath()
### getPath([timeout=15000])
*memoized*

gets path to Xcode
gets path to Xcode Developer root.

### getVersion([num_retries])
### getVersion([parse=false], [retries], [timeout])
*memoized*, *retry*

returns the version of Xcode. Returns strings like `'6.3.1'`

### getAutomationTraceTemplatePath([num_retries])
*memoized, *retry*

returns a path to the default AutomationTraceTemplate

### getAutomationTraceTemplatePathWithoutRetry()

same as `getAutomationTraceTemplatePath()` but without retry or memoization.
returns the version of Xcode formatted as a string, for example `6.3.1`, or a version object if `parse` is `true`

### getMaxIOSSDK([num_retries])
*memoized*, *retry*

returns largest IOS SDK version supported by Xcode.
returns the highest IOS SDK version supported by Xcode.
eg: `'8.3'`

### getMaxIOSSDKWithoutRetry()

same as `getMaxIOSDK()` but without retry or memoization

### getMaxTVOSSDK([num_retries])
*memoized*, *retry*

returns largest tvOS SDK version supported by Xcode.
returns highest tvOS SDK version supported by Xcode.
eg: `'10.1'`

### getMaxTVOSSDKWithoutRetry()

same as `getMaxTVOSSDK()` but without retry or memoization

### clearInternalCache()
clears the internal cache used for memoizing functions.

Develop
=======

Expand Down
34 changes: 19 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
// transpile:main

import * as xcode from './lib/xcode';


const {
getPath, getVersion, getAutomationTraceTemplatePath, getMaxIOSSDK,
getAutomationTraceTemplatePathWithoutRetry, getMaxIOSSDKWithoutRetry,
getConnectedDevices, clearInternalCache, getInstrumentsPath,
getCommandLineToolsVersion, getMaxTVOSSDK, getMaxTVOSSDKWithoutRetry,
import {
getPath,
getVersion,
getMaxIOSSDK,
getMaxTVOSSDK,
getClangVersion,
} = xcode;
} from './lib/xcode';

const xcode = {
getPath,
getVersion,
getMaxIOSSDK,
getMaxTVOSSDK,
getClangVersion
};

export {
getPath, getVersion, getAutomationTraceTemplatePath, getMaxIOSSDK,
getAutomationTraceTemplatePathWithoutRetry, getMaxIOSSDKWithoutRetry,
getConnectedDevices, clearInternalCache, getInstrumentsPath,
getCommandLineToolsVersion, getMaxTVOSSDK, getMaxTVOSSDKWithoutRetry,
getClangVersion,
getPath,
getVersion,
getMaxIOSSDK,
getMaxTVOSSDK,
getClangVersion
};
export default xcode;
72 changes: 72 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import _ from 'lodash';
import B from 'bluebird';
import { exec } from 'teen_process';
import { fs, plist } from '@appium/support';
import path from 'path';

export const XCRUN_TIMEOUT = 15000;

/**
* Executes 'xcrun' command line utility
*
* @param {string[]} args xcrun arguments
* @param {number} timeout [15000] The maximum number of milliseconds to wait until xcrun exists
* @returns {Promise<import("teen_process").ExecResult>} The result of xcrun execution
* @throws {Error} If xcrun returned non-zero exit code or timed out
*/
export async function runXcrunCommand (args, timeout = XCRUN_TIMEOUT) {
try {
return await exec('xcrun', args, {timeout});
} catch (err) {
// the true error can be hidden within the stderr
if (err.stderr) {
err.message = `${err.message}: ${err.stderr}`;
}

throw err;
}
}

/**
* Uses macOS Spotlight service to detect where the given app is installed
*
* @param {string} bundleId Bundle identifier of the target app
* @returns {Promise<string[]>} Full paths to where the app with the given bundle id is present.
*/
export async function findAppPaths (bundleId) {
let stdout;
try {
({stdout} = await exec('/usr/bin/mdfind', [
`kMDItemCFBundleIdentifier=${bundleId}`
]));
} catch (e) {
return [];
}

const matchedPaths = _.trim(stdout)
.split('\n')
.map(_.trim)
.filter(Boolean);
if (_.isEmpty(matchedPaths)) {
return [];
}
const results = matchedPaths.map((p) => (async () => {
if (await fs.exists(p)) {
return p;
}
})());
return (await B.all(results)).filter(Boolean);
}

/**
* Finds and retrieves the content of the Xcode's Info.plist file
*
* @param {string} developerRoot Full path to the Contents/Developer folder under Xcode.app root
* @returns {Promise<object>} All plist entries as an object or an empty object if no plist was found
*/
export async function readXcodePlist (developerRoot) {
const plistPath = path.resolve(developerRoot, '..', 'Info.plist');
return await fs.exists(plistPath)
? await plist.parsePlistFile(plistPath)
: {};
}
Loading

0 comments on commit a08cd19

Please sign in to comment.