From 1a0443d9b46ff8a24adf13888f9394008676899d Mon Sep 17 00:00:00 2001 From: abose Date: Sun, 20 Oct 2024 11:26:10 +0530 Subject: [PATCH] fix: accidental download count reset in github actions --- build/downloadCounts.js | 12 ++++++++++++ build/index.js | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/build/downloadCounts.js b/build/downloadCounts.js index c6fbf6ff..b55efb2d 100644 --- a/build/downloadCounts.js +++ b/build/downloadCounts.js @@ -31,8 +31,20 @@ function computeTotalDownloads(releases) { return {totalInstallerDownloads, totalUpdaterDownloads}; } +function isRunningInGitHubActions() { + return process.env.GITHUB_ACTIONS === 'true'; +} + const DOWNLOAD_COUNTS_URL = "https://public-stats.phcode.io/generated/download_counts.json"; async function getCurrentDownloadData() { + if(isRunningInGitHubActions()){ + // in github actions, there can be times when fetch fails in the automated hourly + // workflows. In that case we should fail early, else it will reset the history + // if we do try catch and return null. We dont want automated workflows resetting + // history. + const fetchedData = await fetch(DOWNLOAD_COUNTS_URL); + return fetchedData.json(); + } try{ const fetchedData = await fetch(DOWNLOAD_COUNTS_URL); return await fetchedData.json(); diff --git a/build/index.js b/build/index.js index a5233c98..8ded9de6 100644 --- a/build/index.js +++ b/build/index.js @@ -51,8 +51,8 @@ async function updateDocs() { // for debugging uncomment the below lines and comment the github fetch line // fs.writeFileSync('temp/release.json', JSON.stringify(releases, null, 2)); // only do this once and comment //const releases = JSON.parse(fs.readFileSync('temp/release.json')); - downloadCounts.updateDownloadStats(releases); - downloadHistory.updateDownloadHistory(releases); + await downloadCounts.updateDownloadStats(releases); + await downloadHistory.updateDownloadHistory(releases); } updateDocs();