Skip to content

Commit

Permalink
Add auto update with better messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaellatman committed Nov 27, 2024
1 parent 5e0c5bd commit 7d32a20
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
35 changes: 31 additions & 4 deletions .github/workflows/update-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Update Package List
on:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight
push:
branches:
- main
workflow_dispatch: # Allows manual triggering

permissions:
Expand Down Expand Up @@ -33,17 +36,41 @@ jobs:
run: |
git diff --exit-code packages/package-list.json || echo "changes=true" >> $GITHUB_OUTPUT
- name: Read commit message
id: commit-msg
if: steps.git-check.outputs.changes == 'true'
run: |
if [ -f "temp/commit-msg.txt" ]; then
echo "message<<EOF" >> $GITHUB_OUTPUT
cat temp/commit-msg.txt >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "message=chore(packages): update MCP package list" >> $GITHUB_OUTPUT
fi
- name: Remove temp files
run: rm -rf temp

- name: Create Pull Request
if: steps.git-check.outputs.changes == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: update package list'
commit-message: ${{ steps.commit-msg.outputs.message }}
title: 'Update MCP Package List'
body: |
This PR updates the package list with new or modified MCP servers.
${{ steps.commit-msg.outputs.message }}
Changes were automatically detected and generated.
This PR was automatically generated by the package update workflow.
branch: update-package-list
base: main
delete-branch: true
delete-branch: true

- name: Merge Pull Request
if: steps.git-check.outputs.changes == 'true'
uses: peter-evans/create-or-update-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: ${{ steps.commit-msg.outputs.message }}
branch: update-package-list
base: main
35 changes: 33 additions & 2 deletions src/extractors/modelcontextprotocol-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface PackageInfo {
export async function extractPackageInfo(): Promise<PackageInfo[]> {
const tempDir = path.join(__dirname, '../../temp');
const outputPath = path.join(__dirname, '../../packages/package-list.json');
const commitMsgPath = path.join(__dirname, '../../temp/commit-msg.txt');

try {
// Load existing packages
Expand All @@ -34,6 +35,10 @@ export async function extractPackageInfo(): Promise<PackageInfo[]> {
fs.mkdirSync(tempDir, { recursive: true });
}

// Initialize commit message
let commitMsg = "chore(packages): update MCP package list\n\nChanges:\n";
let changes: string[] = [];

// Clone the repository
console.log('Cloning repository...');
await execAsync(
Expand Down Expand Up @@ -74,28 +79,54 @@ export async function extractPackageInfo(): Promise<PackageInfo[]> {
if (existingIndex >= 0) {
// Update existing package if there are changes
if (JSON.stringify(mergedPackages[existingIndex]) !== JSON.stringify(newPkg)) {
const oldPkg = mergedPackages[existingIndex];
mergedPackages[existingIndex] = newPkg;
hasChanges = true;
console.log(`Updated package: ${newPkg.name}`);

// Add detailed change information
const changeDetails = [];
if (oldPkg.description !== newPkg.description) changeDetails.push('description');
if (oldPkg.vendor !== newPkg.vendor) changeDetails.push('vendor');
if (oldPkg.license !== newPkg.license) changeDetails.push('license');
if (oldPkg.homepage !== newPkg.homepage) changeDetails.push('homepage');
if (oldPkg.sourceUrl !== newPkg.sourceUrl) changeDetails.push('sourceUrl');

changes.push(`- Updated ${newPkg.name} (changed: ${changeDetails.join(', ')})`);
}
} else {
// Add new package
mergedPackages.push(newPkg);
hasChanges = true;
console.log(`Added new package: ${newPkg.name}`);
changes.push(`- Added new package: ${newPkg.name}`);
}
}

// Write updated packages to file if there are changes
if (hasChanges) {
fs.writeFileSync(outputPath, JSON.stringify(mergedPackages, null, 2));
console.log('Package list updated successfully');

// Write commit message
if (changes.length === 0) {
changes.push('- Initial package list creation');
}
commitMsg += changes.join('\n');
fs.writeFileSync(commitMsgPath, commitMsg);
console.log('Commit message generated');
} else {
console.log('No changes detected in package list');
}

// Cleanup
fs.rmSync(tempDir, { recursive: true, force: true });
// Cleanup (but keep commit-msg.txt if it exists)
const filesToKeep = new Set(['commit-msg.txt']);
for (const file of fs.readdirSync(tempDir)) {
if (!filesToKeep.has(file)) {
const filePath = path.join(tempDir, file);
fs.rmSync(filePath, { recursive: true, force: true });
}
}
console.log('Temporary files cleaned up');

return mergedPackages;
Expand Down

0 comments on commit 7d32a20

Please sign in to comment.