Skip to content

Commit

Permalink
fix: save script to tmp file
Browse files Browse the repository at this point in the history
  • Loading branch information
hexnickk4997 committed Jan 9, 2024
1 parent 0bec49d commit 28835d9
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions .github/workflows/fetch-audits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,32 @@ jobs:
with:
node-version: '18'

- name: Create JavaScript file
- name: Create fetcher script
run: |
cat <<EOF | node
const API_URL = `https://api.github.com/repos/lidofinance/audits/contents/`;
async function countPdfFiles(path = '') {
const response = await fetch(API_URL + path);
const data = await response.json();
let count = 0;
for (const item of data) {
if (item.type === 'file' && item.name.endsWith('.pdf')) {
count++;
} else if (item.type === 'dir') {
count += await countPdfFiles(item.path);
}
}
return count;
}
countPdfFiles().then(count => {
console.log(`count: ${count}`);
});
EOF
cat <<EOF > /tmp/fetch-audits.js
const API_URL = 'https://api.github.com/repos/lidofinance/audits/contents/';

async function countPdfFiles(path = '') {
const response = await fetch(API_URL + path);
const data = await response.json();
let count = 0;

for (const item of data) {
if (item.type === 'file' && item.name.endsWith('.pdf')) {
count++;
} else if (item.type === 'dir') {
count += await countPdfFiles(item.path);
}
}

return count;
}

countPdfFiles().then(count => {
console.log(`count: ${count}`);
});

EOF

- name: Execute fetcher script
run: node /tmp/fetch-audits.js

0 comments on commit 28835d9

Please sign in to comment.