Skip to content

Commit 48b1b68

Browse files
authored
ci: Add CODEOWNER constraints (#5352)
## Explanation Add Yarn constraints to ensure each package has a designated owner, and that any non-wallet-frameowrk packages have the wallet framework team set as co-owners of release related files. ## References N/A ## Changelog N/A ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've highlighted breaking changes using the "BREAKING" category above as appropriate - [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent 8e348d8 commit 48b1b68

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

yarn.config.cjs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ module.exports = defineConfig({
247247
if (isChildWorkspace) {
248248
// All non-root packages must have a valid README.md file.
249249
await expectReadme(workspace, workspaceBasename);
250+
251+
await expectCodeowner(workspace, workspaceBasename);
250252
}
251253
}
252254

@@ -835,3 +837,62 @@ async function expectReadme(workspace, workspaceBasename) {
835837
);
836838
}
837839
}
840+
841+
// A promise resolving to the codeowners file contents
842+
let cachedCodeownersFile;
843+
844+
/**
845+
* Expect that the workspace has a codeowner set, and that the CHANGELOG.md and
846+
* package.json files are co-owned with the wallet framework team.
847+
*
848+
* @param {Workspace} workspace - The workspace to check.
849+
* @param {string} workspaceBasename - The name of the workspace.
850+
* @returns {Promise<void>}
851+
*/
852+
async function expectCodeowner(workspace, workspaceBasename) {
853+
if (!cachedCodeownersFile) {
854+
cachedCodeownersFile = readFile(
855+
resolve(__dirname, '.github', 'CODEOWNERS'),
856+
'utf8',
857+
);
858+
}
859+
const codeownersFile = await cachedCodeownersFile;
860+
const codeownerRules = codeownersFile.split('\n');
861+
862+
const packageCodeownerRule = codeownerRules.find((rule) =>
863+
// Matcher includes intentional trailing space to ensure there is a package-wide rule, not
864+
// just a rule for specific files/directories in the package.
865+
rule.startsWith(`/packages/${workspaceBasename} `),
866+
);
867+
868+
if (!packageCodeownerRule) {
869+
workspace.error('Missing CODEOWNER rule for package');
870+
return;
871+
}
872+
873+
if (!packageCodeownerRule.includes('@MetaMask/wallet-framework-engineers')) {
874+
if (
875+
!codeownerRules.some(
876+
(rule) =>
877+
rule.startsWith(`/packages/${workspaceBasename}/CHANGELOG.md`) &&
878+
rule.includes('@MetaMask/wallet-framework-engineers'),
879+
)
880+
) {
881+
workspace.error(
882+
'Missing CODEOWNER rule for CHANGELOG.md co-ownership with wallet framework team',
883+
);
884+
}
885+
886+
if (
887+
!codeownerRules.some(
888+
(rule) =>
889+
rule.startsWith(`/packages/${workspaceBasename}/package.json`) &&
890+
rule.includes('@MetaMask/wallet-framework-engineers'),
891+
)
892+
) {
893+
workspace.error(
894+
'Missing CODEOWNER rule for package.json co-ownership with wallet framework team',
895+
);
896+
}
897+
}
898+
}

0 commit comments

Comments
 (0)