Skip to content

Commit 193c803

Browse files
committed
fix: build falure due to node download in github workflow
1 parent 540f6ed commit 193c803

3 files changed

Lines changed: 61 additions & 11 deletions

File tree

package-lock.json

Lines changed: 42 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@
4848
"fs-extra": "11.2.0",
4949
"shx": "^0.3.4",
5050
"tar": "6.2.0",
51-
"axios": "1.6.7"
51+
"axios": "1.6.7",
52+
"axios-retry": "4.0.0"
5253
},
5354
"phoenixRepo": {
5455
"gitClonrUrl": "https://github.com/phcode-dev/phoenix.git",
5556
"branch": "tauri",
5657
"commit": "35ffea70f6b9f98870a1a8970c030acb939fc781"
5758
}
58-
}
59+
}

src-build/downloadNodeBinary.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ import {dirname} from 'path';
77
import * as fsExtra from "fs-extra";
88
import {getPlatformDetails, getSideCarBinName, removeDir} from "./utils.js";
99
import axios from 'axios';
10-
10+
import axiosRetry from 'axios-retry';
1111
const __filename = fileURLToPath(import.meta.url);
1212
const __dirname = dirname(__filename);
1313

14+
// Setup axios-retry
15+
axiosRetry(axios, {
16+
retries: 3,
17+
retryDelay: axiosRetry.exponentialDelay,
18+
retryCondition: (error) => error.code === 'ECONNABORTED' || /5\d{2}/.test(error.response?.status)
19+
});
1420
/**
1521
* Downloads the latest Node.js binary for the specified platform and architecture.
1622
* If the file already exists, it will not be downloaded again. If the download fails,
@@ -46,7 +52,7 @@ async function downloadNodeBinary(platform, arch, maxRetries = 3) {
4652

4753
const outputPath = path.resolve(__dirname, asset.name);
4854
if (fs.existsSync(outputPath)) {
49-
console.log('File already downloaded:', asset.name);
55+
console.log(`File already downloaded: ${asset.name}`);
5056
return asset.name;
5157
}
5258

@@ -62,19 +68,22 @@ async function downloadNodeBinary(platform, arch, maxRetries = 3) {
6268

6369
return new Promise((resolve, reject) => {
6470
writer.on('finish', () => {
65-
console.log('Download completed:', asset.name);
71+
console.log(`Download completed: ${asset.name}`);
6672
resolve(asset.name);
6773
});
68-
writer.on('error', err => {
69-
fs.unlinkSync(outputPath); // remove the partially downloaded file
74+
writer.on('error', (err) => {
75+
fs.unlink(outputPath, (unlinkErr) => {
76+
if (unlinkErr) console.error(`Error removing incomplete download: ${unlinkErr}`);
77+
});
7078
reject(err);
7179
});
7280
});
7381

7482
} catch (err) {
75-
console.error('Error:', err.message);
83+
console.error(`Error: ${err.message}`);
7684
if (maxRetries > 0) {
7785
console.log('Retrying download...');
86+
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait before retrying
7887
return downloadNodeBinary(platform, arch, maxRetries - 1);
7988
} else {
8089
throw new Error('Max retries reached, download failed.');
@@ -230,4 +239,4 @@ console.log(args);
230239
const platformDetails = (args.length === 1) ? JSON.parse(args[0]) : getPlatformDetails();
231240
console.log(platformDetails);
232241

233-
await copyLatestNodeForBuild(platformDetails.platform, platformDetails.arch);
242+
await copyLatestNodeForBuild(platformDetails.platform, platformDetails.arch);

0 commit comments

Comments
 (0)