From 0c2abf5633c0a3c18029397682d5033dbd837834 Mon Sep 17 00:00:00 2001 From: Nathan Ahn Date: Sat, 12 Jul 2025 13:27:44 -0400 Subject: [PATCH] Fixes --- dist/setup/index.js | 2 +- src/action.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index b297878..d7c2b75 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -66,7 +66,7 @@ Other caches with similar key:`);for(let p of n?.artifactCaches||[])fa.debug(`Ca `:a+=" "+i.join(", ")+(i.length>0?" ":""),a+"]"}o(xF,"stringifyInlineArray");function bF(t){t=Lu(t);var e=[];return Object.keys(t).forEach(a=>{e.push(qu(a)+" = "+O_(t[a],!1))}),"{ "+e.join(", ")+(e.length>0?" ":"")+"}"}o(bF,"stringifyInlineTable");function wF(t,e,a,i){var r=oa(i);if(r==="array")return NF(t,e,a,i);if(r==="table")return _F(t,e,a,i);throw hn(r)}o(wF,"stringifyComplex");function NF(t,e,a,i){i=Lu(i),P_(i);var r=oa(i[0]);if(r!=="table")throw hn(r);var n=t+qu(a),s="";return i.forEach(p=>{s.length>0&&(s+=` `),s+=e+"[["+n+`]] `,s+=u6(n+".",e,p)}),s}o(NF,"stringifyArrayOfTables");function _F(t,e,a,i){var r=t+qu(a),n="";return S_(i).length>0&&(n+=e+"["+r+`] -`),n+u6(r+".",e,i)}o(_F,"stringifyComplexTable")});var D_=E(h6=>{"use strict";h6.parse=__();h6.stringify=I_()});var V_=require("node:os"),Pt=ya(rt());var q_=require("node:crypto"),v6=require("node:os"),gn=require("node:path"),bi=require("node:fs"),Ir=ya(rt()),ju=ya(BN()),Hp=ya(t_()),x6=ya(Sn());var Js=require("node:fs"),g6=ya(rt()),zu=ya(D_());function A_(t,e){if(!e.length)return;let a=0;if(e.forEach(n=>{try{new URL(n.url)}catch{throw new Error(`Invalid registry URL: ${n.url}`)}n.scope||a++}),a>1)throw new Error("You can't have more than one global registry.");(0,g6.info)(`Writing bunfig.toml to '${t}'.`);let i={};if((0,Js.existsSync)(t))try{let n=(0,Js.readFileSync)(t,{encoding:"utf-8"});i=(0,zu.parse)(n)}catch(n){(0,g6.info)(`Error reading existing bunfig: ${n.message}`),i={}}i.install=i?.install||{},i.install.scopes=i?.install.scopes||{};let r=e.find(n=>!n.scope);r&&(i.install.registry={url:r.url,...r.token?{token:r.token}:{}});for(let n of e)if(n.scope){let s=n.scope.startsWith("@")?n.scope.toLowerCase():`@${n.scope.toLowerCase()}`;i.install.scopes[s]={url:n.url,...n.token?{token:n.token}:{}}}Object.keys(i.install.scopes).length===0&&delete i.install.scopes,(0,Js.writeFileSync)(t,(0,zu.stringify)(i),{encoding:"utf8"})}o(A_,"writeBunfig");var z_=ya(rt());var Zs=ya(rt()),B_=require("node:console"),eo=require("node:fs"),ku=require("node:path");function y6(t,e,a=1e4){return t().catch(i=>{if(e<=0)throw i;return new Promise(r=>setTimeout(r,a)).then(()=>y6(t,e-1,a))})}o(y6,"retry");function M_(t,e){return t.endsWith(e)?t:((0,eo.renameSync)(t,t+e),t+e)}o(M_,"addExtension");var SF={"package.json":t=>{let e=JSON.parse(t);return e.packageManager?.split("bun@")?.[1]??e.engines?.bun},".tool-versions":t=>t.match(/^bun\s*(?.*?)$/m)?.groups?.version,".bumrc":t=>t,".bun-version":t=>t};function L_(t){let e=process.env.GITHUB_WORKSPACE;if(!e||!t)return;(0,Zs.debug)(`Reading version from ${t}`);let a=(0,ku.resolve)(e,t),i=(0,ku.basename)(t);if(!(0,eo.existsSync)(a)){(0,Zs.warning)(`File ${a} not found`);return}let r=SF[i]??(()=>{}),n;try{if(n=r((0,eo.readFileSync)(a,"utf8"))?.trim(),!n){(0,Zs.warning)(`Failed to read version from ${t}`);return}}catch(s){let{message:p}=s;(0,Zs.warning)(`Failed to read ${t}: ${p}`)}finally{if(n)return(0,B_.info)(`Obtained version ${n} from ${t}`),n}}o(L_,"readVersionFromFile");var k_=require("node:process");var j_=o(async t=>{let e=(0,gn.join)((0,k_.cwd)(),"bunfig.toml");A_(e,t.registries);let a=TF(t),i=EF(t),r=(0,gn.join)((0,v6.homedir)(),".bun","bin"),n=(0,gn.join)((0,v6.homedir)(),".bun","cache");try{(0,bi.mkdirSync)(r,{recursive:!0})}catch(h){if(h.code!=="EEXIST")throw h}(0,Ir.addPath)(r);let s=o(h=>process.platform==="win32"?`${h}.exe`:h,"exe"),p=(0,gn.join)(r,s("bun"));try{(0,bi.symlinkSync)(p,(0,gn.join)(r,s("bunx")))}catch(h){if(h.code!=="EEXIST")throw h}let l,d=!1,c=(0,q_.createHash)("sha1").update(a).digest("base64"),u=`${c}-${t.extraKey??"default"}`;if(i){let h=await(0,ju.restoreCache)([p,n],u,[c]);h&&(l=await H_(p),l?((0,Ir.info)(`Using a cached version of Bun: ${l}`),h===u&&((0,Ir.info)(`Cache hit with key: ${h}`),d=!0)):(0,Ir.warning)(`Found a cached version of Bun: ${l} (but it appears to be corrupted?)`))}if(d||((0,Ir.info)(`Downloading a new version of Bun: ${a}`),l=await y6(async()=>await CF(a,p),3)),!l)throw new Error("Downloaded a new version of Bun, but failed to check its version? Try again.");let[m]=l.split("+");return(0,z_.saveState)("cache",JSON.stringify({cacheEnabled:i,cacheHit:d,bunPath:p,url:a,cacheKey:u})),{version:m,revision:l,bunPath:p,url:a,cacheHit:d}},"default");async function CF(t,e){let a=M_(await(0,Hp.downloadTool)(t),".zip"),i=await(0,Hp.extractZip)(a),r=await b6(i);try{(0,bi.renameSync)(r,e)}catch{(0,bi.copyFileSync)(r,e)}return await H_(e)}o(CF,"downloadBun");function EF(t){let{customUrl:e,version:a,noCache:i}=t;return i||e||!a||/latest|canary|action/i.test(a)?!1:(0,ju.isFeatureAvailable)()}o(EF,"isCacheEnabled");function TF(t){let{customUrl:e}=t;if(e)return e;let{version:a,os:i,arch:r,avx2:n,profile:s}=t,p=encodeURIComponent(a??"latest"),l=encodeURIComponent(i??process.platform),d=encodeURIComponent(r??process.arch),c=encodeURIComponent(n??!0),u=encodeURIComponent(s??!1),{href:m}=new URL(`${p}/${l}/${d}?avx2=${c}&profile=${u}`,"https://bun.sh/download/");return m}o(TF,"getDownloadUrl");async function b6(t){for(let e of(0,bi.readdirSync)(t,{withFileTypes:!0})){let{name:a}=e,i=(0,gn.join)(t,a);if(e.isFile()){if(a==="bun"||a==="bun.exe")return i;if(/^bun.*\.zip/.test(a)){let r=await(0,Hp.extractZip)(i);return b6(r)}}if(/^bun/.test(a)&&e.isDirectory())return b6(i)}throw new Error("Could not find executable: bun")}o(b6,"extractBun");async function H_(t){let e=await(0,x6.getExecOutput)(t,["--revision"],{ignoreReturnCode:!0});if(e.exitCode===0&&/^\d+\.\d+\.\d+/.test(e.stdout))return e.stdout.trim();let a=await(0,x6.getExecOutput)(t,["--version"],{ignoreReturnCode:!0});if(a.exitCode===0&&/^\d+\.\d+\.\d+/.test(a.stdout))return a.stdout.trim()}o(H_,"getRevision");function U_(t){return t?.trim()?t.split(` +`),n+u6(r+".",e,i)}o(_F,"stringifyComplexTable")});var D_=E(h6=>{"use strict";h6.parse=__();h6.stringify=I_()});var V_=require("node:os"),Pt=ya(rt());var q_=require("node:crypto"),v6=require("node:os"),gn=require("node:path"),bi=require("node:fs"),Ir=ya(rt()),ju=ya(BN()),Hp=ya(t_()),x6=ya(Sn());var Js=require("node:fs"),g6=ya(rt()),zu=ya(D_());function A_(t,e){if(!e.length)return;let a=0;if(e.forEach(n=>{try{new URL(n.url)}catch{throw new Error(`Invalid registry URL: ${n.url}`)}n.scope||a++}),a>1)throw new Error("You can't have more than one global registry.");(0,g6.info)(`Writing bunfig.toml to '${t}'.`);let i={};if((0,Js.existsSync)(t))try{let n=(0,Js.readFileSync)(t,{encoding:"utf-8"});i=(0,zu.parse)(n)}catch(n){(0,g6.info)(`Error reading existing bunfig: ${n.message}`),i={}}i.install=i?.install||{},i.install.scopes=i?.install.scopes||{};let r=e.find(n=>!n.scope);r&&(i.install.registry={url:r.url,...r.token?{token:r.token}:{}});for(let n of e)if(n.scope){let s=n.scope.startsWith("@")?n.scope.toLowerCase():`@${n.scope.toLowerCase()}`;i.install.scopes[s]={url:n.url,...n.token?{token:n.token}:{}}}Object.keys(i.install.scopes).length===0&&delete i.install.scopes,(0,Js.writeFileSync)(t,(0,zu.stringify)(i),{encoding:"utf8"})}o(A_,"writeBunfig");var z_=ya(rt());var Zs=ya(rt()),B_=require("node:console"),eo=require("node:fs"),ku=require("node:path");function y6(t,e,a=1e4){return t().catch(i=>{if(e<=0)throw i;return new Promise(r=>setTimeout(r,a)).then(()=>y6(t,e-1,a))})}o(y6,"retry");function M_(t,e){return t.endsWith(e)?t:((0,eo.renameSync)(t,t+e),t+e)}o(M_,"addExtension");var SF={"package.json":t=>{let e=JSON.parse(t);return e.packageManager?.split("bun@")?.[1]??e.engines?.bun},".tool-versions":t=>t.match(/^bun\s*(?.*?)$/m)?.groups?.version,".bumrc":t=>t,".bun-version":t=>t};function L_(t){let e=process.env.GITHUB_WORKSPACE;if(!e||!t)return;(0,Zs.debug)(`Reading version from ${t}`);let a=(0,ku.resolve)(e,t),i=(0,ku.basename)(t);if(!(0,eo.existsSync)(a)){(0,Zs.warning)(`File ${a} not found`);return}let r=SF[i]??(()=>{}),n;try{if(n=r((0,eo.readFileSync)(a,"utf8"))?.trim(),!n){(0,Zs.warning)(`Failed to read version from ${t}`);return}}catch(s){let{message:p}=s;(0,Zs.warning)(`Failed to read ${t}: ${p}`)}finally{if(n)return(0,B_.info)(`Obtained version ${n} from ${t}`),n}}o(L_,"readVersionFromFile");var k_=require("node:process");var j_=o(async t=>{let e=(0,gn.join)((0,k_.cwd)(),"bunfig.toml");A_(e,t.registries);let a=TF(t),i=EF(t),r=(0,gn.join)((0,v6.homedir)(),".bun","bin"),n=(0,gn.join)((0,v6.homedir)(),".bun","install","cache");try{(0,bi.mkdirSync)(r,{recursive:!0})}catch(x){if(x.code!=="EEXIST")throw x}(0,Ir.addPath)(r);let s=o(x=>process.platform==="win32"?`${x}.exe`:x,"exe"),p=(0,gn.join)(r,s("bun"));try{(0,bi.symlinkSync)(p,(0,gn.join)(r,s("bunx")))}catch(x){if(x.code!=="EEXIST")throw x}let l,d=!1,c=!1,u=(0,q_.createHash)("sha1").update(a).digest("base64"),m=`${u}-${t.extraKey??"default"}`;if(i){let x=await(0,ju.restoreCache)([p,n],m,[u]);x&&(l=await H_(p),l?(d=!0,(0,Ir.info)(`Using a cached version of Bun: ${l}`),x===m&&((0,Ir.info)(`Cache hit with key: ${x}`),c=!0)):(0,Ir.warning)(`Found a cached version of Bun: ${l} (but it appears to be corrupted?)`))}if(d||((0,Ir.info)(`Downloading a new version of Bun: ${a}`),l=await y6(async()=>await CF(a,p),3)),!l)throw new Error("Downloaded a new version of Bun, but failed to check its version? Try again.");let[f]=l.split("+");return(0,z_.saveState)("cache",JSON.stringify({cacheEnabled:i,cacheHit:c,bunPath:p,url:a,cacheKey:m})),{version:f,revision:l,bunPath:p,url:a,cacheHit:c}},"default");async function CF(t,e){let a=M_(await(0,Hp.downloadTool)(t),".zip"),i=await(0,Hp.extractZip)(a),r=await b6(i);try{(0,bi.renameSync)(r,e)}catch{(0,bi.copyFileSync)(r,e)}return await H_(e)}o(CF,"downloadBun");function EF(t){let{customUrl:e,version:a,noCache:i}=t;return i||e||!a||/latest|canary|action/i.test(a)?!1:(0,ju.isFeatureAvailable)()}o(EF,"isCacheEnabled");function TF(t){let{customUrl:e}=t;if(e)return e;let{version:a,os:i,arch:r,avx2:n,profile:s}=t,p=encodeURIComponent(a??"latest"),l=encodeURIComponent(i??process.platform),d=encodeURIComponent(r??process.arch),c=encodeURIComponent(n??!0),u=encodeURIComponent(s??!1),{href:m}=new URL(`${p}/${l}/${d}?avx2=${c}&profile=${u}`,"https://bun.sh/download/");return m}o(TF,"getDownloadUrl");async function b6(t){for(let e of(0,bi.readdirSync)(t,{withFileTypes:!0})){let{name:a}=e,i=(0,gn.join)(t,a);if(e.isFile()){if(a==="bun"||a==="bun.exe")return i;if(/^bun.*\.zip/.test(a)){let r=await(0,Hp.extractZip)(i);return b6(r)}}if(/^bun/.test(a)&&e.isDirectory())return b6(i)}throw new Error("Could not find executable: bun")}o(b6,"extractBun");async function H_(t){let e=await(0,x6.getExecOutput)(t,["--revision"],{ignoreReturnCode:!0});if(e.exitCode===0&&/^\d+\.\d+\.\d+/.test(e.stdout))return e.stdout.trim();let a=await(0,x6.getExecOutput)(t,["--version"],{ignoreReturnCode:!0});if(a.exitCode===0&&/^\d+\.\d+\.\d+/.test(a.stdout))return a.stdout.trim()}o(H_,"getRevision");function U_(t){return t?.trim()?t.split(` `).map(e=>e.trim()).filter(Boolean).map(OF).filter(Boolean):[]}o(U_,"parseRegistries");function OF(t){let e=t.match(/^(@[a-z0-9-_.]+|[a-z0-9-_.]+(?=:[a-z]+:\/\/)):(.+)$/i);if(e){let a=e[1],i=e[2].trim(),[r,n]=i.split("|",2).map(s=>s?.trim());try{return new URL(r),{url:r,scope:a,...n&&{token:n}}}catch{throw new Error(`Invalid URL in registry configuration: ${r}`)}}else{let[a,i]=t.split("|",2).map(r=>r?.trim());try{return new URL(a),{url:a,scope:"",...i&&{token:i}}}catch{throw new Error(`Invalid URL in registry configuration: ${a}`)}}}o(OF,"parseLine");process.env.RUNNER_TEMP||(process.env.RUNNER_TEMP=(0,V_.tmpdir)());var $_=U_((0,Pt.getInput)("registries")),F_=(0,Pt.getInput)("registry-url"),RF=(0,Pt.getInput)("scope");F_&&$_.push({url:F_,scope:RF,token:"$BUN_AUTH_TOKEN"});j_({version:(0,Pt.getInput)("bun-version")||L_((0,Pt.getInput)("bun-version-file"))||void 0,customUrl:(0,Pt.getInput)("bun-download-url")||void 0,registries:$_,noCache:(0,Pt.getBooleanInput)("no-cache")||!1,extraKey:(0,Pt.getInput)("extra-key")||void 0}).then(({version:t,revision:e,bunPath:a,url:i,cacheHit:r})=>{(0,Pt.setOutput)("bun-version",t),(0,Pt.setOutput)("bun-revision",e),(0,Pt.setOutput)("bun-path",a),(0,Pt.setOutput)("bun-download-url",i),(0,Pt.setOutput)("cache-hit",r),process.exit(0)}).catch(t=>{(0,Pt.setFailed)(t),process.exit(1)}); /*! Bundled license information: diff --git a/src/action.ts b/src/action.ts index 6d7c099..b0b1e6d 100644 --- a/src/action.ts +++ b/src/action.ts @@ -53,7 +53,7 @@ export default async (options: Input): Promise => { const cacheEnabled = isCacheEnabled(options); const binPath = join(homedir(), ".bun", "bin"); - const cachePath = join(homedir(), ".bun", "cache"); + const cachePath = join(homedir(), ".bun", "install", "cache"); try { mkdirSync(binPath, { recursive: true }); } catch (error) { @@ -75,6 +75,7 @@ export default async (options: Input): Promise => { } let revision: string | undefined; + let cacheBaseHit = false; let cacheHit = false; const cacheKeyBase = createHash("sha1").update(url).digest("base64") @@ -84,6 +85,7 @@ export default async (options: Input): Promise => { if (cacheRestored) { revision = await getRevision(bunPath); if (revision) { + cacheBaseHit = true; info(`Using a cached version of Bun: ${revision}`); if(cacheRestored === cacheKey){ info(`Cache hit with key: ${cacheRestored}`); @@ -97,7 +99,7 @@ export default async (options: Input): Promise => { } } - if (!cacheHit) { + if (!cacheBaseHit) { info(`Downloading a new version of Bun: ${url}`); // TODO: remove this, temporary fix for https://github.com/oven-sh/setup-bun/issues/73 revision = await retry(async () => await downloadBun(url, bunPath), 3);