Skip to content

Commit c12d4c7

Browse files
committed
refactor: Improve daily updates workflow and README benchmark results
- Updated GitHub Actions workflow to create a new branch for dependency updates and check for changes before committing. - Enhanced `compare-and-update-readme.ts` to dynamically generate benchmark results based on available tools, improving maintainability and accuracy. - Adjusted logging to only display results for tools that are present, streamlining output. This refactor enhances the automation of dependency updates and the clarity of benchmark results.
1 parent 0cd388c commit c12d4c7

File tree

2 files changed

+51
-27
lines changed

2 files changed

+51
-27
lines changed

.github/workflows/daily-updates.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,29 +108,43 @@ jobs:
108108
with:
109109
name: updated-files
110110

111-
- name: Commit and push changes
111+
- name: Create branch and commit changes
112+
id: commit
112113
run: |
114+
# Configure git
113115
git config --local user.email "action@github.com"
114116
git config --local user.name "GitHub Action"
117+
118+
# Create and switch to new branch
119+
BRANCH_NAME="dependencies/update-$(date '+%Y-%m-%d')"
120+
git checkout -b "$BRANCH_NAME"
121+
122+
# Stage all changes
115123
git add -A
116-
git commit -m "⬆️ Update dependencies to latest versions - $(date '+%Y-%m-%d')" || exit 0
117-
git pull --rebase origin main
118-
git push
124+
125+
# Check if there are actually changes to commit
126+
if git diff --cached --quiet; then
127+
echo "No changes to commit"
128+
echo "has-commits=false" >> $GITHUB_OUTPUT
129+
exit 0
130+
fi
131+
132+
# Commit changes
133+
git commit -m "⬆️ Update dependencies to latest versions - $(date '+%Y-%m-%d')"
134+
135+
# Push branch
136+
git push origin "$BRANCH_NAME"
137+
138+
echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
139+
echo "has-commits=true" >> $GITHUB_OUTPUT
119140
120141
- name: Create PR for dependency updates
142+
if: steps.commit.outputs.has-commits == 'true'
121143
uses: actions/github-script@v7
122144
with:
123145
github-token: ${{ secrets.PAT_TOKEN }}
124146
script: |
125-
const branchName = `dependencies/update-${new Date().toISOString().split('T')[0]}`;
126-
127-
// Create branch
128-
await github.rest.git.createRef({
129-
owner: context.repo.owner,
130-
repo: context.repo.repo,
131-
ref: `refs/heads/${branchName}`,
132-
sha: context.sha
133-
});
147+
const branchName = '${{ steps.commit.outputs.branch-name }}';
134148
135149
// Create PR
136150
await github.rest.pulls.create({

scripts/compare-and-update-readme.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as fs from 'fs';
2-
import * as path from 'path';
1+
import * as fs from 'node:fs';
2+
import * as path from 'node:path';
33
import type { BenchmarkResults, ComparisonOutputs, ToolName } from './types';
44

55
// Threshold for significant performance change (10%)
@@ -54,20 +54,26 @@ function formatResults(results: BenchmarkResults): string {
5454
})
5555
.join('\n');
5656

57+
// Generate tool results list dynamically based on available tools
58+
const toolOrder = ['lage', 'turbo', 'lerna', 'moon', 'nx'];
59+
const toolResults = toolOrder
60+
.filter((tool) => results.tools[tool as ToolName])
61+
.map((tool) => {
62+
const toolLabel = tool === 'lerna' ? 'lerna (powered by nx)' : tool;
63+
return `* average ${toolLabel} time is: ${results.tools[
64+
tool as ToolName
65+
].average.toFixed(1)}`;
66+
})
67+
.join('\n');
68+
5769
return `## Benchmark & Results (${date})
5870
5971
Run \`pnpm run benchmark\`. The benchmark will warm the cache of all the tools. We benchmark how quickly
6072
Turbo/Nx/Lerna/Lage/Moon can figure out what needs to be restored from the cache and restores it.
6173
6274
These are the numbers using GitHub Actions runner:
6375
64-
* average lage time is: ${results.tools.lage.average.toFixed(1)}
65-
* average turbo time is: ${results.tools.turbo.average.toFixed(1)}
66-
* average lerna (powered by nx) time is: ${results.tools.lerna.average.toFixed(
67-
1
68-
)}
69-
* average moon time is: ${results.tools.moon.average.toFixed(1)}
70-
* average nx time is: ${results.tools.nx.average.toFixed(1)}
76+
${toolResults}
7177
${comparisons}`;
7278
}
7379

@@ -232,11 +238,15 @@ function main(): ComparisonOutputs {
232238

233239
// Log current results for debugging
234240
console.log('Current benchmark results:');
235-
console.log(`- NX: ${currentResults.tools.nx.average.toFixed(1)}ms`);
236-
console.log(`- Turbo: ${currentResults.tools.turbo.average.toFixed(1)}ms`);
237-
console.log(`- Lerna: ${currentResults.tools.lerna.average.toFixed(1)}ms`);
238-
console.log(`- Lage: ${currentResults.tools.lage.average.toFixed(1)}ms`);
239-
console.log(`- Moon: ${currentResults.tools.moon.average.toFixed(1)}ms`);
241+
const availableTools: ToolName[] = ['nx', 'turbo', 'lerna', 'lage', 'moon'];
242+
availableTools.forEach((tool) => {
243+
if (currentResults.tools[tool]) {
244+
const toolLabel = tool.toUpperCase();
245+
console.log(
246+
`- ${toolLabel}: ${currentResults.tools[tool].average.toFixed(1)}ms`
247+
);
248+
}
249+
});
240250

241251
return {
242252
readmeUpdated: shouldUpdate,

0 commit comments

Comments
 (0)