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

use Octokit client to download buildx

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-01-28 01:43:10 +01:00
parent c252a3bb80
commit 7c965aebec
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
12 changed files with 200 additions and 18 deletions

View file

@ -237,10 +237,12 @@ export async function build(inputBuildRef: string, dest: string, standalone: boo
return setPlugin(toolPath, dest);
}
export async function install(inputVersion: string, dest: string, standalone: boolean): Promise<string> {
const release: github.GitHubRelease | null = await github.getRelease(inputVersion);
if (!release) {
throw new Error(`Cannot find buildx ${inputVersion} release`);
export async function install(inputVersion: string, githubToken: string, dest: string, standalone: boolean): Promise<string> {
let release: github.Release;
if (inputVersion == 'latest') {
release = await github.getLatestRelease(githubToken);
} else {
release = await github.getReleaseTag(inputVersion, githubToken);
}
core.debug(`Release ${release.tag_name} found`);
const version = release.tag_name.replace(/^v+|v+$/g, '');

View file

@ -36,6 +36,7 @@ export interface Inputs {
config: string;
configInline: string;
append: string;
githubToken: string;
}
export async function getInputs(): Promise<Inputs> {
@ -51,7 +52,8 @@ export async function getInputs(): Promise<Inputs> {
endpoint: core.getInput('endpoint'),
config: core.getInput('config'),
configInline: core.getInput('config-inline'),
append: core.getInput('append')
append: core.getInput('append'),
githubToken: core.getInput('github_token')
};
}

View file

@ -1,12 +1,37 @@
import * as httpm from '@actions/http-client';
import * as github from '@actions/github';
export interface GitHubRelease {
export interface Release {
id: number;
tag_name: string;
}
export const getRelease = async (version: string): Promise<GitHubRelease | null> => {
const url = `https://github.com/docker/buildx/releases/${version}`;
const http: httpm.HttpClient = new httpm.HttpClient('setup-buildx');
return (await http.getJson<GitHubRelease>(url)).result;
const [owner, repo] = 'docker/buildx'.split('/');
export const getReleaseTag = async (tag: string, githubToken: string): Promise<Release> => {
return (
await github
.getOctokit(githubToken)
.rest.repos.getReleaseByTag({
owner,
repo,
tag
})
.catch(error => {
throw new Error(`Cannot get release ${tag}: ${error}`);
})
).data as Release;
};
export const getLatestRelease = async (githubToken: string): Promise<Release> => {
return (
await github
.getOctokit(githubToken)
.rest.repos.getLatestRelease({
owner,
repo
})
.catch(error => {
throw new Error(`Cannot get latest release: ${error}`);
})
).data as Release;
};

View file

@ -42,7 +42,7 @@ async function run(): Promise<void> {
core.endGroup();
} else if (!(await buildx.isAvailable(standalone)) || inputs.version) {
core.startGroup(`Download and install buildx`);
await buildx.install(inputs.version || 'latest', standalone ? context.tmpDir() : dockerConfigHome, standalone);
await buildx.install(inputs.version || 'latest', inputs.githubToken, standalone ? context.tmpDir() : dockerConfigHome, standalone);
core.endGroup();
}