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:
parent
c252a3bb80
commit
7c965aebec
12 changed files with 200 additions and 18 deletions
|
@ -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, '');
|
||||
|
|
|
@ -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')
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue