Skip to content

Commit 379311a

Browse files
authored
Merge pull request #200 from crazy-max/toolkit
Get releases from actions toolkit
2 parents 11e8a2e + 6842354 commit 379311a

File tree

7 files changed

+376
-58
lines changed

7 files changed

+376
-58
lines changed

__tests__/buildx.test.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,6 @@ describe('isAvailable', () => {
2828
});
2929
});
3030

31-
describe('getRelease', () => {
32-
it('returns latest buildx GitHub release', async () => {
33-
const release = await buildx.getRelease('latest');
34-
expect(release).not.toBeNull();
35-
expect(release?.tag_name).not.toEqual('');
36-
});
37-
38-
it('returns v0.10.1 buildx GitHub release', async () => {
39-
const release = await buildx.getRelease('v0.10.1');
40-
expect(release).not.toBeNull();
41-
expect(release?.id).toEqual(90346950);
42-
expect(release?.tag_name).toEqual('v0.10.1');
43-
expect(release?.html_url).toEqual('https://github.com/docker/buildx/releases/tag/v0.10.1');
44-
});
45-
46-
it('returns v0.2.2 buildx GitHub release', async () => {
47-
const release = await buildx.getRelease('v0.2.2');
48-
expect(release).not.toBeNull();
49-
expect(release?.id).toEqual(17671545);
50-
expect(release?.tag_name).toEqual('v0.2.2');
51-
expect(release?.html_url).toEqual('https://github.com/docker/buildx/releases/tag/v0.2.2');
52-
});
53-
54-
it('unknown release', async () => {
55-
await expect(buildx.getRelease('foo')).rejects.toThrowError(new Error('Cannot find Buildx release foo in https://raw.githubusercontent.com/docker/buildx/master/.github/releases.json'));
56-
});
57-
});
58-
5931
describe('isAvailable standalone', () => {
6032
const execSpy = jest.spyOn(exec, 'getExecOutput');
6133
buildx.isAvailable(true);

dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/licenses.txt

Lines changed: 195 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"dependencies": {
3030
"@actions/core": "^1.10.0",
3131
"@actions/exec": "^1.1.1",
32-
"@actions/http-client": "^2.0.1",
3332
"@actions/tool-cache": "^2.0.1",
33+
"@docker/actions-toolkit": "^0.1.0-beta.4",
3434
"csv-parse": "^5.3.3",
3535
"js-yaml": "^4.1.0",
3636
"semver": "^7.3.7",

src/buildx.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import * as context from './context';
66
import * as git from './git';
77
import * as core from '@actions/core';
88
import * as exec from '@actions/exec';
9-
import * as httpm from '@actions/http-client';
109
import * as tc from '@actions/tool-cache';
10+
import {Install as BuildxInstall} from '@docker/actions-toolkit/lib/buildx/install';
11+
import {GitHubRelease} from '@docker/actions-toolkit/lib/types/github';
1112

1213
export type Builder = {
1314
name?: string;
@@ -25,29 +26,6 @@ export type Node = {
2526
platforms?: string;
2627
};
2728

28-
export interface GitHubRelease {
29-
id: number;
30-
tag_name: string;
31-
html_url: string;
32-
assets: Array<string>;
33-
}
34-
35-
export const getRelease = async (version: string): Promise<GitHubRelease> => {
36-
const url = `https://raw.githubusercontent.com/docker/buildx/master/.github/releases.json`;
37-
const http: httpm.HttpClient = new httpm.HttpClient('setup-buildx');
38-
const resp: httpm.HttpClientResponse = await http.get(url);
39-
const body = await resp.readBody();
40-
const statusCode = resp.message.statusCode || 500;
41-
if (statusCode >= 400) {
42-
throw new Error(`Failed to get Buildx release ${version} from ${url} with status code ${statusCode}: ${body}`);
43-
}
44-
const releases = <Record<string, GitHubRelease>>JSON.parse(body);
45-
if (!releases[version]) {
46-
throw new Error(`Cannot find Buildx release ${version} in ${url}`);
47-
}
48-
return releases[version];
49-
};
50-
5129
export async function getConfigInline(s: string): Promise<string> {
5230
return getConfig(s, false);
5331
}
@@ -261,7 +239,7 @@ export async function build(inputBuildRef: string, dest: string, standalone: boo
261239
}
262240

263241
export async function install(inputVersion: string, dest: string, standalone: boolean): Promise<string> {
264-
const release: GitHubRelease = await getRelease(inputVersion);
242+
const release: GitHubRelease = await BuildxInstall.getRelease(inputVersion);
265243
core.debug(`Release ${release.tag_name} found`);
266244
const version = release.tag_name.replace(/^v+|v+$/g, '');
267245

0 commit comments

Comments
 (0)