build-webdriveragents.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const buildWebDriverAgent = require('./build-webdriveragent');
  2. const { asyncify } = require('asyncbox');
  3. const { fs, logger } = require('@appium/support');
  4. const { exec } = require('teen_process');
  5. const path = require('path');
  6. const log = new logger.getLogger('WDABuild');
  7. async function buildAndUploadWebDriverAgents () {
  8. // Get all xcode paths from /Applications/
  9. const xcodePaths = (await fs.readdir('/Applications/'))
  10. .filter((file) => file.toLowerCase().startsWith('xcode_'));
  11. // Determine which xcodes need to be skipped
  12. let excludedXcodeArr = (process.env.EXCLUDE_XCODE || '').replace(/\s/g, '').split(',');
  13. log.info(`Will skip xcode versions: '${excludedXcodeArr}'`);
  14. for (let xcodePath of xcodePaths) {
  15. if (xcodePath.includes('beta')) {
  16. log.info(`Skipping beta Xcode '${xcodePath}'`);
  17. continue;
  18. }
  19. // Skip if .0 because redundant (example: skip 11.4.0 because it already does 11.4)
  20. const [, , patch] = xcodePath.split('.');
  21. if (patch === '0') {
  22. log.info(`Skipping xcode '${xcodePath}'`);
  23. continue;
  24. }
  25. // Build webdriveragent for this xcode version
  26. log.info(`Running xcode-select for '${xcodePath}'`);
  27. await exec('sudo', ['xcode-select', '-s', `/Applications/${xcodePath}/Contents/Developer`]);
  28. const xcodeVersion = path.parse(xcodePath).name.split('_', 2)[1];
  29. if (excludedXcodeArr.includes(xcodeVersion)) {
  30. log.info(`Skipping xcode version '${xcodeVersion}'`);
  31. continue;
  32. }
  33. log.info('Building webdriveragent for xcode version', xcodeVersion);
  34. try {
  35. await buildWebDriverAgent(xcodeVersion);
  36. } catch (e) {
  37. log.error(`Skipping build for '${xcodeVersion} due to error: ${e}'`);
  38. }
  39. }
  40. // Divider log line
  41. log.info('\n');
  42. }
  43. if (require.main === module) {
  44. asyncify(buildAndUploadWebDriverAgents);
  45. }
  46. module.exports = buildAndUploadWebDriverAgents;