Skip to content

Commit 283a7b7

Browse files
authored
Merge pull request #1 from Ashutoshx7/ci/pr-category-check
Ci/pr category check
2 parents 81cefcb + 5980640 commit 283a7b7

File tree

152 files changed

+23086
-31677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+23086
-31677
lines changed

.github/PULL_REQUEST_TEMPLATE/generic.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ about: Submit changes to the project for review and inclusion
1515

1616
This PR fixes #
1717

18+
## PR Category
19+
20+
<!--- ⚠️ CI ENFORCED: You MUST check at least ONE category below or the CI will fail. -->
21+
<!--- Check all categories that apply to this pull request. -->
22+
23+
- [ ] 🐛 Bug Fix — Fixes a bug or incorrect behavior
24+
- [ ] ✨ Feature — Adds new functionality
25+
- [ ] ⚡ Performance — Improves performance (load time, memory, rendering, etc.)
26+
- [ ] 🧪 Tests — Adds or updates test coverage
27+
- [ ] 📝 Documentation — Updates to docs, comments, or README
28+
1829
## Changes Made
1930

2031
<!--- Provide a summary of the changes made in this pull request. -->
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: PR Category Check
2+
3+
# Ensures every PR has at least one category checkbox checked.
4+
# Automatically applies matching GitHub labels to the PR.
5+
# Uses pull_request_target so it works for fork PRs too (runs in base repo context).
6+
# This is safe because we only read the PR body from the event payload — no fork code is checked out or executed.
7+
8+
on:
9+
pull_request_target:
10+
types: [opened, edited, synchronize, reopened]
11+
12+
permissions:
13+
pull-requests: write
14+
contents: read
15+
16+
jobs:
17+
check-pr-category:
18+
name: Validate PR Category & Auto-Label
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Check categories and apply labels
22+
uses: actions/github-script@v7
23+
with:
24+
script: |
25+
const prBody = context.payload.pull_request.body || '';
26+
const prNumber = context.payload.pull_request.number;
27+
28+
// Category checkboxes mapped to their GitHub label names
29+
const categories = [
30+
{ label: 'Issue-Bug', emoji: '🐛', displayName: '🐛 Bug Fix', pattern: /- \[x\]\s*🐛\s*Bug Fix/i },
31+
{ label: 'Issue-Enhancement', emoji: '✨', displayName: '✨ Feature', pattern: /- \[x\]\s*✨\s*Feature/i },
32+
{ label: 'Issue-Performance', emoji: '⚡', displayName: '⚡ Performance', pattern: /- \[x\]\s*⚡\s*Performance/i },
33+
{ label: 'Issue-Testing', emoji: '🧪', displayName: '🧪 Tests', pattern: /- \[x\]\s*🧪\s*Tests/i },
34+
{ label: 'Issue-Documentation', emoji: '📝', displayName: '📝 Documentation', pattern: /- \[x\]\s*📝\s*Documentation/i },
35+
];
36+
37+
const checkedCategories = categories.filter(cat => cat.pattern.test(prBody));
38+
const uncheckedCategories = categories.filter(cat => !cat.pattern.test(prBody));
39+
40+
// --- Step 1: Fail CI if no category is selected ---
41+
if (checkedCategories.length === 0) {
42+
const message = [
43+
'## ❌ PR Category Required',
44+
'',
45+
'This pull request does not have any **PR Category** selected.',
46+
'Please edit your PR description and check **at least one** category checkbox:',
47+
'',
48+
'| Category | Description |',
49+
'|----------|-------------|',
50+
'| 🐛 Bug Fix | Fixes a bug or incorrect behavior |',
51+
'| ✨ Feature | Adds new functionality |',
52+
'| ⚡ Performance | Improves performance |',
53+
'| 🧪 Tests | Adds or updates test coverage |',
54+
'| 📝 Documentation | Updates to docs, comments, or README |',
55+
'',
56+
'Example: Change `- [ ] 🐛 Bug Fix` to `- [x] 🐛 Bug Fix`',
57+
'',
58+
'> **Tip:** You can select multiple categories if your PR spans several areas.',
59+
].join('\n');
60+
61+
core.setFailed(message);
62+
return;
63+
}
64+
65+
// --- Step 2: Auto-apply labels for checked categories ---
66+
const labelsToAdd = checkedCategories.map(cat => cat.label);
67+
const labelsToRemove = uncheckedCategories.map(cat => cat.label);
68+
69+
// Get current labels on the PR
70+
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
issue_number: prNumber,
74+
});
75+
const currentLabelNames = currentLabels.map(l => l.name);
76+
77+
// Add labels that are checked but not yet on the PR
78+
for (const label of labelsToAdd) {
79+
if (!currentLabelNames.includes(label)) {
80+
try {
81+
await github.rest.issues.addLabels({
82+
owner: context.repo.owner,
83+
repo: context.repo.repo,
84+
issue_number: prNumber,
85+
labels: [label],
86+
});
87+
core.info(`🏷️ Added label: "${label}"`);
88+
} catch (error) {
89+
core.warning(`⚠️ Could not add label "${label}". Make sure it exists in the repo. Error: ${error.message}`);
90+
}
91+
}
92+
}
93+
94+
// Remove labels that are unchecked but still on the PR
95+
for (const label of labelsToRemove) {
96+
if (currentLabelNames.includes(label)) {
97+
try {
98+
await github.rest.issues.removeLabel({
99+
owner: context.repo.owner,
100+
repo: context.repo.repo,
101+
issue_number: prNumber,
102+
name: label,
103+
});
104+
core.info(`🗑️ Removed label: "${label}"`);
105+
} catch (error) {
106+
core.warning(`⚠️ Could not remove label "${label}". Error: ${error.message}`);
107+
}
108+
}
109+
}
110+
111+
const selected = checkedCategories.map(c => c.displayName).join(', ');
112+
core.info(`✅ PR categories selected: ${selected}`);
113+
core.info(`🏷️ Labels synced: ${labelsToAdd.join(', ')}`);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: E2E Test
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
push:
9+
branches:
10+
- master
11+
12+
jobs:
13+
e2e:
14+
name: Run Cypress E2E Tests
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout Repository
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '20'
25+
cache: 'npm'
26+
27+
- name: Run Cypress E2E Tests
28+
uses: cypress-io/github-action@v6
29+
with:
30+
install-command: npm ci
31+
start: npm start
32+
wait-on: 'http://127.0.0.1:3000'
33+
wait-on-timeout: 120
34+
browser: chrome
35+
config: video=false
36+
37+
- name: Upload Cypress Screenshots on Failure
38+
if: failure()
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: cypress-screenshots
42+
path: cypress/screenshots
43+
if-no-files-found: ignore

CONTRIBUTING.md

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
## <a name="CONTRIBUTING"></a>Contributing
22

33
We welcome contributions of all kinds — whether it’s code,
4-
documentation, music, lesson plans, artwork, or ideas. Music Blocks
4+
documentation, music, lesson plans, artwork, or ideas. Music Blocks
55
is a community-driven project, and every meaningful contribution helps
66
improve the platform for learners and educators around the world.
77

88
If you’re new to the project, start by setting up the local
9-
development environment using the guide linked above, then explore
9+
development environment using the guide linked below, then explore
1010
open issues or discussions to find a place to contribute.
1111

1212
- [How to set up a local server](README.md#how-to-set-up-a-local-server)
1313

14-
1514
### Special Notes
1615

1716
Music Blocks is being built from the ground-up, to address several
@@ -50,9 +49,12 @@ following resources:
5049
- [JavaScript tutorial - w3schools.com](https://www.w3schools.com/js/default.asp)
5150
- [JavaScript reference - MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript)
5251

53-
Programmers, please follow these general [guidelines for
52+
For code contributions, please follow these general [guidelines for
5453
contributions](https://github.com/sugarlabs/sugar-docs/blob/master/src/contributing.md).
5554

55+
### AI guidelines
56+
57+
Follow [AI guidelines for Sugar Labs](https://github.com/sugarlabs/sugar-docs/blob/master/src/contributing.md#ai-guidelines-for-sugar-labs)
5658

5759
### Before You Push
5860

@@ -64,8 +66,20 @@ npx prettier --check . # Formatting
6466
npm test # Jest
6567
```
6668

69+
NOTE: Only run ```prettier``` on the files you have modified.
70+
6771
If formatting fails, run `npx prettier --write .` to fix it.
6872

73+
### After your PR is merged
74+
75+
Please note that production deployments of Music Blocks are **manual**.
76+
77+
This means that even after your pull request is merged, your changes may not immediately appear. Your update will become visible after the next official release is deployed.
78+
79+
If your changes are not visible right away, it does **not** indicate a problem with your PR or implementation.
80+
81+
This note is included to prevent contributors from spending time debugging caching or deployment issues unnecessarily.
82+
6983
### License Header
7084

7185
Music Blocks is licensed under the [AGPL](https://www.gnu.org/licenses/agpl-3.0.en.html).
@@ -129,60 +143,60 @@ Feel free. But, please don't spam :p.
129143
### Keep in Mind
130144

131145
1. Your contributions need not necessarily have to address any
132-
discovered issue. If you encounter any, feel free to add a fix through
133-
a PR, or create a new issue ticket.
146+
discovered issue. If you encounter any, feel free to add a fix through
147+
a PR, or create a new issue ticket.
134148

135149
2. Use [labels](https://github.com/sugarlabs/musicblocks/labels) on
136-
your issues and PRs.
150+
your issues and PRs.
137151

138152
3. Please do not spam with many PRs consisting of little changes.
139153

140154
4. If you are addressing a bulk change, divide your commits across
141-
multiple PRs, and send them one at a time. The fewer the number of
142-
files addressed per PR, the better.
155+
multiple PRs, and send them one at a time. The fewer the number of
156+
files addressed per PR, the better.
143157

144158
5. Communicate effectively. Go straight to the point. You don't need
145-
to address anyone using '_sir_'. Don't write unnecessary comments;
146-
don't be over-apologetic. There is no superiority hierarchy. Every
147-
single contribution is welcome, as long as it doesn't spam or distract
148-
the flow.
159+
to address anyone using '_sir_'. Don't write unnecessary comments;
160+
don't be over-apologetic. There is no superiority hierarchy. Every
161+
single contribution is welcome, as long as it doesn't spam or distract
162+
the flow.
149163

150164
6. Write useful, brief commit messages. Add commit descriptions if
151-
necessary. PR name should speak about what it is addressing and not
152-
the issue. In case a PR fixes an issue, use `fixes #ticketno` or
153-
`closes #ticketno` in the PR's comment. Briefly explain what your PR
154-
is doing.
165+
necessary. PR name should speak about what it is addressing and not
166+
the issue. In case a PR fixes an issue, use `fixes #ticketno` or
167+
`closes #ticketno` in the PR's comment. Briefly explain what your PR
168+
is doing.
155169

156170
7. Always test your changes extensively before creating a PR. There's
157-
no sense in merging broken code. If a PR is a _work in progress
158-
(WIP)_, convert it to draft. It'll let the maintainers know it isn't
159-
ready for merging.
171+
no sense in merging broken code. If a PR is a _work in progress
172+
(WIP)_, convert it to draft. It'll let the maintainers know it isn't
173+
ready for merging.
160174

161175
8. Read and revise the concepts about programming constructs you're
162-
dealing with. You must be clear about the behavior of the language or
163-
compiler/transpiler. See [JavaScript
164-
docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript).
176+
dealing with. You must be clear about the behavior of the language or
177+
compiler/transpiler. See [JavaScript
178+
docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript).
165179

166180
9. If you have a question, do a _web search_ first. If you don't find
167-
any satisfactory answer, then ask it in a comment. If it is a general
168-
question about Music Blocks, please use the new
169-
[discussions](https://github.com/sugarlabs/musicblocks/discussions)
170-
tab on top the the repository, or the _Sugar-dev Devel
171-
<[sugar-devel@lists.sugarlabs.org](mailto:sugar-devel@lists.sugarlabs.org)>_
172-
mailing list. Don't ask silly questions (unless you don't know it is
173-
silly ;p) before searching it on the web.
181+
any satisfactory answer, then ask it in a comment. If it is a general
182+
question about Music Blocks, please use the new
183+
[discussions](https://github.com/sugarlabs/musicblocks/discussions)
184+
tab on top the the repository, or the _Sugar-dev Devel
185+
<[sugar-devel@lists.sugarlabs.org](mailto:sugar-devel@lists.sugarlabs.org)>_
186+
mailing list. Don't ask silly questions (unless you don't know it is
187+
silly ;p) before searching it on the web.
174188

175189
10. Work on things that matter. Follow three milestones: `Port Ready`,
176-
`Migration`, and `Future`. Those tagged `Port Ready` are
177-
priority. Those tagged with `Migration` will be taken care of during
178-
or after the foundation rebuild. Feel free to participate in the
179-
conversation, adding valuable comments. Those tagged with `Future`
180-
need not be addressed presently.
190+
`Migration`, and `Future`. Those tagged `Port Ready` are
191+
priority. Those tagged with `Migration` will be taken care of during
192+
or after the foundation rebuild. Feel free to participate in the
193+
conversation, adding valuable comments. Those tagged with `Future`
194+
need not be addressed presently.
181195

182196
_Please note there is no need to ask permission to work on an
183197
issue. You should check for pull requests linked to an issue you are
184198
addressing; if there are none, then assume nobody has done
185199
anything. Begin to fix the problem, test, make your commits, push your
186200
commits, then make a pull request. Mention an issue number in the pull
187201
request, but not the commit message. These practices allow the
188-
competition of ideas (Sugar Labs is a meritocracy)._
202+
competition of ideas (Sugar Labs is a meritocracy)._

0 commit comments

Comments
 (0)