Skip to content

Commit

Permalink
Fix create-update-issues workflow to account for no team assigned (#5087
Browse files Browse the repository at this point in the history
)

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
  • Loading branch information
mcmire authored Dec 19, 2024
1 parent 15fe706 commit f8e5f2e
Show file tree
Hide file tree
Showing 6 changed files with 1,578 additions and 24 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/create-update-issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ jobs:
# Check if version number ends with .0.0
if [[ $version == *.0.0 ]]; then
# Fetch responsible team from file
# Fetch responsible teams from file
teams=$(jq -r --arg key "$package_name" '.[$key]' teams.json)
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"
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"
labels="client-controller-update"
if [[ $teams != "null" ]]; then
labels+=",$teams"
fi
gh issue create --title "Update ${package_name} to version ${version}" --body "Please update ${package_name} to version ${version}" --repo "MetaMask/metamask-extension" --label "$labels"
gh issue create --title "Update ${package_name} to version ${version}" --body "Please update ${package_name} to version ${version}" --repo "MetaMask/metamask-mobile" --label "$labels"
fi
fi
done
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
"changelog:update": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:update",
"changelog:validate": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:validate",
"create-package": "ts-node scripts/create-package",
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn constraints && yarn lint:dependencies",
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn constraints && yarn lint:dependencies && yarn lint:teams",
"lint:dependencies": "depcheck && yarn dedupe --check",
"lint:dependencies:fix": "depcheck && yarn dedupe",
"lint:eslint": "eslint . --cache --ext js,cjs,mjs,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn constraints --fix && yarn lint:dependencies:fix",
"lint:misc": "prettier '**/*.json' '**/*.md' '!**/CHANGELOG.old.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path .gitignore",
"lint:teams": "ts-node scripts/lint-teams-json.ts",
"prepack": "./scripts/prepack.sh",
"prepare-preview-builds": "./scripts/prepare-preview-builds.sh",
"publish-previews": "yarn workspaces foreach --all --no-private --parallel --verbose run publish:preview",
Expand Down Expand Up @@ -68,6 +69,9 @@
"@types/semver": "^7",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@yarnpkg/cli": "^4.5.3",
"@yarnpkg/core": "^4.1.6",
"@yarnpkg/fslib": "^3.1.1",
"@yarnpkg/types": "^4.0.0",
"babel-jest": "^27.5.1",
"depcheck": "^1.4.7",
Expand Down
69 changes: 69 additions & 0 deletions scripts/lint-teams-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { readJsonFile } from '@metamask/utils/node';
import { getPluginConfiguration } from '@yarnpkg/cli';
import { Configuration, Project, structUtils } from '@yarnpkg/core';
import { ppath } from '@yarnpkg/fslib';
import path from 'path';

main().catch(console.error);

/**
* The entrypoint to this script.
*
* Cross-checks the packages listed in `teams.json` against the public packages
* in the monorepo. If there are any packages missing from `teams.json`, prints
* an error and exits with a non-zero code.
*/
async function main() {
const releaseableWorkspaces = await getPublicWorkspaces();
const releaseablePackageNames = releaseableWorkspaces.map((workspace) => {
const packageName = workspace.manifest.name;
if (packageName === null) {
throw new Error(
`${structUtils.stringifyIdent(
workspace.anchoredDescriptor,
)} has no name in its manifest`,
);
}
// The package names in teams.json omit the leading "@", so we do that here
// too in order to be consistent
return structUtils.stringifyIdent(packageName).slice(1);
});

const teams = await readJsonFile<Record<string, string>>(
path.resolve(__dirname, '../teams.json'),
);
const assignedPackageNames = Object.keys(teams);

const missingPackageNames = releaseablePackageNames.filter(
(releaseablePackageName) => {
return !assignedPackageNames.includes(releaseablePackageName);
},
);

if (missingPackageNames.length > 0) {
console.error(
'ERROR: teams.json is invalid. Please add the following packages:',
);
for (const missingPackageName of missingPackageNames) {
console.error(`- ${missingPackageName}`);
}
process.exitCode = 1;
}
}

/**
* Uses the Yarn API to gather the Yarn workspaces inside of this project (the
* packages that are matched by the `workspaces` field inside of
* `package.json`).
*
* @returns The list of workspaces.
*/
async function getPublicWorkspaces() {
const cwd = ppath.resolve('..', ppath.cwd());
const configuration = await Configuration.find(cwd, getPluginConfiguration());
const { project } = await Project.find(configuration, cwd);

return project.workspaces.filter((workspace) => {
return !workspace.manifest.private;
});
}
2 changes: 2 additions & 0 deletions teams.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"metamask/keyring-controller": "team-accounts",
"metamask/logging-controller": "team-confirmations",
"metamask/message-manager": "team-confirmations",
"metamask/multichain": "team-wallet-api-platform",
"metamask/name-controller": "team-confirmations",
"metamask/network-controller": "team-wallet-framework,team-assets",
"metamask/notification-controller": "team-snaps-platform",
Expand All @@ -29,6 +30,7 @@
"metamask/profile-sync-controller": "team-notifications",
"metamask/queued-request-controller": "team-wallet-api-platform",
"metamask/rate-limit-controller": "team-snaps-platform",
"metamask/remote-feature-flag-controller": "team-extension-platform,team-mobile-platform",
"metamask/selected-network-controller": "team-wallet-api-platform,team-wallet-framework,team-assets",
"metamask/signature-controller": "team-confirmations",
"metamask/transaction-controller": "team-confirmations",
Expand Down
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"compilerOptions": { "esModuleInterop": true, "noEmit": true },
"compilerOptions": {
"esModuleInterop": true,
"module": "Node16",
"moduleResolution": "Node16",
"noEmit": true
},
"references": [
{ "path": "./examples/example-controllers" },
{ "path": "./packages/accounts-controller" },
Expand Down
Loading

0 comments on commit f8e5f2e

Please sign in to comment.