Skip to content

Commit 6ba49d6

Browse files
committed
chore(ci): use one github action with variants for package bumps
1 parent c832b30 commit 6ba49d6

File tree

5 files changed

+133
-123
lines changed

5 files changed

+133
-123
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Update dependencies
2+
3+
# Runs nightly and manually
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
group_name:
8+
description: 'Package group to update'
9+
type: choice
10+
default: 'all'
11+
options:
12+
- electron
13+
- eslint
14+
- typescript
15+
- mongosh
16+
- all
17+
required: true
18+
schedule:
19+
- cron: '0 0 * * *'
20+
21+
permissions:
22+
contents: none # We use the github app token to push the changes
23+
24+
jobs:
25+
update_dependencies_group:
26+
name: Update ${{ matrix.group_name }} to latest
27+
runs-on: ubuntu-latest
28+
strategy:
29+
matrix:
30+
group_name:
31+
# When adding new group, don't forget to update the
32+
# `workflow_dispatch.inputs`
33+
- electron
34+
- eslint
35+
- typescript
36+
- mongosh
37+
if: ${{ inputs.group_name == '' || inputs.group_name == 'all' || inputs.group_name == matrix.group_name }}
38+
steps:
39+
- name: Create Github App Token
40+
uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
41+
id: app-token
42+
with:
43+
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
44+
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}
45+
46+
- uses: actions/checkout@v4
47+
with:
48+
# don't checkout a detatched HEAD
49+
ref: ${{ github.head_ref || github.ref_name }}
50+
token: ${{ steps.app-token.outputs.token }}
51+
52+
- uses: actions/setup-node@v4
53+
with:
54+
node-version: 22.15.1
55+
cache: 'npm'
56+
57+
- name: Install [email protected]
58+
run: |
59+
npm install -g [email protected]
60+
61+
- name: Install dependencies
62+
run: |
63+
npm ci
64+
65+
- name: Run "update dependencies" script
66+
run: npx compass-scripts update-dependencies preset-${{ matrix.group_name }}
67+
68+
- name: Create Pull Request
69+
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # 7.0.5
70+
with:
71+
token: ${{ steps.app-token.outputs.token }}
72+
commit-message: 'chore(deps): update ${{ matrix.group_name }} to latest'
73+
branch: ci/update-${{ matrix.group_name }}
74+
title: 'chore(deps): update ${{ matrix.group_name }} to latest'
75+
labels: no-title-validation
76+
author: '${{ steps.app-token.outputs.app-slug}}[bot] <${{ steps.app-token.outputs.app-email }}>'
77+
body: |
78+
<p>This PR is automatically generated and updates the versions of
79+
the dependency group ${{ matrix.group_name }} to latest version.</p>
80+
81+
<p>If CI is green on this patch you should feel free to merge it at
82+
your convenience.</p>
83+
84+
<p>If CI is red and you think that failures are related to the
85+
version updates, you should raise an issue, so that it can be
86+
manually resolved and we can continue to update the package group to
87+
latest.</p>

.github/workflows/update-electron.yaml

Lines changed: 0 additions & 55 deletions
This file was deleted.

.github/workflows/update-eslint.yaml

Lines changed: 0 additions & 56 deletions
This file was deleted.

scripts/update-dependencies-config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ module.exports = {
2222
'eslint-plugin-react-hooks',
2323
],
2424
typescript: ['typescript', 'ts-node'],
25+
leafygreen: [
26+
'@emotion/*',
27+
'@leafygreen-ui/*',
28+
'@lg-code/*',
29+
'@mongodb-js/diagramming',
30+
],
31+
mongosh: ['@mongosh/*'],
2532
// TODO(COMPASS-9443): Update update-* github actions to handle all groups as
2633
// a matrix inside one action instead of having separate action for every
2734
// group and add more groups following the ones in _dependabot

scripts/update-dependencies.js

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ async function getVersion(depSpec) {
6969
return [name, version.trim()];
7070
}
7171

72+
const DEP_TYPES = [
73+
'dependencies',
74+
'devDependencies',
75+
'peerDependencies',
76+
'optionalDependencies',
77+
];
78+
7279
function updateDependencies(packageJson, newVersions) {
73-
for (const depType of [
74-
'dependencies',
75-
'devDependencies',
76-
'peerDependencies',
77-
'optionalDependencies',
78-
]) {
80+
for (const depType of DEP_TYPES) {
7981
if (packageJson[depType]) {
8082
for (const packageName of Object.keys(packageJson[depType])) {
8183
if (packageJson[depType][packageName] && newVersions[packageName]) {
@@ -146,6 +148,36 @@ async function main() {
146148
dependencies = args;
147149
}
148150

151+
const monorepoRoot = await findMonorepoRoot();
152+
const workspaces = [monorepoRoot].concat(
153+
await Array.fromAsync(listAllPackages(), (workspace) => workspace.location)
154+
);
155+
const allMonorepoDependencies = Array.from(
156+
new Set(
157+
workspaces.flatMap((location) => {
158+
try {
159+
const deps = {};
160+
const packageJson = require(path.join(location, 'package.json'));
161+
for (const depType of DEP_TYPES) {
162+
Object.assign(deps, packageJson[depType] ?? {});
163+
}
164+
return Object.keys(deps);
165+
} catch {
166+
return [];
167+
}
168+
})
169+
)
170+
);
171+
172+
dependencies = dependencies.flatMap((depToUpdate) => {
173+
if (/\*/.test(depToUpdate)) {
174+
return allMonorepoDependencies.filter((dep) => {
175+
return dep.startsWith(depToUpdate.replace('*', ''));
176+
});
177+
}
178+
return depToUpdate;
179+
});
180+
149181
const newVersions = await withProgress(
150182
`Collection version information for packages...`,
151183
() => {
@@ -159,7 +191,7 @@ async function main() {
159191

160192
console.log();
161193
console.log(
162-
'Updating following packages:\n\n * %s\n',
194+
'Updating following packages:\n\n * %s',
163195
newVersions
164196
.map((spec) => {
165197
return spec.join('@');
@@ -171,11 +203,6 @@ async function main() {
171203
const newVersionsObj = Object.fromEntries(newVersions);
172204
let hasChanged;
173205

174-
const monorepoRoot = await findMonorepoRoot();
175-
const workspaces = [monorepoRoot].concat(
176-
await Array.fromAsync(listAllPackages(), (workspace) => workspace.location)
177-
);
178-
179206
await withProgress('Updating package.json in workspaces', async () => {
180207
for (const workspacePath of workspaces) {
181208
await updatePackageJson(workspacePath, (packageJson) => {

0 commit comments

Comments
 (0)