@@ -2,25 +2,64 @@ const core = require('@actions/core');
22const { exec } = require ( 'child_process' ) ;
33const axios = require ( 'axios' ) ;
44
5+ const maxAttempts = 3 ; // Maximum number of attempts for retries
6+ const waitingTime = 1000 ; // Initial waiting time in milliseconds
7+
8+
59module . exports = async function ( ) {
610 try {
711 const inputVersion = core . getInput ( 'version' ) ;
812 let latestVersion ;
913 let selectedVersion ;
1014
11- core . debug ( `🔍 looking for the latest DuckDB version.` ) ;
15+ core . debug ( `🔍 Looking for the latest DuckDB version.. .` ) ;
1216 const headers = { 'Accept' : 'application/vnd.github+json' , 'X-GitHub-Api-Version' : '2022-11-28' }
13- const res = await axios . get ( 'https://api.github.com/repos/duckdb/duckdb/releases/latest' , { headers : headers } ) ;
14- if ( res . status != 200 ) {
15- core . error ( `❌ Failed to get latest DuckDB version` ) ;
16- core . setFailed ( res . statusText ) ;
17- } else {
18- core . debug ( `✔️ Latest DuckDB version found is ${ res . data . tag_name } .` ) ;
19- latestVersion = res . data . tag_name ;
17+ // Retry logic for axios.get (up to 3 attempts)
18+ let res ;
19+ let attempt = 1 ;
20+ let success = false ;
21+ core . info ( `🔁 Attempting to get the latest DuckDB version (max attempts: ${ maxAttempts } )` ) ;
22+ while ( attempt < maxAttempts && ! success ) {
23+ core . info ( `🔁 Attempt ${ attempt } /${ maxAttempts } to get the latest DuckDB version...` ) ;
24+ try {
25+ core . info ( `🔍 Attempting to fetch latest DuckDB version from GitHub API...` ) ;
26+ res = await axios . get ( 'https://api.github.com/repos/duckdb/duckdb/releases/latest' , { headers : headers } ) ;
27+ if ( res . status === 200 ) {
28+ success = true ;
29+ core . info ( `ℹ️ Latest DuckDB version found is ${ res . data . tag_name } .` ) ;
30+ latestVersion = res . data . tag_name ;
31+ } else {
32+ if ( attempt < maxAttempts ) {
33+ core . warning ( `⚠️ Failed to get latest DuckDB version (status ${ res . status } ), attempt ${ attempt } of ${ maxAttempts } ` ) ;
34+ } else {
35+ core . error ( `❌ Failed to get latest DuckDB version (status ${ res . status } ), last attempt (${ attempt } )` ) ;
36+ }
37+ attempt ++ ;
38+ if ( attempt < maxAttempts ) {
39+ core . info ( `🔁 Retry attempt ${ attempt } ...` ) ;
40+ await new Promise ( r => setTimeout ( r , waitingTime * attempt ) ) ;
41+ }
42+ }
43+ } catch ( err ) {
44+ if ( attempt < maxAttempts ) {
45+ core . warning ( `⚠️ Attempt ${ attempt } failed: ${ err . message } ` ) ;
46+ } else {
47+ core . error ( `❌ Attempt ${ attempt } failed: ${ err . message } ` ) ;
48+ }
49+ attempt ++ ;
50+ if ( attempt < maxAttempts ) {
51+ core . info ( `🔁 Retry attempt ${ attempt } ...` ) ;
52+ await new Promise ( r => setTimeout ( r , waitingTime * attempt ) ) ;
53+ }
54+ }
55+ }
56+ if ( ! success ) {
57+ core . setFailed ( `❌ Failed to get latest DuckDB version after ${ maxAttempts } attempts.` ) ;
58+ return ;
2059 }
2160
2261 if ( inputVersion === 'latest' ) {
23- core . info ( `📦 DuckDb latest version requested : ${ latestVersion } will be installed.` ) ;
62+ core . info ( `ℹ️ DuckDb latest version requested : ${ latestVersion } will be installed.` ) ;
2463 selectedVersion = latestVersion ;
2564 }
2665 else {
@@ -53,7 +92,7 @@ module.exports = async function () {
5392 if ( stderr ) {
5493 core . debug ( stderr ) ;
5594 }
56- core . info ( `🚀 DuckDB ${ selectedVersion } successfully installed.` ) ;
95+ core . info ( `✔️ DuckDB ${ selectedVersion } successfully installed.` ) ;
5796 } ) ;
5897 } catch ( error ) {
5998 core . setFailed ( error . message ) ;
0 commit comments