Skip to content

Commit

Permalink
Use async promises in parallel when creating tree entries
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Harding <[email protected]>
  • Loading branch information
klutchell committed Dec 31, 2024
1 parent 57d5bf9 commit 355e372
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/flowzone.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions flowzone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1290,40 +1290,38 @@ jobs:
github-token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
script: |
const { execSync } = require('child_process');
const fs = require('fs');
const fs = require('fs').promises;
// Get modified and untracked files
const getModifiedFiles = () => {
const modifiedCmd = 'git diff --name-only';
const untrackedCmd = 'git ls-files --others --exclude-standard';
const modified = execSync(modifiedCmd).toString().trim().split('\n');
const untracked = execSync(untrackedCmd).toString().trim().split('\n');
return [...new Set([...modified, ...untracked])].filter(f => f);
return [...new Set([...modified, ...untracked])].filter(f => f != null && !!f.trim());
};
// Create tree entries for modified files
const createTreeEntries = async () => {
const entries = [];
const files = getModifiedFiles();
for (const file of files) {
const entries = await Promise.all(files.map(async (file) => {
core.info(`Creating blob for file ${file}...`);
// Read file content and create blob
const content = fs.readFileSync(file, "utf8");
const content = await fs.readFile(file, { encoding: 'utf8' });
const { data: blob } = await github.rest.git.createBlob({
...context.repo,
content: Buffer.from(content).toString("base64"),
encoding: 'base64'
});
entries.push({
return {
path: file,
mode: '100644',
type: 'blob',
sha: blob.sha
});
}
};
}));
return entries;
};
Expand Down

0 comments on commit 355e372

Please sign in to comment.