Skip to content

Commit

Permalink
ci: add support for ConfidenceProvider in API diff
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklasl committed Jul 4, 2024
1 parent 0a265bc commit f49e1c0
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:

jobs:
API-diff:
strategy:
matrix:
module: ["ConfidenceProvider", "Confidence"]
runs-on: macOS-latest
steps:
- name: install sourcekitten
Expand All @@ -20,7 +23,7 @@ jobs:
with:
ssh-private-key: ${{ secrets.SDK_REPO_PRIVATE_KEY }}
- name: Run public API diff
run: scripts/api_diff.sh
run: scripts/api_diff.sh ${{ matrix.module }}

Tests:
runs-on: macOS-latest
Expand Down
43 changes: 43 additions & 0 deletions api/ConfidenceProvider_public_api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[
{
"className": "ConfidenceFeatureProvider",
"apiFunctions": [
{
"name": "init(confidence:initializationStrategy:)",
"declaration": "public convenience init(confidence: Confidence, initializationStrategy: InitializationStrategy = .fetchAndActivate)"
},
{
"name": "initialize(initialContext:)",
"declaration": "public func initialize(initialContext: OpenFeature.EvaluationContext?)"
},
{
"name": "onContextSet(oldContext:newContext:)",
"declaration": "public func onContextSet(\n oldContext: OpenFeature.EvaluationContext?,\n newContext: OpenFeature.EvaluationContext\n)"
},
{
"name": "getBooleanEvaluation(key:defaultValue:context:)",
"declaration": "public func getBooleanEvaluation(key: String, defaultValue: Bool, context: EvaluationContext?) throws\n-> OpenFeature.ProviderEvaluation<Bool>"
},
{
"name": "getStringEvaluation(key:defaultValue:context:)",
"declaration": "public func getStringEvaluation(key: String, defaultValue: String, context: EvaluationContext?) throws\n-> OpenFeature.ProviderEvaluation<String>"
},
{
"name": "getIntegerEvaluation(key:defaultValue:context:)",
"declaration": "public func getIntegerEvaluation(key: String, defaultValue: Int64, context: EvaluationContext?) throws\n-> OpenFeature.ProviderEvaluation<Int64>"
},
{
"name": "getDoubleEvaluation(key:defaultValue:context:)",
"declaration": "public func getDoubleEvaluation(key: String, defaultValue: Double, context: EvaluationContext?) throws\n-> OpenFeature.ProviderEvaluation<Double>"
},
{
"name": "getObjectEvaluation(key:defaultValue:context:)",
"declaration": "public func getObjectEvaluation(key: String, defaultValue: OpenFeature.Value, context: EvaluationContext?)\nthrows -> OpenFeature.ProviderEvaluation<OpenFeature.Value>"
},
{
"name": "observe()",
"declaration": "public func observe() -> AnyPublisher<OpenFeature.ProviderEvent, Never>"
}
]
}
]
File renamed without changes.
17 changes: 12 additions & 5 deletions scripts/api_diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@ set -e
script_dir=$(dirname $0)
root_dir="$script_dir/../"

# exit if param is not supplied
if [ -z "$1" ]; then
echo "Please provide the module name as a parameter."
exit 1
fi
MODULE=$1

# Generate the json file with:
sourcekitten doc --module-name Confidence -- -scheme Confidence-Package -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.2' > $script_dir/raw_api.json
sourcekitten doc --module-name ${MODULE} -- -scheme Confidence-Package -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.2' > $script_dir/${MODULE}_raw_api.json

# Extract the public API from the raw api json file
python3 $script_dir/extract_public_funcs.py $script_dir/raw_api.json $script_dir/current_public_api.json
python3 $script_dir/extract_public_funcs.py $script_dir/${MODULE}_raw_api.json $script_dir/${MODULE}_current_public_api.json

# Clean up the raw api json file
rm $script_dir/raw_api.json
rm $script_dir/${MODULE}_raw_api.json

# Compare the public API with the previous public API and exit with 1 if there are changes
echo "Comparing genereated public API with previous public API"
set +e
git diff --no-index --exit-code $root_dir/api/public_api.json $script_dir/current_public_api.json
git diff --no-index --exit-code $root_dir/api/${MODULE}_public_api.json $script_dir/${MODULE}_current_public_api.json
# Capture the exit code of the git diff command
diff_exit_code=$?
set -e
Expand All @@ -36,7 +43,7 @@ If the changes are unintended, please investigate the changes and update the sou
fi

# Clean up the current public api json file
rm $script_dir/current_public_api.json
rm $script_dir/${MODULE}_current_public_api.json

# Exit with the diff's exit code to maintain the intended behavior
exit $diff_exit_code
13 changes: 10 additions & 3 deletions scripts/generate_public_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ set -e
script_dir=$(dirname $0)
root_dir="$script_dir/../"

# exit if param is not supplied
if [ -z "$1" ]; then
echo "Please provide the module name as a parameter."
exit 1
fi
MODULE=$1

# Generate the json file with:
sourcekitten doc --module-name Confidence -- -scheme Confidence-Package -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.2' > $script_dir/raw_api.json
sourcekitten doc --module-name ${MODULE} -- -scheme Confidence-Package -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.2' > $script_dir/${MODULE}_raw_api.json

# Extract the public API from the raw api json file
python3 $script_dir/extract_public_funcs.py $script_dir/raw_api.json $root_dir/api/public_api.json
python3 $script_dir/extract_public_funcs.py $script_dir/${MODULE}_raw_api.json $root_dir/api/${MODULE}_public_api.json

# Clean up the raw api json file
rm $script_dir/raw_api.json
rm $script_dir/${MODULE}_raw_api.json

0 comments on commit f49e1c0

Please sign in to comment.