Repository navigation
Expand file tree
/
Copy pathswift-package-breaking-changes.yml
More file actions
203 lines (177 loc) · 7.23 KB
/
Copy pathswift-package-breaking-changes.yml
File metadata and controls
203 lines (177 loc) · 7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#
# This source file is part of the Schmiedmayer Lab open-source organization
#
# SPDX-FileCopyrightText: 2026 Schmiedmayer Lab and the project authors (see CONTRIBUTORS.md)
#
# SPDX-License-Identifier: MIT
#
name: Diagnose Swift Package API Breaking Changes
on:
workflow_call:
inputs:
library_products:
description: |
JSON array of library product names, e.g. '["ExamplePackage"]'.
required: true
type: string
platform_name:
description: |
Platform name for breaking changes analysis, e.g. "ios".
required: true
type: string
platform_version:
description: |
Platform version string, e.g. "18.0".
required: false
type: string
default: ""
branch:
description: |
The name of the branch to compare against.
required: false
type: string
default: main
runsonlabels:
description: |
JSON-based collection of labels indicating which type of GitHub runner should be chosen.
required: false
type: string
default: '["macOS", "self-hosted"]'
permissions:
contents: read
issues: write
pull-requests: write
jobs:
diagnose:
name: Diagnose Swift Package API Breaking Changes
runs-on: ${{ fromJson(inputs.runsonlabels) }}
steps:
- uses: actions/checkout@v7
- name: Fetch base branch
run: git fetch origin "${{ inputs.branch }}:${{ inputs.branch }}"
- name: Diagnose API breaking changes
id: diagnose
shell: bash
run: |
set -euo pipefail
summary="$RUNNER_TEMP/api-breakages.md"
has_breaking_changes=false
status=0
{
echo "## API breaking changes"
echo
} > "$summary"
library_products=()
while IFS= read -r product; do
[[ -n "$product" ]] || continue
library_products+=("$product")
done < <(echo '${{ inputs.library_products }}' | jq -r '.[]')
if [[ "${#library_products[@]}" -eq 0 ]]; then
echo "No library products found, skipping breaking changes check"
exit 0
fi
platform_name="${{ inputs.platform_name }}"
platform_version="${{ inputs.platform_version }}"
swift_package_args=()
case "$platform_name" in
macos) sdk_name=""; triple="" ;;
ios) sdk_name="iphonesimulator"; triple="arm64-apple-ios${platform_version}-simulator" ;;
maccatalyst) sdk_name="macosx"; triple="arm64-apple-ios${platform_version}-macabi" ;;
visionos) sdk_name="xrsimulator"; triple="arm64-apple-xros${platform_version}-simulator" ;;
tvos) sdk_name="appletvsimulator"; triple="arm64-apple-tvos${platform_version}-simulator" ;;
watchos) sdk_name="watchsimulator"; triple="arm64-apple-watchos${platform_version}-simulator" ;;
*)
echo "Unsupported platform selection: $platform_name"
exit 1
;;
esac
if [[ -n "$triple" ]]; then
# swift package does not forward --triple to swift-api-digester, which then targets the
# host, fails to load the standard library, and writes an empty baseline.
toolset="$RUNNER_TEMP/api-digester-toolset.json"
jq -n --arg triple "$triple" \
'{schemaVersion: "1.0", swiftCompiler: {extraCLIOptions: ["-target", $triple]}}' > "$toolset"
swift_package_args=(
--sdk "$(xcrun --sdk "$sdk_name" --show-sdk-path)"
--triple "$triple"
--toolset "$toolset"
)
echo "Using $platform_name SDK: $platform_version"
else
echo "Using host macOS SDK"
fi
run_diagnose() {
local product="$1"
if [[ "${#swift_package_args[@]}" -gt 0 ]]; then
swift package "${swift_package_args[@]}" diagnose-api-breaking-changes "${{ inputs.branch }}" --products "$product"
else
swift package diagnose-api-breaking-changes "${{ inputs.branch }}" --products "$product"
fi
}
for product in "${library_products[@]}"; do
log="$RUNNER_TEMP/${product}-apidiff.log"
echo "::group::Diagnosing $product"
if run_diagnose "$product" 2>&1 | tee "$log"; then
echo "- ✅ \`$product\`: no breaking changes" >> "$summary"
else
breakages=()
while IFS= read -r breakage_line; do
[[ -n "$breakage_line" ]] || continue
breakages+=("$(printf '%s\n' "$breakage_line" | sed 's/^[[:space:]]*//')")
done < <(grep 'API breakage:' "$log" || true)
if ((${#breakages[@]})); then
has_breaking_changes=true
echo "- ❌ \`$product\`" >> "$summary"
for line in "${breakages[@]}"; do
msg="$product: $line"
esc=${msg//'%'/'%25'}
esc=${esc//$'\n'/'%0A'}
esc=${esc//$'\r'/'%0D'}
echo "::error title=API breaking change::$esc"
echo " $line" >> "$summary"
done
else
echo "::error title=diagnose-api-breaking-changes failed::$product failed for a non-breakage reason; see logs"
echo "- ⚠️ \`$product\`: command failed for a non-breakage reason" >> "$summary"
fi
status=1
fi
echo "::endgroup::"
done
echo "has_breaking_changes=$has_breaking_changes" >> "$GITHUB_OUTPUT"
cat "$summary" >> "$GITHUB_STEP_SUMMARY"
exit "$status"
- name: Update PR comment
if: github.event_name == 'pull_request' && always()
uses: actions/github-script@v9
env:
HAS_BREAKING_CHANGES: ${{ steps.diagnose.outputs.has_breaking_changes }}
with:
script: |
const fs = require('fs');
const marker = '<!-- api-breaking-changes -->';
const hasBreakingChanges = process.env.HAS_BREAKING_CHANGES === 'true';
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const comments = await github.paginate(github.rest.issues.listComments, {
owner, repo, issue_number
});
const existing = comments.find(c => c.user.type === 'Bot' && c.body.includes(marker));
if (!hasBreakingChanges) {
if (existing) {
await github.rest.issues.deleteComment({
owner, repo, comment_id: existing.id
});
}
return;
}
const body = marker + '\n' + fs.readFileSync(process.env.RUNNER_TEMP + '/api-breakages.md', 'utf8');
if (existing) {
await github.rest.issues.updateComment({
owner, repo, comment_id: existing.id, body
});
} else {
await github.rest.issues.createComment({
owner, repo, issue_number, body
});
}