Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 5d/graphql-filter-sup…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
5d committed Jul 30, 2024
2 parents 5d7c180 + 2d3b505 commit ec12db9
Show file tree
Hide file tree
Showing 602 changed files with 234,710 additions and 5,951 deletions.
5 changes: 4 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
coverage:
codecov:
branch: main

coverage:
status:
patch: off
project:
default:
threshold: 1%
13 changes: 12 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
* @aws-amplify/amplify-ios
# Amplify iOS / Swift team has general approval permissions.
* @aws-amplify/amplify-ios

# Changes to this file requires admin approval.
/.github/CODEOWNERS @aws-amplify/amplify-ios-admins

# Changes to Xcode / OS runtime versions run in CI/CD requires admin approval.
/.github/composite_actions/get_platform_parameters/action.yml @aws-amplify/amplify-ios-admins

# Changes to files in the api-dump or api-dump-test folder require admin approval.
api-dump/* @aws-amplify/amplify-ios-admins
api-dump-test/* @aws-amplify/amplify-ios-admins
57 changes: 40 additions & 17 deletions .github/composite_actions/get_platform_parameters/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ outputs:
destination:
description: "The destination associated with the given platform and Xcode version"
value: ${{ steps.get-destination.outputs.destination }}
device:
description: "The device name used in the destination"
value: ${{ steps.get-destination.outputs.device }}
sdk:
description: "The SDK associated with the given platform"
value: ${{ steps.get-sdk.outputs.sdk }}
Expand All @@ -38,8 +41,8 @@ runs:

- id: get-xcode-version
run: |
LATEST_XCODE_VERSION=14.3.1
MINIMUM_XCODE_VERSION=14.0.1
LATEST_XCODE_VERSION=15.3.0
MINIMUM_XCODE_VERSION=15.0.1
INPUT_XCODE_VERSION=${{ inputs.xcode_version }}
Expand All @@ -61,23 +64,42 @@ runs:
INPUT_DESTINATION='${{ inputs.destination }}'
INPUT_XCODE_VERSION=${{ inputs.xcode_version }}
DESTINATION_MAPPING='{
"minimum": {
"iOS": "platform=iOS Simulator,name=iPhone 14,OS=16.0",
"tvOS": "platform=tvOS Simulator,name=Apple TV 4K (2nd generation),OS=16.0",
"watchOS": "platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=9.0",
"macOS": "platform=macOS,arch=x86_64"
},
"latest": {
"iOS": "platform=iOS Simulator,name=iPhone 14,OS=16.4",
"tvOS": "platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=16.4",
"watchOS": "platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=9.4",
"macOS": "platform=macOS,arch=x86_64"
}
}'
case $INPUT_PLATFORM/$INPUT_XCODE_VERSION in
iOS/latest)
DEVICE="iPhone 15"
OS_VERSION="17.4"
;;
iOS/*)
DEVICE="iPhone 14"
OS_VERSION="17.0.1"
;;
tvOS/latest)
DEVICE="Apple TV 4K (3rd generation)"
OS_VERSION="17.4"
;;
tvOS/*)
DEVICE="Apple TV 4K (3rd generation)"
OS_VERSION="17.0"
;;
watchOS/latest)
DEVICE="Apple Watch Series 9 (45mm)"
OS_VERSION="10.4"
;;
watchOS/*)
DEVICE="Apple Watch Series 8 (45mm)"
OS_VERSION="10.0"
;;
esac
DESTINATION_MAPPING="{
\"iOS\": \"platform=iOS Simulator,name=$DEVICE,OS=$OS_VERSION\",
\"tvOS\": \"platform=tvOS Simulator,name=$DEVICE,OS=$OS_VERSION\",
\"watchOS\": \"platform=watchOS Simulator,name=$DEVICE,OS=$OS_VERSION\",
\"macOS\": \"platform=macOS,arch=arm64\"
}"
if [ -z "$INPUT_DESTINATION" ]; then
DESTINATION=$(echo $DESTINATION_MAPPING | jq -r ".\"$INPUT_XCODE_VERSION\".$INPUT_PLATFORM")
DESTINATION=$(echo $DESTINATION_MAPPING | jq -r ".$INPUT_PLATFORM")
else
DESTINATION=$INPUT_DESTINATION
fi
Expand All @@ -87,6 +109,7 @@ runs:
exit 1
fi
echo "destination=$DESTINATION" >> $GITHUB_OUTPUT
echo "device=$DEVICE" >> $GITHUB_OUTPUT
shell: bash

- id: get-sdk
Expand Down
223 changes: 223 additions & 0 deletions .github/workflows/api-breaking-changes-detection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
name: Public Interface Breakage Detection

on:
pull_request:

permissions:
contents: write
pull-requests: write

jobs:
build-and-check-api-breakage:
name: Build and Check API Breakage
runs-on: macos-latest

steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1
with:
ref: ${{ github.head_ref }} # Checkout the PR branch
fetch-depth: 1

- name: Fetch the branchs
run: |
git fetch origin ${{ github.sha }}
- name: Setup and Run Swift API Diff
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Define the list of exceptions to filter out
exceptions=(
'has been added as a new enum case$'
'is now with @_spi$'
)
# Define the mandatory patterns to filter out
mandatory_patterns=(
'^/\*'
'^$'
)
# Function to apply patterns with grep
apply_patterns() {
local input="$1"
local output="$input"
# Apply mandatory patterns
for pattern in "${mandatory_patterns[@]}"; do
output=$(echo "$output" | grep -v "$pattern")
done
# Apply exceptions
for exception in "${exceptions[@]}"; do
output=$(echo "$output" | grep -v "$exception")
done
echo "$output"
}
echo "Swift version: $(swift --version)"
echo "Swift package manager version: $(swift package --version)"
swift package resolve
# Ensure we are in the correct directory
cd $GITHUB_WORKSPACE
# Run swift-api-diff commands here directly
NEW_API_DIR=$(mktemp -d)
OLD_API_DIR=$(mktemp -d)
SDK_PATH=$(xcrun --show-sdk-path)
# Get all library module names
# Moduels with aws-crt-swift as dependency are not listed due to swift-api-digester's issue with analyzing C dependencies
modules=$(swift package dump-package | jq -r '.products | map(select(.name == "Amplify" or .name == "CoreMLPredictionsPlugin" or .name == "AWSDataStorePlugin" or .name == "AWSPluginsCore")) | map(.name) | .[]')
echo "Modules: $modules"
echo "Fetching old version..."
git fetch origin ${{ github.event.pull_request.base.sha }}
git checkout ${{ github.event.pull_request.base.sha }}
built=false
for module in $modules; do
# If file doesn't exits in the old directory
if [ ! -f api-dump/${module}.json ]; then
echo "Old API file does not exist in the base branch. Generating it..."
# Check if the project has been built
if ! $built; then
echo "Building project..."
swift build > /dev/null 2>&1 || { echo "Failed to build project"; exit 1; }
built=true
fi
# Generate the API file using api-digester
swift api-digester -sdk "$SDK_PATH" -dump-sdk -module "$module" -o "$OLD_API_DIR/${module}.json" -I .build/debug || { echo "Failed to dump new SDK for module $module"; exit 1; }
else
# Use the api-dump/${module}.json file from the base branch directly
cp "api-dump/${module}.json" "$OLD_API_DIR/${module}.json"
fi
done
echo "Fetching new version..."
git checkout ${{ github.sha }}
git log -1 # Print the commit info for debugging
swift build> /dev/null 2>&1 || { echo "Failed to build new version"; exit 1; }
for module in $modules; do
swift api-digester -sdk "$SDK_PATH" -dump-sdk -module "$module" -o "$NEW_API_DIR/${module}.json" -I .build/debug || { echo "Failed to dump new SDK for module $module"; exit 1; }
done
# Compare APIs for each module and capture the output
api_diff_output=""
for module in $modules; do
swift api-digester -sdk "$SDK_PATH" -diagnose-sdk --input-paths "$OLD_API_DIR/${module}.json" --input-paths "$NEW_API_DIR/${module}.json" >> "api-diff-report-${module}.txt" 2>&1
module_diff_output=$(apply_patterns "$(cat "api-diff-report-${module}.txt")")
if [ -n "$module_diff_output" ]; then
api_diff_output="${api_diff_output}\n**Module: ${module}**\n${module_diff_output}\n"
# Check if there are lines containing "has been renamed to Func"
if echo "$module_diff_output" | grep -q 'has been renamed to Func'; then
# Capture the line containing "has been renamed to Func"
renamed_line=$(echo "$module_diff_output" | grep 'has been renamed to Func')
# Append a message to the module_diff_output
api_diff_output="${api_diff_output}👉🏻 _Note: If you're just adding optional parameters to existing methods, neglect the line:_\n_${renamed_line}_\n"
fi
fi
done
echo "API_DIFF_OUTPUT<<EOF" >> $GITHUB_ENV
if [ -n "$api_diff_output" ]; then
echo "### 💔 Public API Breaking Change detected:" >> $GITHUB_ENV
echo -e "$api_diff_output" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
else
echo "### ✅ No Public API Breaking Change detected" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
fi
# Checkout to the branch associated with the pull request
git stash --include-untracked
git checkout ${{ github.head_ref }}
if [ ! -d "api-dump" ]; then
echo "api-dump folder does not exist. Creating it..."
mkdir -p "api-dump"
fi
# Update the api-dump folder of the new version by making a commit if there are changes
for module in $modules; do
if [ ! -f api-dump/${module}.json ]; then
echo "API file does not exist in api-dump folder. Creating it..."
echo "{}" > "api-dump/${module}.json"
fi
if ! diff "$NEW_API_DIR/${module}.json" "api-dump/${module}.json" > /dev/null; then
echo "Updating API Dumps..."
mv "$NEW_API_DIR/${module}.json" "api-dump/${module}.json"
fi
done
git config --global user.name "aws-amplify-ops"
git config --global user.email "aws-amplify@amazon.com"
git add api-dump/*.json
if ! git diff --cached --quiet --exit-code; then
# Get the file names that have changes
changed_files=$(git diff --cached --name-only)
push_changes=false
for file in $changed_files; do
if [[ $file == api-dump/* ]]; then
# Get the number of lines in the file
total_lines=$(wc -l < "$file")
# Get the line numbers of the changes
changed_lines=$(git diff --cached -U0 "$file" | grep -o '@@ [^ ]* [^ ]* @@' | awk '{print $3}' | cut -d ',' -f1 | sed 's/[^0-9]//g')
echo "Changed lines in $file: $changed_lines"
# Check if any change is not within the last 10 lines
for line in $changed_lines; do
if [ "$line" -le "$((total_lines - 10))" ]; then
push_changes=true
break
fi
done
# If any file should be pushed, break out of the loop
if [ "$push_changes" = true ]; then
break
fi
fi
done
if [ "$push_changes" = true ]; then
git commit -m "Update API dumps for new version"
git push origin HEAD:${{ github.head_ref }}
else
echo "No changes to commit in the api-dump folder."
fi
else
echo "No changes to commit in the api-dump folder."
fi
git stash pop || true
- name: Comment on PR with API Diff
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const apiDiffOutput = process.env.API_DIFF_OUTPUT;
const issueNumber = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
if (apiDiffOutput && apiDiffOutput.trim().length > 0) {
github.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: issueNumber,
body: `## API Breakage Report\n${apiDiffOutput}\n`
});
} else {
console.log("No API diff output found.");
}
39 changes: 39 additions & 0 deletions .github/workflows/api_digester_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Swift API Digester Functionality Check

on:
schedule:
- cron: '0 15 * * *' # This will run the action every day at 3:00 pm UTC (8:00 am PDT)
workflow_dispatch: # Allows manual triggering

jobs:
check-swift-api-digester:
runs-on: macos-latest

steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1

- name: Check API Digester
shell: bash
env:
WEBHOOK_URL: ${{ secrets.SLACK_API_CHECKER_WEBHOOK_URL }}
run: |
TEMP_DIR=$(mktemp -d)
echo "Temporary directory created at $TEMP_DIR"
SDK_PATH=$(xcrun --sdk macosx --show-sdk-path)
echo "SDK Path: $SDK_PATH"
# Run swift-api-digester
swift api-digester -sdk "$SDK_PATH" -diagnose-sdk --input-paths api-dump-test/A.json --input-paths api-dump-test/B.json >> "$TEMP_DIR/api-digester-output.txt" 2>&1
# Display the output
cat "$TEMP_DIR/api-digester-output.txt"
if diff "$TEMP_DIR/api-digester-output.txt" api-dump-test/expected-result.txt; then
echo "The output matches the expected result."
else
echo "The output does not match the expected result."
WORKFLOW_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
echo "$WORKFLOW_URL" | xargs -I {} curl -s POST "$WEBHOOK_URL" -H "Content-Type:application/json" --data '{"WORKFLOW_URL":"{}"}'
exit 1
fi
3 changes: 2 additions & 1 deletion .github/workflows/build_amplify_swift_platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ jobs:
- platform: ${{ github.event.inputs.macos == 'false' && 'macOS' || 'None' }}
- platform: ${{ github.event.inputs.tvos == 'false' && 'tvOS' || 'None' }}
- platform: ${{ github.event.inputs.watchos == 'false' && 'watchOS' || 'None' }}
uses: ./.github/workflows/build_amplify_swift.yml
uses: ./.github/workflows/build_scheme.yml
with:
scheme: Amplify-Package
platform: ${{ matrix.platform }}

confirm-pass:
Expand Down
Loading

0 comments on commit ec12db9

Please sign in to comment.