Skip to content

Commit

Permalink
refactor: ios test artifacts cleanup #1345 (#1350)
Browse files Browse the repository at this point in the history
#1345 - iOS Tests artifacts cleanup

Changes:
* renamed some variables inside flankScripts/ios 
* added scripts for generating IPA file instead of .xctestrun for gameloop example
* reorganised test artefacts (removed unused files, moved them to correct directories
* renamed *FlankMultiTestTargetsExample* to *FlankTestPlansExample* // CC: @jan-gogo  
* changed all references to old test artefacts
* rebuilded EarlGrey example with compatible Xcode version

Previously:
<img width="1046" alt="Screenshot 2020-11-25 at 13 36 07" src="https://user-images.githubusercontent.com/31246956/100228584-2f5e4480-2f23-11eb-9292-112335fd3db1.png">

Now:
<img width="1009" alt="Screenshot 2020-11-25 at 13 28 07" src="https://user-images.githubusercontent.com/31246956/100228420-f1f9b700-2f22-11eb-95db-b9291d83cc38.png">

## Test Plan
> How do we know the code works?

1. If you want to easily notice that artifact generation is working correctly you can clear your linked local `test_artifacts` directory.
1. Run `flankScripts shell ops ios`, this command should generate all ios artifacts one by one, and copy each to local `test_artifacts` dir.
1. Make sure the console log doesn't show any error.
1. Make sure the `test_artifacts` directory is containing the following directories: [ EarlGreyExample, FlankExample, FlankGameLoopExample, FlankTestPlansExample ]
1. Run tests manually on each ios project and make sure the results are the same as expected (This step should be widely detailed and updated!!!).

## Checklist

- [x] Documented
- [x] Unit tested
  • Loading branch information
zuziaka authored Dec 1, 2020
1 parent f953384 commit 3de1718
Show file tree
Hide file tree
Showing 61 changed files with 460 additions and 1,146 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.iml
.idea/
build/
Build/
out/
.DS_Store
.gradle/
Expand Down
66 changes: 66 additions & 0 deletions docs/test_artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,69 @@ To export path to your local flank repository just source [.env](../.env) file.
> As a developer I want to remove test artifacts
* Run `flankScripts testArtifacts remove` this will remove the remote copy of test artifacts for current working branch.


## iOS test artifacts

Currently we have 4 different iOS test projects:

1. EarlGreyExample
2. FlankExample
3. FlankGameLoopExample
4. FlankTestPlansExample

Source code of each of them is located under: [test_projects/ios](../test_projects/ios)

Test artifacts for each project contains:
* build output in Debug-iphoneos
* zipped build output in PROJECT_NAME.zip,
* .xctestrun file for each test target

### EarlGreyExample

This project is basically clone of [EarlGrey](https://github.com/google/EarlGrey).
Source project contains two test targets: EarlGreyExampleSwiftTests, EarlGreyExampleTests.

#### Generate
Run: `flankScripts shell ops build_earl_grey_example`.

#### Source Code
[test_projects/ios/EarlGreyExample](../test_projects/ios/EarlGreyExample)


### FlankExample

Simple project with two test targets: FlankExampleTests, FlankExampleSecondTests.

#### Generate
Run: `flankScripts shell ops build_flank_example`.

#### Source Code
[test_projects/ios/EarlGreyExample](../test_projects/ios/FlankExample)


### FlankGameLoopExample

Simple SpriteKit app to test gameloop mode. It doesn't contain any test target, so test artifacts contains only IPA file.

#### Generate
Run: `flankScripts shell ops build_ios_gameloop_example`.

#### Source Code
[test_projects/ios/EarlGreyExample](../test_projects/ios/FlankGameLoopExample)

⚠️ NOTE: Generating IPA requires Apple distribution certificate therefore for now it's not possible to generate it without correct Apple Developer Account.
`build_ios_gameloop_example` is excluded when building all iOS artifacts:
```bash
update_test_artifacts ios
```

### FlankTestPlansExample

iOS project with XCTestPlans. Contains `AllTests` test plan. Generated .xctestrun is using V2 format. More details about test plans: [docs/feature/ios_test_plans.md](feature/ios_test_plans.md)

#### Generate
Run: `flankScripts shell ops build_ios_testplans_example`.

#### Source Code
[test_projects/ios/EarlGreyExample](../test_projects/ios/FlankTestPlansExample)
1 change: 1 addition & 0 deletions flank-scripts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Package Files #
flankScripts.jar
flank-scripts.jar
*.war
*.nar
*.ear
Expand Down
24 changes: 12 additions & 12 deletions flank-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,27 +209,27 @@ Run ftl locally ios app
Contains tasks related to building sample apps with tests.
These tasks are :
- `go` Build go app with tests
- `ios` Build ios app with tests
- `build_earl_grey_example` Build ios earl grey example app with tests
- `build_ios_gameloop_example` Build ios game loop example app
- `build_ios_testplans_example` Build ios test plans example app
- `build_flank_example` Build ios flank example app with tests
- `ios` Build all ios tests artifacts
- `android` Build android apks with tests

##### `go`
Build go app with tests

##### `build_earl_grey_example`
Build ios earl grey example app with tests

| Option | Short option | Description |
|------------|--------------|--------------------------|
| --generate | -g | Make build |
| --copy | -c | Copy output files to tmp |
Build ios [Earlgrey example](../docs/test_artifacts.md#earlgreyexample) app and copy output to the test artifacts directory

##### `build_flank_example`
Build ios flank example app with tests
Build ios [Flank example](../docs/test_artifacts.md#flankexample) app and copy output to the test artifacts directory

| Option | Short option | Description |
|------------|--------------|--------------------------|
| --generate | -g | Make build |
| --copy | -c | Copy output files to tmp |
##### `build_ios_gameloop_example`
Build ios [Game loop example](../docs/test_artifacts.md#flankgameloopexample) app and copy .IPA to the test artifacts directory

##### `build_ios_testplans_example`
Build ios [Test plans example](../docs/test_artifacts.md#flanktestplansexample) app and copy output to the test artifacts directory

##### `android`
Build android apks with tests
Expand Down
2 changes: 1 addition & 1 deletion flank-scripts/bash/buildFlankScripts.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ SET FLANK_SCRIPTS=%DIR%\..
SET GRADLE_EXECUTABLE_PATH=%FLANK_SCRIPTS%\..

CALL %GRADLE_EXECUTABLE_PATH%\gradlew.bat flank-scripts:clean flank-scripts:assemble flank-scripts:shadowJar
copy %FLANK_SCRIPTS%\build\libs\flankScripts.jar %DIR%\flankScripts.jar
copy %FLANK_SCRIPTS%\build\libs\flank-scripts.jar %DIR%\flank-scripts.jar
2 changes: 1 addition & 1 deletion flank-scripts/bash/buildFlankScripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ DIR=`dirname "$BASH_SOURCE"`
FLANK_SCRIPTS="$DIR/.."

"$FLANK_SCRIPTS/../gradlew" :flank-scripts:clean :flank-scripts:assemble :flank-scripts:shadowJar
cp "$FLANK_SCRIPTS"/build/libs/flankScripts.jar "$DIR/flankScripts.jar"
cp "$FLANK_SCRIPTS"/build/libs/flank-scripts.jar "$DIR/flank-scripts.jar"
2 changes: 1 addition & 1 deletion flank-scripts/bash/flankScripts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

dir=$(dirname "$BASH_SOURCE")
scriptsJar="$dir/flankScripts.jar"
scriptsJar="$dir/flank-scripts.jar"

if [ ! -f "$scriptsJar" ]; then
"$dir/buildFlankScripts.sh"
Expand Down
6 changes: 3 additions & 3 deletions flank-scripts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ shadowJar.apply {
}
}
// <breaking change>.<feature added>.<fix/minor change>
version = "1.0.0"
version = "1.1.0"
group = "com.github.flank"

application {
Expand Down Expand Up @@ -146,13 +146,13 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> { kotlinOptions.
val prepareJar by tasks.registering(Copy::class) {
dependsOn("shadowJar")
from("$buildDir/libs")
include("flankScripts.jar")
include("flank-scripts.jar")
into("$projectDir/bash")
}

tasks.register("download") {
val sourceUrl = "https://dl.bintray.com/flank/maven/com/github/flank/$artifactID/$version/$artifactID-$version.jar"
val destinationFile = Paths.get("bash", "flankScripts.jar").toFile()
val destinationFile = Paths.get("bash", "flank-scripts.jar").toFile()
ant.invokeMethod("get", mapOf("src" to sourceUrl, "dest" to destinationFile))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ package flank.scripts.shell.ios
import com.github.ajalt.clikt.core.CliktCommand
import flank.scripts.shell.utils.currentPath
import flank.scripts.shell.utils.failIfWindows
import flank.scripts.shell.utils.iOSTestProjectsPath
import flank.scripts.shell.utils.pipe
import flank.scripts.utils.archive
import flank.scripts.utils.downloadXcPrettyIfNeeded
import flank.scripts.utils.installPodsIfNeeded
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
Expand All @@ -22,26 +24,36 @@ object BuildExampleCommand : CliktCommand(name = "iosBuildExample", help = "Buil
}

private fun buildExample() {
val dataPath: Path = Paths.get(currentPath.toString(), "dd_tmp").apply {
val projectPath: Path = Paths.get(iOSTestProjectsPath, EARLGREY_EXAMPLE)
val buildPath: Path = Paths.get(projectPath.toString(), "build").apply {
toFile().deleteRecursively()
}

val xcodeCommandSwiftTests = createIosBuildCommand(
dataPath.toString(),
"./EarlGreyExample.xcworkspace",
"EarlGreyExampleSwiftTests"
val xcodeCommandSwiftTests = createXcodeBuildForTestingCommand(
buildDir = buildPath.toString(),
scheme = "EarlGreyExampleSwiftTests",
workspace = Paths.get(projectPath.toString(), "EarlGreyExample.xcworkspace").toString(),
useLegacyBuildSystem = true
)

installPodsIfNeeded(path = projectPath)
xcodeCommandSwiftTests pipe "xcpretty"

val xcodeCommandTests = createIosBuildCommand(dataPath.toString(), "./EarlGreyExample.xcworkspace", "EarlGreyExampleTests")
val xcodeCommandTests = createXcodeBuildForTestingCommand(
buildDir = buildPath.toString(),
scheme = "EarlGreyExampleTests",
workspace = Paths.get(projectPath.toString(), "EarlGreyExample.xcworkspace").toString(),
useLegacyBuildSystem = true
)

xcodeCommandTests pipe "xcpretty"

copyExampleOutputFiles(dataPath.toString())
copyExampleOutputFiles(buildPath.toString())
}

private fun copyExampleOutputFiles(dataPath: String) {
private fun copyExampleOutputFiles(buildPath: String) {
val archiveFileName = "earlgrey_example.zip"
val buildProductPath = Paths.get(dataPath, "Build", "Products")
val buildProductPath = Paths.get(buildPath, "Build", "Products")

Files.walk(Paths.get(""))
.filter { it.fileName.toString().endsWith("-iphoneos") || it.fileName.toString().endsWith(".xctestrun") }
Expand All @@ -55,3 +67,5 @@ private fun copyExampleOutputFiles(dataPath: String) {
StandardCopyOption.REPLACE_EXISTING
)
}

private const val EARLGREY_EXAMPLE = "EarlGreyExample"
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ private fun buildFtl() {
val dataPath = Paths.get("", "dd_tmp").apply {
toFile().deleteRecursively()
}.toString()
val xcodeCommand = createIosBuildCommand(dataPath, "./EarlGreyExample.xcworkspace", "\"EarlGreyExampleSwiftTests\"")
val xcodeCommand = createXcodeBuildForTestingCommand(
buildDir = dataPath,
scheme = "\"EarlGreyExampleSwiftTests\"",
useLegacyBuildSystem = true
)

xcodeCommand pipe "xcpretty"
copyFtlOutputFiles(dataPath)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
package flank.scripts.shell.ios

fun createIosBuildCommand(buildDir: String, workspace: String, scheme: String, project: String = "") =
fun createXcodeBuildForTestingCommand(
buildDir: String,
scheme: String,
project: String = "",
workspace: String = "",
useLegacyBuildSystem: Boolean
) =
"xcodebuild build-for-testing" +
" -allowProvisioningUpdates" +
(if (workspace.isBlank()) "" else " -workspace $workspace") +
(if (project.isBlank()) "" else " -project $project") +
" -scheme $scheme" +
(if (useLegacyBuildSystem) " -UseModernBuildSystem=NO" else "") +
" -derivedDataPath $buildDir" +
" -sdk iphoneos"

fun createXcodeArchiveCommand(
archivePath: String,
scheme: String,
project: String = "",
workspace: String = ""
) =
"xcodebuild" +
" -allowProvisioningUpdates" +
(if (workspace.isBlank()) "" else " -workspace $workspace") +
(if (project.isBlank()) "" else " -project $project") +
" -scheme $scheme" +
" archive" +
" -archivePath $archivePath"

fun createXcodeExportArchiveCommand(
archivePath: String,
exportOptionsPlistPath: String,
exportPath: String = ""
) =
"xcodebuild -exportArchive" +
" -allowProvisioningUpdates" +
" -archivePath $archivePath" +
" -exportOptionsPlist $exportOptionsPlistPath" +
" -exportPath $exportPath"
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import flank.scripts.shell.ops.EARL_GREY_EXAMPLE
import flank.scripts.shell.utils.failIfWindows
import flank.scripts.shell.utils.iOSTestProjectsPath
import flank.scripts.utils.downloadCocoaPodsIfNeeded
import flank.scripts.utils.installPods
import flank.scripts.utils.installPodsIfNeeded
import java.nio.file.Paths

object SetupIosEnvCommand : CliktCommand(name = "setup_ios_env", help = "Build ios app with tests") {
override fun run() {
failIfWindows()
downloadCocoaPodsIfNeeded()
installPods(Paths.get(iOSTestProjectsPath, EARL_GREY_EXAMPLE))
installPodsIfNeeded(Paths.get(iOSTestProjectsPath, EARL_GREY_EXAMPLE))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ object BuildEarlGreyExampleCommand : CliktCommand(name = "build_earl_grey_exampl
),
useWorkspace = true,
generate = generate ?: true,
copy = copy ?: true
).generateIos()
copy = copy ?: true,
copyXCTestFiles = copy ?: true,
useLegacyBuildSystem = true
).generateIosTestArtifacts()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object BuildFlankExampleCommand : CliktCommand(name = "build_flank_example", hel
useWorkspace = false,
generate = generate ?: true,
copy = copy ?: true
).generateIos()
).generateIosTestArtifacts()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package flank.scripts.shell.ops

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import flank.scripts.shell.utils.failIfWindows
import flank.scripts.shell.utils.iOSTestProjectsPath
import java.nio.file.Paths

object BuildGameLoopExampleCommand : CliktCommand(
name = "build_ios_gameloop_example",
help = "Build ios game loop example app"
) {

private val generate: Boolean? by option(help = "Make build").flag("-g", default = true)

private val copy: Boolean? by option(help = "Copy output files to tmp").flag("-c", default = true)

override fun run() {
failIfWindows()

IosBuildConfiguration(
projectPath = Paths.get(iOSTestProjectsPath, FLANK_GAME_LOOP_EXAMPLE).toString(),
projectName = FLANK_GAME_LOOP_EXAMPLE,
buildConfigurations = listOf(
IosTestBuildConfiguration(FLANK_GAME_LOOP_EXAMPLE, "tests"),
),
useWorkspace = false,
generate = generate ?: true,
copy = copy ?: true
).generateIPA()
}
}

private const val FLANK_GAME_LOOP_EXAMPLE = "FlankGameLoopExample"
Loading

0 comments on commit 3de1718

Please sign in to comment.