Skip to content

Commit f8e5f2e

Browse files
authored
Fix create-update-issues workflow to account for no team assigned (#5087)
The `create-update-issues` workflow can fail if it doesn't know which team labels to assign to a package that has a major version bump. It consults `teams.json` for these labels, and it is possible for a package to be missing from that file. To fix this problem, this commit: - Updates the workflow to account for a missing package - Updates `teams.json` so all packages in the monorepo are listed - Adds a script to the lint step which guarantees that `teams.json` lists all packages in the monorepo going forward
1 parent 15fe706 commit f8e5f2e

File tree

6 files changed

+1578
-24
lines changed

6 files changed

+1578
-24
lines changed

.github/workflows/create-update-issues.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ jobs:
3434
3535
# Check if version number ends with .0.0
3636
if [[ $version == *.0.0 ]]; then
37-
# Fetch responsible team from file
37+
# Fetch responsible teams from file
3838
teams=$(jq -r --arg key "$package_name" '.[$key]' teams.json)
39-
gh issue create --title "Update ${package_name} to version ${version}" --body "Please update ${package_name} to version ${version}" --repo "MetaMask/metamask-extension" --label "$teams, client-controller-update"
40-
gh issue create --title "Update ${package_name} to version ${version}" --body "Please update ${package_name} to version ${version}" --repo "MetaMask/metamask-mobile" --label "$teams, client-controller-update"
39+
labels="client-controller-update"
40+
if [[ $teams != "null" ]]; then
41+
labels+=",$teams"
42+
fi
43+
gh issue create --title "Update ${package_name} to version ${version}" --body "Please update ${package_name} to version ${version}" --repo "MetaMask/metamask-extension" --label "$labels"
44+
gh issue create --title "Update ${package_name} to version ${version}" --body "Please update ${package_name} to version ${version}" --repo "MetaMask/metamask-mobile" --label "$labels"
4145
fi
4246
fi
4347
done

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
"changelog:update": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:update",
2121
"changelog:validate": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:validate",
2222
"create-package": "ts-node scripts/create-package",
23-
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn constraints && yarn lint:dependencies",
23+
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn constraints && yarn lint:dependencies && yarn lint:teams",
2424
"lint:dependencies": "depcheck && yarn dedupe --check",
2525
"lint:dependencies:fix": "depcheck && yarn dedupe",
2626
"lint:eslint": "eslint . --cache --ext js,cjs,mjs,ts",
2727
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn constraints --fix && yarn lint:dependencies:fix",
2828
"lint:misc": "prettier '**/*.json' '**/*.md' '!**/CHANGELOG.old.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path .gitignore",
29+
"lint:teams": "ts-node scripts/lint-teams-json.ts",
2930
"prepack": "./scripts/prepack.sh",
3031
"prepare-preview-builds": "./scripts/prepare-preview-builds.sh",
3132
"publish-previews": "yarn workspaces foreach --all --no-private --parallel --verbose run publish:preview",
@@ -68,6 +69,9 @@
6869
"@types/semver": "^7",
6970
"@typescript-eslint/eslint-plugin": "^5.62.0",
7071
"@typescript-eslint/parser": "^5.62.0",
72+
"@yarnpkg/cli": "^4.5.3",
73+
"@yarnpkg/core": "^4.1.6",
74+
"@yarnpkg/fslib": "^3.1.1",
7175
"@yarnpkg/types": "^4.0.0",
7276
"babel-jest": "^27.5.1",
7377
"depcheck": "^1.4.7",

scripts/lint-teams-json.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { readJsonFile } from '@metamask/utils/node';
2+
import { getPluginConfiguration } from '@yarnpkg/cli';
3+
import { Configuration, Project, structUtils } from '@yarnpkg/core';
4+
import { ppath } from '@yarnpkg/fslib';
5+
import path from 'path';
6+
7+
main().catch(console.error);
8+
9+
/**
10+
* The entrypoint to this script.
11+
*
12+
* Cross-checks the packages listed in `teams.json` against the public packages
13+
* in the monorepo. If there are any packages missing from `teams.json`, prints
14+
* an error and exits with a non-zero code.
15+
*/
16+
async function main() {
17+
const releaseableWorkspaces = await getPublicWorkspaces();
18+
const releaseablePackageNames = releaseableWorkspaces.map((workspace) => {
19+
const packageName = workspace.manifest.name;
20+
if (packageName === null) {
21+
throw new Error(
22+
`${structUtils.stringifyIdent(
23+
workspace.anchoredDescriptor,
24+
)} has no name in its manifest`,
25+
);
26+
}
27+
// The package names in teams.json omit the leading "@", so we do that here
28+
// too in order to be consistent
29+
return structUtils.stringifyIdent(packageName).slice(1);
30+
});
31+
32+
const teams = await readJsonFile<Record<string, string>>(
33+
path.resolve(__dirname, '../teams.json'),
34+
);
35+
const assignedPackageNames = Object.keys(teams);
36+
37+
const missingPackageNames = releaseablePackageNames.filter(
38+
(releaseablePackageName) => {
39+
return !assignedPackageNames.includes(releaseablePackageName);
40+
},
41+
);
42+
43+
if (missingPackageNames.length > 0) {
44+
console.error(
45+
'ERROR: teams.json is invalid. Please add the following packages:',
46+
);
47+
for (const missingPackageName of missingPackageNames) {
48+
console.error(`- ${missingPackageName}`);
49+
}
50+
process.exitCode = 1;
51+
}
52+
}
53+
54+
/**
55+
* Uses the Yarn API to gather the Yarn workspaces inside of this project (the
56+
* packages that are matched by the `workspaces` field inside of
57+
* `package.json`).
58+
*
59+
* @returns The list of workspaces.
60+
*/
61+
async function getPublicWorkspaces() {
62+
const cwd = ppath.resolve('..', ppath.cwd());
63+
const configuration = await Configuration.find(cwd, getPluginConfiguration());
64+
const { project } = await Project.find(configuration, cwd);
65+
66+
return project.workspaces.filter((workspace) => {
67+
return !workspace.manifest.private;
68+
});
69+
}

teams.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"metamask/keyring-controller": "team-accounts",
1818
"metamask/logging-controller": "team-confirmations",
1919
"metamask/message-manager": "team-confirmations",
20+
"metamask/multichain": "team-wallet-api-platform",
2021
"metamask/name-controller": "team-confirmations",
2122
"metamask/network-controller": "team-wallet-framework,team-assets",
2223
"metamask/notification-controller": "team-snaps-platform",
@@ -29,6 +30,7 @@
2930
"metamask/profile-sync-controller": "team-notifications",
3031
"metamask/queued-request-controller": "team-wallet-api-platform",
3132
"metamask/rate-limit-controller": "team-snaps-platform",
33+
"metamask/remote-feature-flag-controller": "team-extension-platform,team-mobile-platform",
3234
"metamask/selected-network-controller": "team-wallet-api-platform,team-wallet-framework,team-assets",
3335
"metamask/signature-controller": "team-confirmations",
3436
"metamask/transaction-controller": "team-confirmations",

tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
2-
"compilerOptions": { "esModuleInterop": true, "noEmit": true },
2+
"compilerOptions": {
3+
"esModuleInterop": true,
4+
"module": "Node16",
5+
"moduleResolution": "Node16",
6+
"noEmit": true
7+
},
38
"references": [
49
{ "path": "./examples/example-controllers" },
510
{ "path": "./packages/accounts-controller" },

0 commit comments

Comments
 (0)