A compile-time check to see if you've implemented everything required by the product team.
The following JSON is converted into swift sourcecode, which is then compile time checked to see if it's implemented in your code
{
"productAnalysis": {
"General": {
"Launch": {
"children": [{
"name": "launchName",
"value": "on_launch"
}]
},
"Quit": {
"children": [{
"name": "terminateName",
"value": "on_terminate"
}]
}
}
}
}
Generated Swift Code
protocol Analyzable {
var analysisKey: String { get }
}
enum AnalysisKeys {
enum General {
enum Quit {
public struct terminateName: Analyzable {
let analysisKey: String = "on_terminate"
}
}
enum Launch {
public struct launchName: Analyzable {
let analysisKey: String = "on_launch"
}
}
}
}
Your Code
@main
struct MyApp {
func main() {
// Nothing Implemented
}
}
When you compile, you get the following results:
⚠️ AnalysisKeys.General.Launch.launchName not implemented
⚠️ AnalysisKeys.General.Quit.terminateName not implemented
Add this Swift Package to your App:
.package(url: "https://github.com/nthState/ProductAnalysis", branch: "main")
Add the following line to a Build Phase Script
:
${BUILD_DIR%Build/*}SourcePackages/checkouts/ProductAnalysis/run
Add a ProductAnalysis.plist
to the root of your project
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>warningsAsErrors</key>
<false/>
<key>duplicatesAsErrors</key>
<false/>
<key>enableAnalysis</key>
<true/>
<key>accessToken</key>
<string>my_token</string>
<key>enableReportAnalysisResults</key>
<true/>
<key>enableGenerateSourceCode</key>
<true/>
<key>folderName</key>
<string>Analysis</string>
</dict>
</plist>
If you don't want to use a ProductAnalysis.plist
file, you can pass arguments to run
like so:
#${BUILD_DIR%Build/*}SourcePackages/checkouts/ProductAnalysis/run --folder-name "MyAnalysis" --enable-analysis --enable-generate-source-code
To install dependencies run the following script, it installs Xcode Command line tools, Commitizen, Pre commit & Swiftlint
./scripts/new_developer.sh
If you want to run unit tests, use the following script, this is also ran as a GitHub Action
swift test --enable-code-coverage
Then to get a code-coverage report (GitHub Action reports this too)
ARCH=$(uname -m)
/Library/Developer/CommandLineTools/usr/bin/llvm-cov \
report ".build/${ARCH}-apple-macosx/debug/ProductAnalysisPackageTests.xctest/Contents/MacOS/ProductAnalysisPackageTests" \
-instr-profile=".build/${ARCH}-apple-macosx/debug/codecov/default.profdata" \
-use-color
To view log events, open a new Terminal
window and run:
log stream --level debug --predicate 'subsystem == "com.productAnalysis"'
Useful/Interesting links
- Localisation
- AnalysisReporter
- Versioning - Send bundle version as a start
- Signed Commits only with GitHub Action
- Service Tests
- CLI Tests
- Self-hosted runner
- Add BDD Feature files
-
print("ProductAnalysis Finished")
fires before all results returned