Skip to content

Commit 97aa0c3

Browse files
authored
Dependabot Beachbot Pipeline (#82)
* Get script for beachball changelogs setup * Remove minor, and only do major vs. patch for dependabot updates
1 parent 178e839 commit 97aa0c3

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env node
2+
3+
import { execSync } from 'node:child_process';
4+
5+
function checkIfBeachballChangeNeeded() {
6+
console.log('Checking if beachball change files are needed...');
7+
8+
try {
9+
execSync('npx beachball check --verbose', { encoding: 'utf8', stdio: 'pipe' });
10+
console.log('✅ Beachball check passed - no change files needed');
11+
return false;
12+
} catch (error) {
13+
console.log('❌ Beachball check failed - change files needed');
14+
return true;
15+
}
16+
}
17+
18+
function determineChangeType(commitMessage) {
19+
console.log(`Analyzing commit message: "${commitMessage}"`);
20+
21+
// Search for keywords to determine change type. This is best effort and intended to be reviewed at PR time.
22+
if (/breaking|major/i.test(commitMessage)) {
23+
return 'major';
24+
} else {
25+
return 'patch';
26+
}
27+
}
28+
29+
function getLatestCommitMessage() {
30+
const commitMessage = execSync('git log -1 --pretty=format:"%s"', { encoding: 'utf8' }).trim();
31+
return commitMessage.replace(/^"|"$/g, ''); // Remove surrounding quotes if present
32+
}
33+
34+
function createBeachballChangeFile(commitMessage, changeType) {
35+
console.log(`Creating beachball change file with type: ${changeType}`);
36+
37+
try {
38+
// Create change file using beachball CLI
39+
execSync('git config --local user.email "[email protected]"');
40+
execSync('git config --local user.name "mc-npm"');
41+
42+
execSync(`npx beachball change --type "${changeType}" --message "${commitMessage}"`, {
43+
encoding: 'utf8',
44+
stdio: 'inherit',
45+
});
46+
47+
console.log('✅ Successfully created and committed beachball change files');
48+
return true;
49+
} catch (error) {
50+
console.error('❌ Failed to create beachball change file:', error.message);
51+
return false;
52+
}
53+
}
54+
55+
try {
56+
const isDryRun = process.argv.includes('-n');
57+
console.log('🤖 Starting dependabot beachball change file automation...');
58+
59+
// Step 1: Check if beachball change files are needed
60+
const needsChange = checkIfBeachballChangeNeeded();
61+
62+
if (!needsChange) {
63+
process.exit(0);
64+
}
65+
66+
// Step 2: Get commit message and determine change type
67+
const commitMessage = getLatestCommitMessage();
68+
const changeType = determineChangeType(commitMessage);
69+
70+
console.log(`📝 Commit message: "${commitMessage}"`);
71+
console.log(`📊 Determined change type: ${changeType}`);
72+
73+
// Step 3: Create beachball change file
74+
const changeFileCreated = createBeachballChangeFile(commitMessage, changeType, isDryRun);
75+
76+
if (!changeFileCreated) {
77+
console.error('❌ Failed to create change file');
78+
process.exit(1);
79+
}
80+
81+
console.log('🎉 Successfully automated beachball change file creation! Pushing changes.');
82+
if (!isDryRun) {
83+
execSync('git push');
84+
}
85+
} catch (error) {
86+
console.error('❌ Error in dependabot beachball automation:', error.message);
87+
console.error(error.stack);
88+
process.exit(1);
89+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Dependabot Beachball Change Files
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
dependabot-beachball:
9+
runs-on: ubuntu-latest
10+
if: github.event.sender.login == 'dependabot[bot]'
11+
permissions:
12+
contents: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Use Node.js 22.x
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 22
20+
21+
- run: npm ci
22+
23+
- name: Run dependabot beachball automation
24+
run: node .github/scripts/dependabot-beachball.mjs

0 commit comments

Comments
 (0)