1
0
Fork 0
mirror of https://github.com/docker/setup-buildx-action.git synced 2025-04-23 08:26:38 +02:00

Get releases from actions toolkit

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-02-03 14:51:57 +01:00
parent 7ce9a1f69d
commit 6842354d08
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
6 changed files with 201 additions and 57 deletions

View file

@ -6,8 +6,9 @@ import * as context from './context';
import * as git from './git';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as httpm from '@actions/http-client';
import * as tc from '@actions/tool-cache';
import {Install as BuildxInstall} from '@docker/actions-toolkit/lib/buildx/install';
import {GitHubRelease} from '@docker/actions-toolkit/lib/types/github';
export type Builder = {
name?: string;
@ -25,29 +26,6 @@ export type Node = {
platforms?: string;
};
export interface GitHubRelease {
id: number;
tag_name: string;
html_url: string;
assets: Array<string>;
}
export const getRelease = async (version: string): Promise<GitHubRelease> => {
const url = `https://raw.githubusercontent.com/docker/buildx/master/.github/releases.json`;
const http: httpm.HttpClient = new httpm.HttpClient('setup-buildx');
const resp: httpm.HttpClientResponse = await http.get(url);
const body = await resp.readBody();
const statusCode = resp.message.statusCode || 500;
if (statusCode >= 400) {
throw new Error(`Failed to get Buildx release ${version} from ${url} with status code ${statusCode}: ${body}`);
}
const releases = <Record<string, GitHubRelease>>JSON.parse(body);
if (!releases[version]) {
throw new Error(`Cannot find Buildx release ${version} in ${url}`);
}
return releases[version];
};
export async function getConfigInline(s: string): Promise<string> {
return getConfig(s, false);
}
@ -261,7 +239,7 @@ export async function build(inputBuildRef: string, dest: string, standalone: boo
}
export async function install(inputVersion: string, dest: string, standalone: boolean): Promise<string> {
const release: GitHubRelease = await getRelease(inputVersion);
const release: GitHubRelease = await BuildxInstall.getRelease(inputVersion);
core.debug(`Release ${release.tag_name} found`);
const version = release.tag_name.replace(/^v+|v+$/g, '');