Skip to content

Commit

Permalink
fix: accidental download count reset in github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Oct 20, 2024
1 parent aa3f722 commit 1a0443d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions build/downloadCounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 1a0443d

Please sign in to comment.