AWS CDK Device Farm Action for CodePipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codepipeline = require('@aws-cdk/aws-codepipeline'); | |
import iam = require('@aws-cdk/aws-iam'); | |
import cdk = require('@aws-cdk/core'); | |
import { ActionCategory } from '@aws-cdk/aws-codepipeline'; | |
import { Action } from '@aws-cdk/aws-codepipeline-actions'; | |
/** | |
* The OS and type of application you are testing. | |
*/ | |
export enum DeviceFarmAppType { | |
IOS = 'iOS', | |
ANDROID = 'Android', | |
WEB = 'Web' | |
} | |
/** | |
* Specifies the supported testing framework for your test. | |
*/ | |
export enum DeviceFarmTestType { | |
/** | |
* The action will have the Appium Java JUnit Test Type. | |
*/ | |
APPIUM_JAVA_JUNIT = 'APPIUM_JAVA_JUNIT', | |
APPIUM_JAVA_TESTNG = 'APPIUM_JAVA_TESTNG', | |
APPIUM_PYTHON = 'APPIUM_PYTHON', | |
APPIUM_WEB_JAVA_JUNIT = 'APPIUM_WEB_JAVA_JUNIT', | |
APPIUM_WEB_JAVA_TESTNG = 'APPIUM_WEB_JAVA_TESTNG', | |
APPIUM_WEB_PYTHON = 'APPIUM_WEB_PYTHON', | |
BUILTIN_EXPLORER = 'BUILTIN_EXPLORER', | |
BUILTIN_FUZZ = 'BUILTIN_FUZZ', | |
CALABASH = 'CALABASH', | |
INSTRUMENTATION = 'INSTRUMENTATION', | |
UIAUTOMATION = 'UIAUTOMATION', | |
UIAUTOMATOR = 'UIAUTOMATOR', | |
XCTEST = 'XCTEST', | |
XCTEST_UI = 'XCTEST_UI' | |
} | |
/** | |
* Construction properties of the {@link DeviceFarmAction Device Farm CodePipeline action}. | |
*/ | |
export interface DeviceFarmConfigurationProps { | |
readonly appType: DeviceFarmAppType; | |
/** | |
* The Device Farm project ID. | |
* | |
* To find your project ID, in the Device Farm console, choose your project. In the browser, copy the URL of your new project. The URL contains the project ID. The project ID is the value in the URL after projects/. In the following example, the project ID is `eec4905f-98f8-40aa-9afc-4c1cfexample`. | |
* ``` | |
* https://<region-URL>/devicefarm/home?region=us-west-2#/projects/eec4905f-98f8 | |
* ``` | |
*/ | |
readonly projectId: string; | |
/** | |
* The name and location of the application file in your input artifact. For example: `s3-ios-test-1.ipa` | |
*/ | |
readonly app: string; | |
/** | |
* The Device Farm device pool ARN. | |
* | |
* To get the available device pool ARNs for the project, including the ARN for Top Devices, use the AWS CLI to enter the following command: | |
* ``` | |
* aws devicefarm list-device-pools --arn arn:aws:devicefarm:us-west-2:account_ID:project:project_ID | |
* ``` | |
*/ | |
readonly devicePoolArn: string; | |
/** | |
* Specifies the supported testing framework for your test. | |
*/ | |
readonly testType: DeviceFarmTestType; | |
/** | |
* A Boolean value that indicates whether to enable Bluetooth at the beginning of the test. | |
*/ | |
readonly radioBluetoothEnabled?: boolean; | |
/** | |
* A Boolean value that indicates whether to record device performance data such as CPU, FPS, and memory performance during the test. | |
*/ | |
readonly recordAppPerformanceData?: boolean; | |
/** | |
* A Boolean value that indicates whether to record video during the test. | |
*/ | |
readonly recordVideo?: boolean; | |
/** | |
* A Boolean value that indicates whether to enable Wi-Fi at the beginning of the test. | |
*/ | |
readonly radioWifiEnabled?: boolean; | |
/** | |
* A Boolean value that indicates whether to enable NFC at the beginning of the test. | |
*/ | |
readonly radioNfcEnabled?: boolean; | |
/** | |
* A Boolean value that indicates whether to enable GPS at the beginning of the test. | |
*/ | |
readonly radioGpsEnabled?: boolean; | |
/** | |
* The name and path of the test definition file in your source location. The path is relative to the root of the input artifact for your test. | |
*/ | |
readonly test?: string; | |
/** | |
* The number of user interface events for the fuzz test to perform, between 1 and 10,000. | |
*/ | |
readonly fuzzEventCount?: number; | |
/** | |
* The number of milliseconds for the fuzz test to wait before performing the next user interface event, between 1 and 1,000. | |
*/ | |
readonly fuzzEventThrottle?: number; | |
/** | |
* A seed for the fuzz test to use for randomizing user interface events. Using the same number for subsequent fuzz tests results in identical event sequences. | |
*/ | |
readonly fuzzRandomizerSeed?: string; | |
/** | |
* The location on the host machine where custom artifacts will be stored. | |
*/ | |
readonly customHostMachineArtifacts?: string; | |
/** | |
* The location on the device where custom artifacts will be stored. | |
*/ | |
readonly customDeviceArtifacts?: string; | |
/** | |
* A Boolean value that indicates whether to only use your unmetered devices when running tests in this step. | |
*/ | |
readonly unmeteredDevicesOnly?: boolean; | |
/** | |
* The number of minutes a test run will execute per device before it times out. | |
*/ | |
readonly jobTimeoutMinutes?: number; | |
/** | |
* The latitude of the device expressed in geographic coordinate system degrees. | |
*/ | |
readonly latitude?: number; | |
/** | |
* The longitude of the device expressed in geographic coordinate system degrees. | |
*/ | |
readonly longitude?: number; | |
} | |
export interface DeviceFarmActionProps | |
extends codepipeline.CommonAwsActionProps { | |
readonly configuration: DeviceFarmConfigurationProps; | |
readonly input: codepipeline.Artifact; | |
} | |
/** | |
* CodePipeline build action that uses AWS Device Farm. | |
*/ | |
export class DeviceFarmAction extends Action { | |
private readonly props: DeviceFarmActionProps; | |
constructor(props: DeviceFarmActionProps) { | |
super({ | |
...props, | |
category: ActionCategory.TEST, | |
provider: 'DeviceFarm', | |
artifactBounds: { | |
minInputs: 1, | |
maxInputs: 1, | |
minOutputs: 0, | |
maxOutputs: 0 | |
}, | |
inputs: [props.input], | |
owner: 'AWS', | |
version: '1' | |
}); | |
this.props = props; | |
} | |
protected bound( | |
scope: cdk.Construct, | |
_stage: codepipeline.IStage, | |
options: codepipeline.ActionBindOptions | |
): codepipeline.ActionConfig { | |
// grant the Pipeline role the required permissions to this Project | |
options.role.addToPrincipalPolicy( | |
new iam.PolicyStatement({ | |
resources: ['*'], | |
actions: [ | |
'devicefarm:ListProjects', | |
'devicefarm:ListDevicePools', | |
'devicefarm:GetRun', | |
'devicefarm:GetUpload', | |
'devicefarm:CreateUpload', | |
'devicefarm:ScheduleRun' | |
] | |
}) | |
); | |
options.bucket.grantRead(options.role); | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
const configuration: any = { | |
AppType: this.props.configuration.appType, | |
ProjectId: this.props.configuration.projectId, | |
App: this.props.configuration.app, | |
DevicePoolArn: this.props.configuration.devicePoolArn, | |
TestType: this.props.configuration.testType, | |
RadioBluetoothEnabled: | |
this.props.configuration.radioBluetoothEnabled, | |
RecordAppPerformanceData: | |
this.props.configuration.recordAppPerformanceData, | |
RecordVideo: this.props.configuration.recordVideo, | |
RadioWifiEnabled: this.props.configuration.radioWifiEnabled, | |
RadioNfcEnabled: this.props.configuration.radioNfcEnabled, | |
RadioGpsEnabled: this.props.configuration.radioGpsEnabled, | |
Test: this.props.configuration.test, | |
FuzzEventCount: this.props.configuration.fuzzEventCount, | |
FuzzEventThrottle: this.props.configuration.fuzzEventThrottle, | |
FuzzRandomizerSeed: this.props.configuration.fuzzRandomizerSeed, | |
CustomHostMachineArtifacts: | |
this.props.configuration.customHostMachineArtifacts, | |
CustomDeviceArtifacts: | |
this.props.configuration.customDeviceArtifacts, | |
UnmeteredDevicesOnly: this.props.configuration.unmeteredDevicesOnly, | |
JobTimeoutMinutes: this.props.configuration.jobTimeoutMinutes, | |
Latitude: this.props.configuration.latitude, | |
Longitude: this.props.configuration.longitude | |
}; | |
return { | |
configuration | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment