-
-
Notifications
You must be signed in to change notification settings - Fork 350
176 lines (142 loc) · 6.66 KB
/
changeset-major-warning.yml
File metadata and controls
176 lines (142 loc) · 6.66 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
name: PR - Major Version Warning
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- ".changeset/*.md"
permissions:
contents: read
pull-requests: write
issues: write
jobs:
check-major:
name: Check Breaking Changes
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed changeset files
id: changed-files
uses: tj-actions/changed-files@v47
with:
files: ".changeset/*.md"
files_ignore: .changeset/README.md
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Check for major changes
id: check-major
if: steps.changed-files.outputs.any_changed == 'true'
run: |
echo "Checking changeset files for major changes..."
major_files=""
major_packages=""
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "Checking file: $file"
# Extract front matter and check for major (more robust parsing)
if sed -n '/^---$/,/^---$/p' "$file" | grep -q ": major"; then
echo "Found major change in: $file"
major_files="$major_files$file "
# Extract package names with major changes (more precise)
packages=$(sed -n '/^---$/,/^---$/p' "$file" | grep ": major" | sed 's/^"\([^"]*\)": major$/\1/' | tr '\n' ' ')
major_packages="$major_packages$packages"
fi
done
if [ -n "$major_files" ]; then
echo "has_major=true" >> $GITHUB_OUTPUT
echo "major_files=$major_files" >> $GITHUB_OUTPUT
echo "major_packages=$major_packages" >> $GITHUB_OUTPUT
else
echo "has_major=false" >> $GITHUB_OUTPUT
fi
- name: Comment on PR with major version warning
if: steps.check-major.outputs.has_major == 'true' && github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@v7
with:
script: |
const majorFiles = ${{ toJSON(steps.check-major.outputs.major_files) }}.trim();
const majorPackages = ${{ toJSON(steps.check-major.outputs.major_packages) }}.trim();
// Check if we already have a major version warning comment
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('⚠️ Major Version Change Detected')
);
const comment = `## ⚠️ Major Version Change Detected
This PR contains **MAJOR** version changes, which means **breaking changes**!
### 📦 Affected Packages
${majorPackages.split(' ').filter(p => p).map(pkg => `- \`${pkg}\``).join('\n')}
### 📁 Related Changeset Files
${majorFiles.split(' ').filter(f => f).map(file => `- \`${file}\``).join('\n')}
### 🔢 Version Impact
Major version changes will:
- Increment the major version number by 1 (e.g., 1.2.3 → 2.0.0)
- Reset minor and patch versions to 0
- Indicate **breaking changes** that may cause existing user code to fail
### ❓ Please Confirm
Please carefully confirm the following:
1. **Does this really contain breaking changes?**
- API removal or modification
- Default behavior changes
- Major dependency updates
2. **Should you use \`minor\` or \`patch\` instead?**
- \`minor\`: New features but backward compatible
- \`patch\`: Bug fixes, backward compatible
3. **Are you ready to release a major version?**
- Updated documentation explaining breaking changes
- Provided migration guide
- Notified users of upcoming major update
### 🛠️ How to Modify
If you need to downgrade the version type:
1. Edit the changeset file, change \`major\` to \`minor\` or \`patch\`
2. Commit the changes
### 📚 References
- [Semantic Versioning](https://semver.org/)
- [Changesets Documentation](https://github.com/changesets/changesets)
---
*This warning is generated by automated checks to prevent accidental breaking version releases.*`;
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
}
- name: Fail workflow for major changes (fork repos only)
if: steps.check-major.outputs.has_major == 'true' && github.event.pull_request.head.repo.full_name != github.repository
run: |
echo "::error::⚠️ Major version changes detected in fork repository!"
echo "::error::"
echo "::error::❓ Are you sure this PR contains BREAKING CHANGES?"
echo "::error:: Major versions (1.2.3 → 2.0.0) are only for:"
echo "::error:: • API removals or incompatible changes"
echo "::error:: • Behavior changes that break existing code"
echo "::error:: • Major dependency updates with breaking changes"
echo "::error::"
echo "::error::🚫 Fork repositories cannot submit major version changes due to their breaking nature."
echo "::error:: Major changes require repository maintainer approval and coordination."
echo "::error::"
echo "::error::📝 Please either:"
echo "::error:: 1. Change 'major' to 'minor' or 'patch' in your changeset files"
echo "::error:: 2. Contact repository maintainers to handle this major change"
echo "::error:: 3. Open an issue to discuss the breaking changes first"
echo "::error::"
echo "::error::For more info about semantic versioning: https://semver.org/"
exit 1