From 28835d9a8295db9966cfe11f384ffb6202b384e0 Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 9 Jan 2024 17:32:07 +0100 Subject: [PATCH] fix: save script to tmp file --- .github/workflows/fetch-audits.yml | 52 ++++++++++++++++-------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/.github/workflows/fetch-audits.yml b/.github/workflows/fetch-audits.yml index 10d4713..ac5e928 100644 --- a/.github/workflows/fetch-audits.yml +++ b/.github/workflows/fetch-audits.yml @@ -19,28 +19,32 @@ jobs: with: node-version: '18' - - name: Create JavaScript file + - name: Create fetcher script run: | - cat < { - console.log(`count: ${count}`); - }); - EOF \ No newline at end of file +cat < /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