Skip to content

Commit

Permalink
ci: Add CODEOWNER constraints
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Gudahtt committed Feb 17, 2025
1 parent 24b1903 commit 6d22c09
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions yarn.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ module.exports = defineConfig({
if (isChildWorkspace) {
// All non-root packages must have a valid README.md file.
await expectReadme(workspace, workspaceBasename);

await expectCodeowner(workspace, workspaceBasename);
}
}

Expand Down Expand Up @@ -835,3 +837,60 @@ async function expectReadme(workspace, workspaceBasename) {
);
}
}

// A promise resolving to the codeowners file contents
let cachedCodeownersFile;

/**
* Expect that the workspace has a codeowner set, and that the CHANGELOG.md and
* package.json files are co-owned with the wallet framework team.
*
* @param {Workspace} workspace - The workspace to check.
* @param {string} workspaceBasename - The name of the workspace.
* @returns {Promise<void>}
*/
async function expectCodeowner(workspace, workspaceBasename) {
if (!cachedCodeownersFile) {
cachedCodeownersFile = readFile(
resolve(__dirname, '.github', 'CODEOWNERS'),
'utf8',
);
}
const codeownersFile = await cachedCodeownersFile;
const codeownerRules = codeownersFile.split('\n');

const packageCodeownerRule = codeownerRules.find((rule) =>
rule.startsWith(`/packages/${workspaceBasename}`),
);

if (!packageCodeownerRule) {
workspace.error('Missing CODEOWNER rule for package');
return;
}

if (!packageCodeownerRule.includes('@MetaMask/wallet-framework-engineers')) {
if (
!codeownerRules.some(
(rule) =>
rule.startsWith(`/packages/${workspaceBasename}/CHANGELOG.md`) &&
rule.includes('@MetaMask/wallet-framework-engineers'),
)
) {
workspace.error(
'Missing CODEOWNER rule for CHANGELOG.md co-ownership with wallet framework team',
);
}

if (
!codeownerRules.some(
(rule) =>
rule.startsWith(`/packages/${workspaceBasename}/package.json`) &&
rule.includes('@MetaMask/wallet-framework-engineers'),
)
) {
workspace.error(
'Missing CODEOWNER rule for package.json co-ownership with wallet framework team',
);
}
}
}

0 comments on commit 6d22c09

Please sign in to comment.