Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ios test artifacts cleanup #1345 #1350

Merged
merged 28 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e5bcb04
Added sample application for ios game loop
zuziaka Nov 17, 2020
0ec66f3
Removed unused test targets from example project
zuziaka Nov 17, 2020
9746e08
Flank scripts for generating test artifacts
zuziaka Nov 19, 2020
838f3fe
Moved all iOS "floating" artifacts under test_artifacts/ios
zuziaka Nov 24, 2020
d7487be
Renamed FlankMultiTestTargetsExample to FlankTestPlansExample
zuziaka Nov 24, 2020
3d4dd3e
Removed old scripts and .ipa file
zuziaka Nov 25, 2020
0df0a27
Code formatting
zuziaka Nov 25, 2020
28f03aa
Added missing ios ops command
zuziaka Nov 25, 2020
a5fe18d
Code cleaning
zuziaka Nov 25, 2020
8fdce8f
Update flank-scripts/src/main/kotlin/flank/scripts/shell/ios/IosBuild…
zuziaka Nov 25, 2020
0a21782
Apply suggestions from code review
zuziaka Nov 25, 2020
d48d29c
Add Build dir to .gitignore & fix detect
jan-goral Nov 25, 2020
de5031e
Added documentation for iOS Test artifacts
zuziaka Nov 26, 2020
8d19481
Update test_artifacts.md
zuziaka Nov 26, 2020
8b7c214
Update flank-scripts/src/main/kotlin/flank/scripts/shell/ops/iOSOpsCo…
jan-goral Nov 26, 2020
4627880
Applied code reviews comments
zuziaka Nov 26, 2020
b40968b
Added support for Xcode's legacy build system in flank scripts
zuziaka Nov 27, 2020
f23dbdd
Updated default iOS version to 13.6
zuziaka Nov 30, 2020
aa94ce7
Added iOS 13.6 to mocked ios_catalog response
zuziaka Nov 30, 2020
e8fe771
Update README.md
zuziaka Nov 30, 2020
865b319
Code review fixes
zuziaka Nov 30, 2020
66e3775
Code review fixes
zuziaka Nov 30, 2020
adcfd78
Fixed typo in CocoaPods installation command
zuziaka Nov 30, 2020
8bdfb75
Update flank-scripts/src/main/kotlin/flank/scripts/shell/ops/BuildTes…
zuziaka Nov 30, 2020
20da711
Fixed gem installation
zuziaka Nov 30, 2020
7abe9dc
Bumped flank-scripts version to 1.1.0
zuziaka Dec 1, 2020
337a32c
Fixed typos in building flank scripts
zuziaka Dec 1, 2020
f49668e
Renamed flankScripts.jar to flank-scripts.jar
zuziaka Dec 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

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