Skip to content

Commit

Permalink
[code-infra] Add monorepo update script (#3091)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Jan 17, 2024
1 parent 487dd66 commit 7bcc102
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"check-types": "lerna run check-types",
"toolpad": "node --enable-source-maps packages/toolpad-app/cli.mjs",
"jsonSchemas": "tsx ./scripts/docs/generateJsonSchemas.ts",
"update-monorepo": "tsx ./scripts/updateMonorepo.ts",
"check-changes": "git add -A && git diff --exit-code --staged",
"test:rest:start": "tsx ./scripts/restTestServer.ts"
},
Expand Down
32 changes: 32 additions & 0 deletions scripts/updateMonorepo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as execa from 'execa';

const $ = execa.$({ stdio: 'inherit' });

async function updateToLatest(dependency: string, repo: string, branch: string = 'master') {
const url = new URL(`https://api.github.com/repos/${repo}/commits`);
url.searchParams.set('sha', branch);
url.searchParams.set('per_page', '1');
const res = await fetch(url);
if (!res.ok) {
throw new Error(`HTTP ${res.status} while fetching "${url}"`);
}
const commits = await res.json();

if (commits.length <= 0) {
throw new Error(`No commits found for "${branch}"`);
}

const latestCommit: string = commits[0].sha;

// eslint-disable-next-line no-console
console.log(`Updating "${repo}" to latest commit ${latestCommit}...`);

await $`pnpm update -r ${dependency}@github:mui/material-ui#${latestCommit}`;

// eslint-disable-next-line no-console
console.log(`Deduping...`);

await $({ stdio: 'inherit' })`pnpm dedupe`;
}

updateToLatest('@mui/monorepo', 'mui/material-ui');

0 comments on commit 7bcc102

Please sign in to comment.