@@ -13,8 +13,8 @@ import { downloadTool, extractZip } from "@actions/tool-cache";
13
13
import { getExecOutput } from "@actions/exec" ;
14
14
import { writeBunfig } from "./bunfig" ;
15
15
import { saveState } from "@actions/core" ;
16
- import { addExtension , getArchitecture , getPlatform , request } from "./utils" ;
17
- import { compareVersions , satisfies , validate } from "compare-versions " ;
16
+ import { addExtension } from "./utils" ;
17
+ import { DownloadMeta , getDownloadMeta } from "./download-url " ;
18
18
19
19
export type Input = {
20
20
customUrl ?: string ;
@@ -48,7 +48,9 @@ export default async (options: Input): Promise<Output> => {
48
48
const bunfigPath = join ( process . cwd ( ) , "bunfig.toml" ) ;
49
49
writeBunfig ( bunfigPath , options ) ;
50
50
51
- const url = await getDownloadUrl ( options ) ;
51
+ const downloadMeta = await getDownloadMeta ( options ) ;
52
+ const url = downloadMeta . url ;
53
+
52
54
const cacheEnabled = isCacheEnabled ( options ) ;
53
55
54
56
const binPath = join ( homedir ( ) , ".bun" , "bin" ) ;
@@ -91,7 +93,7 @@ export default async (options: Input): Promise<Output> => {
91
93
92
94
if ( ! cacheHit ) {
93
95
info ( `Downloading a new version of Bun: ${ url } ` ) ;
94
- revision = await downloadBun ( url , bunPath ) ;
96
+ revision = await downloadBun ( downloadMeta , bunPath ) ;
95
97
}
96
98
97
99
if ( ! revision ) {
@@ -121,11 +123,18 @@ export default async (options: Input): Promise<Output> => {
121
123
} ;
122
124
123
125
async function downloadBun (
124
- url : string ,
126
+ downloadMeta : DownloadMeta ,
125
127
bunPath : string
126
128
) : Promise < string | undefined > {
127
129
// Workaround for https://github.com/oven-sh/setup-bun/issues/79 and https://github.com/actions/toolkit/issues/1179
128
- const zipPath = addExtension ( await downloadTool ( url ) , ".zip" ) ;
130
+ const zipPath = addExtension (
131
+ await downloadTool (
132
+ downloadMeta . url ,
133
+ undefined ,
134
+ downloadMeta . auth ?? undefined
135
+ ) ,
136
+ ".zip"
137
+ ) ;
129
138
const extractedZipPath = await extractZip ( zipPath ) ;
130
139
const extractedBunPath = await extractBun ( extractedZipPath ) ;
131
140
try {
@@ -153,52 +162,6 @@ function isCacheEnabled(options: Input): boolean {
153
162
return isFeatureAvailable ( ) ;
154
163
}
155
164
156
- async function getDownloadUrl ( options : Input ) : Promise < string > {
157
- const { customUrl } = options ;
158
- if ( customUrl ) {
159
- return customUrl ;
160
- }
161
-
162
- const res = ( await (
163
- await request ( "https://api.github.com/repos/oven-sh/bun/git/refs/tags" , {
164
- headers : {
165
- "Authorization" : `Bearer ${ options . token } ` ,
166
- } ,
167
- } )
168
- ) . json ( ) ) as { ref : string } [ ] ;
169
- let tags = res
170
- . filter (
171
- ( tag ) =>
172
- tag . ref . startsWith ( "refs/tags/bun-v" ) || tag . ref === "refs/tags/canary"
173
- )
174
- . map ( ( item ) => item . ref . replace ( / r e f s \/ t a g s \/ ( b u n - v ) ? / g, "" ) ) ;
175
-
176
- const { version, os, arch, avx2, profile } = options ;
177
-
178
- let tag = tags . find ( ( t ) => t === version ) ;
179
- if ( ! tag ) {
180
- tags = tags . filter ( ( t ) => validate ( t ) ) . sort ( compareVersions ) ;
181
-
182
- if ( version === "latest" ) tag = `bun-v${ tags . at ( - 1 ) } ` ;
183
- else tag = `bun-v${ tags . filter ( ( t ) => satisfies ( t , version ) ) . at ( - 1 ) } ` ;
184
- } else if ( validate ( tag ) ) {
185
- tag = `bun-v${ tag } ` ;
186
- }
187
-
188
- const eversion = encodeURIComponent ( tag ?? version ) ;
189
- const eos = encodeURIComponent ( os ?? getPlatform ( ) ) ;
190
- const earch = encodeURIComponent ( arch ?? getArchitecture ( ) ) ;
191
- const eavx2 = encodeURIComponent ( avx2 ? "-baseline" : "" ) ;
192
- const eprofile = encodeURIComponent ( profile ? "-profile" : "" ) ;
193
-
194
- const { href } = new URL (
195
- `${ eversion } /bun-${ eos } -${ earch } ${ eavx2 } ${ eprofile } .zip` ,
196
- "https://github.com/oven-sh/bun/releases/download/"
197
- ) ;
198
-
199
- return href ;
200
- }
201
-
202
165
async function extractBun ( path : string ) : Promise < string > {
203
166
for ( const entry of readdirSync ( path , { withFileTypes : true } ) ) {
204
167
const { name } = entry ;
0 commit comments