Skip to content

Commit

Permalink
Merge pull request #200 from crazy-max/toolkit
Browse files Browse the repository at this point in the history
Get releases from actions toolkit
  • Loading branch information
crazy-max committed Feb 6, 2023
2 parents 11e8a2e + 6842354 commit 379311a
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 58 deletions.
28 changes: 0 additions & 28 deletions __tests__/buildx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,6 @@ describe('isAvailable', () => {
});
});

describe('getRelease', () => {
it('returns latest buildx GitHub release', async () => {
const release = await buildx.getRelease('latest');
expect(release).not.toBeNull();
expect(release?.tag_name).not.toEqual('');
});

it('returns v0.10.1 buildx GitHub release', async () => {
const release = await buildx.getRelease('v0.10.1');
expect(release).not.toBeNull();
expect(release?.id).toEqual(90346950);
expect(release?.tag_name).toEqual('v0.10.1');
expect(release?.html_url).toEqual('https://github.com/docker/buildx/releases/tag/v0.10.1');
});

it('returns v0.2.2 buildx GitHub release', async () => {
const release = await buildx.getRelease('v0.2.2');
expect(release).not.toBeNull();
expect(release?.id).toEqual(17671545);
expect(release?.tag_name).toEqual('v0.2.2');
expect(release?.html_url).toEqual('https://github.com/docker/buildx/releases/tag/v0.2.2');
});

it('unknown release', async () => {
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'));
});
});

describe('isAvailable standalone', () => {
const execSpy = jest.spyOn(exec, 'getExecOutput');
buildx.isAvailable(true);
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

195 changes: 195 additions & 0 deletions dist/licenses.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
"@actions/http-client": "^2.0.1",
"@actions/tool-cache": "^2.0.1",
"@docker/actions-toolkit": "^0.1.0-beta.4",
"csv-parse": "^5.3.3",
"js-yaml": "^4.1.0",
"semver": "^7.3.7",
Expand Down
28 changes: 3 additions & 25 deletions src/buildx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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, '');

Expand Down

0 comments on commit 379311a

Please sign in to comment.