-
Notifications
You must be signed in to change notification settings - Fork 223
168 lines (147 loc) · 6 KB
/
changeset.yaml
File metadata and controls
168 lines (147 loc) · 6 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
# Copyright 2025 LiveKit, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Changeset Check
on:
pull_request:
branches: [main]
permissions:
contents: read
pull-requests: write
jobs:
changeset:
name: Changeset & Breaking Change Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for changeset entries
id: changeset
run: |
count=$(find .changes -maxdepth 1 -type f ! -name '.*' 2>/dev/null | wc -l | tr -d ' ')
echo "count=$count" >> "$GITHUB_OUTPUT"
has_major=false
if [ "$count" -gt 0 ]; then
if grep -rq '^major ' .changes/ 2>/dev/null; then
has_major=true
fi
fi
echo "has_major=$has_major" >> "$GITHUB_OUTPUT"
- uses: ./.github/actions/setup-flutter
- name: Detect breaking changes
id: breaking
run: |
echo "Comparing public API against main"
dart pub global activate dart_apitool
BASE_REF="git://${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}:main"
DIFF_OUTPUT=$(dart-apitool diff \
--old "$BASE_REF" \
--new . \
--force-use-flutter 2>&1) || true
echo "--- dart-apitool output ---"
echo "$DIFF_OUTPUT"
echo "---"
# Check for "BREAKING CHANGES" header in the output (not "No breaking changes!")
BREAKING_LINES=$(echo "$DIFF_OUTPUT" | grep "^BREAKING CHANGES" || true)
if [ -n "$BREAKING_LINES" ]; then
echo "has_breaking=true" >> "$GITHUB_OUTPUT"
echo "$DIFF_OUTPUT" > "$RUNNER_TEMP/breaking_changes.txt"
else
echo "has_breaking=false" >> "$GITHUB_OUTPUT"
echo "No breaking changes detected"
fi
- name: Manage PR comments
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const changesetCount = parseInt('${{ steps.changeset.outputs.count }}');
const hasMajor = '${{ steps.changeset.outputs.has_major }}' === 'true';
const hasBreaking = '${{ steps.breaking.outputs.has_breaking }}' === 'true';
let details = '';
if (hasBreaking) {
const detailsPath = path.join(process.env.RUNNER_TEMP, 'breaking_changes.txt');
try { details = fs.readFileSync(detailsPath, 'utf8').trim(); } catch {}
}
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
// Minimize a comment via GraphQL (collapses with "resolved" reason)
async function minimizeComment(commentId) {
await github.graphql(`
mutation($id: ID!) {
minimizeComment(input: { subjectId: $id, classifier: RESOLVED }) {
minimizedComment { isMinimized }
}
}
`, { id: commentId });
}
// Create or update a comment; minimize the existing one if resolved
async function upsertOrResolve(marker, shouldShow, bodyLines) {
const existing = comments.find(c => c.body.includes(marker));
if (shouldShow) {
const body = [marker, ...bodyLines].join('\n');
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
} else if (existing) {
await minimizeComment(existing.node_id);
}
}
// --- Changeset missing ---
await upsertOrResolve('<!-- changeset-check -->', changesetCount === 0, [
'> [!WARNING]',
'> **No changeset found**',
'>',
'> If this PR includes user-facing changes, please add a changeset file in `.changes/`',
'',
'**Format:** `level type="kind" "description"`',
'',
'```',
'patch type="fixed" "Fix audio frame generation"',
'minor type="added" "Add support for custom audio processing"',
'major type="changed" "Breaking: Rename Room.connect() to Room.join()"',
'```',
]);
// --- Breaking change without major changeset ---
await upsertOrResolve('<!-- breaking-change-check -->', hasBreaking && !hasMajor, [
'> [!CAUTION]',
'> **Breaking change detected without major changeset**',
'',
'`dart-apitool` detected the following breaking changes:',
'',
'```',
details,
'```',
'',
'If this is intentional, please add a changeset with `major` level in `.changes/`:',
'```',
'major type="changed" "Description of breaking change"',
'```',
]);