Skip to content

Commit 1a0443d

Browse files
committed
fix: accidental download count reset in github actions
1 parent aa3f722 commit 1a0443d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

build/downloadCounts.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,20 @@ function computeTotalDownloads(releases) {
3131
return {totalInstallerDownloads, totalUpdaterDownloads};
3232
}
3333

34+
function isRunningInGitHubActions() {
35+
return process.env.GITHUB_ACTIONS === 'true';
36+
}
37+
3438
const DOWNLOAD_COUNTS_URL = "https://public-stats.phcode.io/generated/download_counts.json";
3539
async function getCurrentDownloadData() {
40+
if(isRunningInGitHubActions()){
41+
// in github actions, there can be times when fetch fails in the automated hourly
42+
// workflows. In that case we should fail early, else it will reset the history
43+
// if we do try catch and return null. We dont want automated workflows resetting
44+
// history.
45+
const fetchedData = await fetch(DOWNLOAD_COUNTS_URL);
46+
return fetchedData.json();
47+
}
3648
try{
3749
const fetchedData = await fetch(DOWNLOAD_COUNTS_URL);
3850
return await fetchedData.json();

build/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ async function updateDocs() {
5151
// for debugging uncomment the below lines and comment the github fetch line
5252
// fs.writeFileSync('temp/release.json', JSON.stringify(releases, null, 2)); // only do this once and comment
5353
//const releases = JSON.parse(fs.readFileSync('temp/release.json'));
54-
downloadCounts.updateDownloadStats(releases);
55-
downloadHistory.updateDownloadHistory(releases);
54+
await downloadCounts.updateDownloadStats(releases);
55+
await downloadHistory.updateDownloadHistory(releases);
5656
}
5757

5858
updateDocs();

0 commit comments

Comments
 (0)