Skip to content

Commit 192630f

Browse files
committed
Merge branch 'master' into render-markdown-report
2 parents 66f89ab + 08fc28d commit 192630f

File tree

4 files changed

+17
-135
lines changed

4 files changed

+17
-135
lines changed

.github/workflows/scripts/prs/checkTypeLabel.js

Lines changed: 12 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -10,84 +10,20 @@ const createEnumerationFromArray = (stringArray) =>
1010
: stringArray.map((s) => `\`${s}\``).join('');
1111

1212
const typeLabels = [
13-
'bug',
14-
'regression', // a sub-type of bug but we flatten it.
15-
'enhancement',
16-
'new feature',
17-
// Those are not "Types" labels, they are "Kind of work" labels, but we don't want to have to handle the overhead of
18-
// setting “Types” labels with them.
19-
'release',
13+
'type: release',
14+
'type: bug',
15+
'type: regression',
16+
'type: improvement',
17+
'type: new feature',
18+
'type: general',
19+
// only used by renovate bot so we can ignore the "type: " prefix here
2020
'dependencies',
2121
];
2222
const labelRegex = new RegExp(`\\b(${typeLabels.join('|')})\\b`, 'i');
2323

24-
const COMMENT_FIRST_LINE = {
25-
NO_LABELS_COMMENT:
26-
'Please add one type label to categorize the purpose of this PR appropriately:',
27-
MULTIPLE_LABELS_COMMENT: 'Multiple type labels found:',
28-
SUCCESS_COMMENT: 'Thanks for adding a type label to the PR! 👍',
29-
};
30-
31-
/**
32-
* @param {Awaited<ReturnType<ReturnType<import("@actions/github").getOctokit>['rest']['issues']['listComments']>>['data']} comments
33-
*/
34-
function containsAny(comments) {
35-
return (
36-
comments.find((comment) =>
37-
Object.values(COMMENT_FIRST_LINE).some((startLine) => comment.body?.startsWith(startLine)),
38-
) ?? false
39-
);
40-
}
41-
42-
/**
43-
* @param {Object} params
44-
* @param {import("@actions/core")} params.core
45-
* @param {ReturnType<import("@actions/github").getOctokit>} params.github
46-
* @param {import("@actions/github").context} params.context
47-
* @param {Awaited<ReturnType<ReturnType<import("@actions/github").getOctokit>['rest']['issues']['listComments']>>['data']} params.comments
48-
*/
49-
const createCommentHandler =
50-
({ core, context, github, comments }) =>
51-
async (/** @type {string[]} */ commentLines) => {
52-
const owner = context.repo.owner;
53-
const repo = context.repo.repo;
54-
const pullNumber = context.issue.number;
55-
56-
const commentFound = containsAny(comments);
57-
58-
if (commentFound) {
59-
core.info(`>>> Updating existing comment on PR`);
60-
core.info(`>>> Comment id: ${commentFound.id}`);
61-
62-
if (commentFound.body?.startsWith(commentLines[0])) {
63-
core.info(`>>> PR already has the needed comment.`);
64-
core.info(`>>> Exiting gracefully! 👍`);
65-
return;
66-
}
67-
68-
return await github.rest.issues.updateComment({
69-
owner,
70-
repo,
71-
comment_id: commentFound.id,
72-
body: commentLines.join('\n\n'),
73-
});
74-
}
75-
76-
// only create a new comment if it's not the success comment
77-
if (commentLines[0] === COMMENT_FIRST_LINE.SUCCESS_COMMENT) {
78-
core.info(`>>> No need for a comment!`);
79-
core.info(`>>> Exiting gracefully! 👍`);
80-
return;
81-
}
82-
83-
core.info(`>>> Creating explanatory comment on PR`);
84-
return await github.rest.issues.createComment({
85-
owner,
86-
repo,
87-
issue_number: pullNumber,
88-
body: commentLines.join('\n\n'),
89-
});
90-
};
24+
const NO_LABELS_COMMENT =
25+
'Please add one type label to categorize the purpose of this PR appropriately:';
26+
const MULTIPLE_LABELS_COMMENT = 'Multiple type labels found:';
9127

9228
/**
9329
* @param {Object} params
@@ -120,51 +56,19 @@ module.exports = async ({ core, context, github }) => {
12056
per_page: 100,
12157
});
12258

123-
const commentHandler = createCommentHandler({
124-
core,
125-
context,
126-
github,
127-
comments: prComments,
128-
});
129-
130-
// docs label is handled differently
131-
if (typeLabelsFound.some((l) => l === 'docs')) {
132-
core.info(`>>> 'docs' type label found`);
133-
134-
await commentHandler([COMMENT_FIRST_LINE.SUCCESS_COMMENT]);
135-
return;
136-
}
137-
13859
if (typeLabelsFound.length === 0) {
13960
core.info(`>>> No type labels found`);
140-
141-
// Add a comment line explaining that a type label needs to be added
142-
await commentHandler([
143-
COMMENT_FIRST_LINE.NO_LABELS_COMMENT,
144-
createEnumerationFromArray(typeLabels),
145-
]);
146-
147-
core.setFailed('>>> Failing workflow to prevent merge without passing this!');
61+
core.setFailed(`>>> ${NO_LABELS_COMMENT} ${createEnumerationFromArray(typeLabels)}`);
14862
return;
14963
}
15064

15165
if (typeLabelsFound.length > 1) {
15266
core.info(`>>> Multiple type labels found: ${typeLabelsFound.join(', ')}`);
153-
154-
// add a comment line explaining that only one type label is allowed
155-
await commentHandler([
156-
COMMENT_FIRST_LINE.MULTIPLE_LABELS_COMMENT,
157-
typeLabelsFound.map((label) => `- ${label}`).join('\n'),
158-
'Only one is allowed. Please remove the extra type labels to ensure the PR is categorized correctly.',
159-
]);
160-
161-
core.setFailed('>>> Failing workflow to prevent merge without passing this!');
67+
core.setFailed(`>>> ${MULTIPLE_LABELS_COMMENT} ${typeLabelsFound.join(', ')}`);
16268
return;
16369
}
16470

16571
core.info(`>>> Single type label found: ${typeLabelsFound[0]}`);
166-
167-
await commentHandler([COMMENT_FIRST_LINE.SUCCESS_COMMENT]);
16872
} catch (error) {
16973
core.error(`>>> Workflow failed with: ${error.message}`);
17074
core.setFailed(error.message);

packages/bundle-size-checker/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"execa": "^7.2.0",
3737
"fast-glob": "^3.3.2",
3838
"file-loader": "^6.2.0",
39-
"fs-extra": "^11.2.0",
4039
"micromatch": "^4.0.8",
4140
"piscina": "^4.2.1",
4241
"rollup-plugin-visualizer": "^6.0.1",
@@ -48,7 +47,6 @@
4847
},
4948
"devDependencies": {
5049
"@types/env-ci": "^3.1.4",
51-
"@types/fs-extra": "^11.0.4",
5250
"@types/micromatch": "^4.0.9",
5351
"@types/webpack": "^5.28.5",
5452
"@types/webpack-bundle-analyzer": "^4.7.0",

packages/bundle-size-checker/src/cli.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import path from 'path';
44
import os from 'os';
5-
import fse from 'fs-extra';
5+
import fs from 'fs/promises';
66
import yargs from 'yargs';
77
import Piscina from 'piscina';
88
import micromatch from 'micromatch';
@@ -31,7 +31,8 @@ async function getWebpackSizes(args, config) {
3131
});
3232
// Clean and recreate the build directory
3333
const buildDir = path.join(rootDir, 'build');
34-
await fse.emptyDir(buildDir);
34+
await fs.rm(buildDir, { recursive: true, force: true });
35+
await fs.mkdir(buildDir, { recursive: true });
3536

3637
if (
3738
!config ||
@@ -89,8 +90,8 @@ async function run(argv) {
8990
const bundleSizes = Object.fromEntries(webpackSizes.sort((a, b) => a[0].localeCompare(b[0])));
9091

9192
// Ensure output directory exists
92-
await fse.mkdirp(path.dirname(snapshotDestPath));
93-
await fse.writeJSON(snapshotDestPath, bundleSizes, { spaces: 2 });
93+
await fs.mkdir(path.dirname(snapshotDestPath), { recursive: true });
94+
await fs.writeFile(snapshotDestPath, JSON.stringify(bundleSizes, null, 2));
9495

9596
// eslint-disable-next-line no-console
9697
console.log(`Bundle size snapshot written to ${snapshotDestPath}`);

pnpm-lock.yaml

Lines changed: 0 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)