Skip to content

chore: Update workstation 9.0 from main #16

chore: Update workstation 9.0 from main

chore: Update workstation 9.0 from main #16

Workflow file for this run

name: SDK Size Report
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
concurrency:
group: size-report-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
env:
XCODE_VERSION: "16.4"
COMMENT_IDENTIFIER: "<!-- sdk-size-report -->"
jobs:
measure-size:
runs-on: macOS-15
steps:
- name: Checkout PR branch
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
path: pr-branch
- name: Checkout target branch
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.base.sha || 'main' }}
path: base-branch
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_${{ env.XCODE_VERSION }}.app
- name: Build and measure target branch
id: base-size
working-directory: base-branch
continue-on-error: true
run: |
# Check if the size test apps and script exist on base branch
if [[ -d "Tests/SizeReport/SizeTestAppWithSDK" ]] && [[ -d "Tests/SizeReport/SizeTestApp" ]] && [[ -f "Tests/SizeReport/measure_size.sh" ]]; then
chmod +x Tests/SizeReport/measure_size.sh
RESULT=$(Tests/SizeReport/measure_size.sh --json 2>/dev/null)
if [[ $? -eq 0 ]] && [[ -n "$RESULT" ]]; then
echo "json=${RESULT}" >> $GITHUB_OUTPUT
# Extract SDK impact (delta between with-SDK and baseline)
SDK_IMPACT_KB=$(echo "$RESULT" | jq -r '.sdk_impact_kb')
SDK_EXECUTABLE_IMPACT=$(echo "$RESULT" | jq -r '.sdk_executable_impact_bytes')
XCFRAMEWORK_SIZE_KB=$(echo "$RESULT" | jq -r '.xcframework_size_kb // 0')
echo "sdk_impact_kb=${SDK_IMPACT_KB}" >> $GITHUB_OUTPUT
echo "sdk_executable_impact=${SDK_EXECUTABLE_IMPACT}" >> $GITHUB_OUTPUT
echo "xcframework_size_kb=${XCFRAMEWORK_SIZE_KB}" >> $GITHUB_OUTPUT
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "Build failed on base branch"
echo 'json={"sdk_impact_kb": 0, "sdk_executable_impact_bytes": 0, "xcframework_size_kb": 0}' >> $GITHUB_OUTPUT
echo "sdk_impact_kb=0" >> $GITHUB_OUTPUT
echo "sdk_executable_impact=0" >> $GITHUB_OUTPUT
echo "xcframework_size_kb=0" >> $GITHUB_OUTPUT
echo "exists=false" >> $GITHUB_OUTPUT
fi
else
echo "Size test app not found on base branch, this PR introduces it"
echo 'json={"sdk_impact_kb": 0, "sdk_executable_impact_bytes": 0, "xcframework_size_kb": 0}' >> $GITHUB_OUTPUT
echo "sdk_impact_kb=0" >> $GITHUB_OUTPUT
echo "sdk_executable_impact=0" >> $GITHUB_OUTPUT
echo "xcframework_size_kb=0" >> $GITHUB_OUTPUT
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Build and measure PR branch
id: pr-size
working-directory: pr-branch
run: |
chmod +x Tests/SizeReport/measure_size.sh
RESULT=$(Tests/SizeReport/measure_size.sh --json)
echo "json=${RESULT}" >> $GITHUB_OUTPUT
# Extract SDK impact (delta between with-SDK and baseline)
SDK_IMPACT_KB=$(echo "$RESULT" | jq -r '.sdk_impact_kb')
SDK_EXECUTABLE_IMPACT=$(echo "$RESULT" | jq -r '.sdk_executable_impact_bytes')
XCFRAMEWORK_SIZE_KB=$(echo "$RESULT" | jq -r '.xcframework_size_kb // 0')
echo "sdk_impact_kb=${SDK_IMPACT_KB}" >> $GITHUB_OUTPUT
echo "sdk_executable_impact=${SDK_EXECUTABLE_IMPACT}" >> $GITHUB_OUTPUT
echo "xcframework_size_kb=${XCFRAMEWORK_SIZE_KB}" >> $GITHUB_OUTPUT
- name: Calculate size delta
id: delta
run: |
BASE_SDK_IMPACT=${{ steps.base-size.outputs.sdk_impact_kb }}
PR_SDK_IMPACT=${{ steps.pr-size.outputs.sdk_impact_kb }}
BASE_EXECUTABLE_IMPACT=${{ steps.base-size.outputs.sdk_executable_impact }}
PR_EXECUTABLE_IMPACT=${{ steps.pr-size.outputs.sdk_executable_impact }}
BASE_XCFRAMEWORK=${{ steps.base-size.outputs.xcframework_size_kb }}
PR_XCFRAMEWORK=${{ steps.pr-size.outputs.xcframework_size_kb }}
BASE_EXISTS=${{ steps.base-size.outputs.exists }}
# Handle case where base branch doesn't have the test app
if [[ "$BASE_EXISTS" != "true" ]] || [[ "$BASE_SDK_IMPACT" == "0" ]]; then
echo "delta_kb=N/A" >> $GITHUB_OUTPUT
echo "delta_executable=N/A" >> $GITHUB_OUTPUT
echo "delta_xcframework=N/A" >> $GITHUB_OUTPUT
echo "delta_percent=N/A" >> $GITHUB_OUTPUT
echo "status=new" >> $GITHUB_OUTPUT
else
DELTA_KB=$((PR_SDK_IMPACT - BASE_SDK_IMPACT))
DELTA_EXECUTABLE=$((PR_EXECUTABLE_IMPACT - BASE_EXECUTABLE_IMPACT))
DELTA_XCFRAMEWORK=$((PR_XCFRAMEWORK - BASE_XCFRAMEWORK))
if [[ "$BASE_SDK_IMPACT" -gt 0 ]]; then
DELTA_PERCENT=$(awk "BEGIN {printf \"%.2f\", ($DELTA_KB / $BASE_SDK_IMPACT) * 100}")
else
DELTA_PERCENT="0.00"
fi
echo "delta_kb=${DELTA_KB}" >> $GITHUB_OUTPUT
echo "delta_executable=${DELTA_EXECUTABLE}" >> $GITHUB_OUTPUT
echo "delta_xcframework=${DELTA_XCFRAMEWORK}" >> $GITHUB_OUTPUT
echo "delta_percent=${DELTA_PERCENT}" >> $GITHUB_OUTPUT
# Determine status emoji
if [[ "$DELTA_KB" -gt 50 ]]; then
echo "status=increase" >> $GITHUB_OUTPUT
elif [[ "$DELTA_KB" -lt -50 ]]; then
echo "status=decrease" >> $GITHUB_OUTPUT
else
echo "status=neutral" >> $GITHUB_OUTPUT
fi
fi
- name: Format size for display
id: format
run: |
BASE_EXISTS=${{ steps.base-size.outputs.exists }}
# Format KB to human readable
format_size() {
local kb=$1
if [[ "$kb" == "0" || "$kb" == "N/A" ]]; then
echo "N/A"
elif [[ "$kb" -ge 1024 ]]; then
awk "BEGIN {printf \"%.2f MB\", $kb / 1024}"
else
echo "${kb} KB"
fi
}
format_bytes() {
local bytes=$1
if [[ "$bytes" == "0" || "$bytes" == "N/A" ]]; then
echo "N/A"
elif [[ "$bytes" -ge 1048576 ]]; then
awk "BEGIN {printf \"%.2f MB\", $bytes / 1048576}"
elif [[ "$bytes" -ge 1024 ]]; then
awk "BEGIN {printf \"%.2f KB\", $bytes / 1024}"
else
echo "${bytes} bytes"
fi
}
# Format SDK impact sizes - show N/A if base doesn't exist
if [[ "$BASE_EXISTS" == "true" ]]; then
echo "base_impact_formatted=$(format_size ${{ steps.base-size.outputs.sdk_impact_kb }})" >> $GITHUB_OUTPUT
echo "base_executable_formatted=$(format_bytes ${{ steps.base-size.outputs.sdk_executable_impact }})" >> $GITHUB_OUTPUT
echo "base_xcframework_formatted=$(format_size ${{ steps.base-size.outputs.xcframework_size_kb }})" >> $GITHUB_OUTPUT
else
echo "base_impact_formatted=N/A" >> $GITHUB_OUTPUT
echo "base_executable_formatted=N/A" >> $GITHUB_OUTPUT
echo "base_xcframework_formatted=N/A" >> $GITHUB_OUTPUT
fi
echo "pr_impact_formatted=$(format_size ${{ steps.pr-size.outputs.sdk_impact_kb }})" >> $GITHUB_OUTPUT
echo "pr_executable_formatted=$(format_bytes ${{ steps.pr-size.outputs.sdk_executable_impact }})" >> $GITHUB_OUTPUT
echo "pr_xcframework_formatted=$(format_size ${{ steps.pr-size.outputs.xcframework_size_kb }})" >> $GITHUB_OUTPUT
DELTA_KB="${{ steps.delta.outputs.delta_kb }}"
DELTA_EXECUTABLE="${{ steps.delta.outputs.delta_executable }}"
DELTA_XCFRAMEWORK="${{ steps.delta.outputs.delta_xcframework }}"
if [[ "$DELTA_KB" != "N/A" ]]; then
if [[ "$DELTA_KB" -ge 0 ]]; then
echo "delta_formatted=+$(format_size $DELTA_KB)" >> $GITHUB_OUTPUT
else
echo "delta_formatted=$(format_size $DELTA_KB)" >> $GITHUB_OUTPUT
fi
if [[ "$DELTA_EXECUTABLE" -ge 0 ]]; then
echo "delta_executable_formatted=+$(format_bytes $DELTA_EXECUTABLE)" >> $GITHUB_OUTPUT
else
echo "delta_executable_formatted=$(format_bytes $DELTA_EXECUTABLE)" >> $GITHUB_OUTPUT
fi
if [[ "$DELTA_XCFRAMEWORK" -ge 0 ]]; then
echo "delta_xcframework_formatted=+$(format_size $DELTA_XCFRAMEWORK)" >> $GITHUB_OUTPUT
else
echo "delta_xcframework_formatted=$(format_size $DELTA_XCFRAMEWORK)" >> $GITHUB_OUTPUT
fi
else
echo "delta_formatted=N/A (new baseline)" >> $GITHUB_OUTPUT
echo "delta_executable_formatted=N/A (new baseline)" >> $GITHUB_OUTPUT
echo "delta_xcframework_formatted=N/A (new baseline)" >> $GITHUB_OUTPUT
fi
- name: Generate size report
id: report
run: |
REPORT_FILE="${RUNNER_TEMP}/size-report.md"
# Determine status message
STATUS="${{ steps.delta.outputs.status }}"
case "$STATUS" in
increase) STATUS_MSG="⚠️ This change increases SDK size impact." ;;
decrease) STATUS_MSG="✅ This change decreases SDK size impact." ;;
neutral) STATUS_MSG="➡️ SDK size impact change is minimal." ;;
new) STATUS_MSG="ℹ️ Size test app not found on target branch. This is the new baseline." ;;
*) STATUS_MSG="" ;;
esac
# Generate the report
cat > "$REPORT_FILE" << EOF
${{ env.COMMENT_IDENTIFIER }}
## 📦 SDK Size Impact Report
Measures how much the SDK adds to an app's size (with-SDK minus without-SDK).
| Metric | Target Branch | This PR | Change |
|--------|---------------|---------|--------|
| App Bundle Impact | ${{ steps.format.outputs.base_impact_formatted }} | ${{ steps.format.outputs.pr_impact_formatted }} | ${{ steps.format.outputs.delta_formatted }} |
| Executable Impact | ${{ steps.format.outputs.base_executable_formatted }} | ${{ steps.format.outputs.pr_executable_formatted }} | ${{ steps.format.outputs.delta_executable_formatted }} |
| XCFramework Size | ${{ steps.format.outputs.base_xcframework_formatted }} | ${{ steps.format.outputs.pr_xcframework_formatted }} | ${{ steps.format.outputs.delta_xcframework_formatted }} |
${STATUS_MSG}
<details>
<summary>Raw measurements</summary>
**Target branch (${{ github.base_ref || 'main' }}):**
\`\`\`json
${{ steps.base-size.outputs.json }}
\`\`\`
**This PR:**
\`\`\`json
${{ steps.pr-size.outputs.json }}
\`\`\`
</details>
EOF
# Remove leading whitespace from heredoc
sed -i.bak 's/^ //' "$REPORT_FILE" && rm -f "${REPORT_FILE}.bak"
echo "path=${REPORT_FILE}" >> $GITHUB_OUTPUT
- name: Find Comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: ${{ env.COMMENT_IDENTIFIER }}
- name: Create or update PR comment
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body-path: ${{ steps.report.outputs.path }}
- name: Write job summary
run: cat "${{ steps.report.outputs.path }}" >> $GITHUB_STEP_SUMMARY