mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-23 11:36:10 +08:00
Merge pull request #6 from crazy-max/buildx-getrelease
buildx: getRelease
This commit is contained in:
commit
b40e86b8f4
@ -257,6 +257,34 @@ describe('getProvenanceAttrs', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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('generateBuildSecret', () => {
|
describe('generateBuildSecret', () => {
|
||||||
test.each([
|
test.each([
|
||||||
['A_SECRET=abcdef0123456789', false, 'A_SECRET', 'abcdef0123456789', null],
|
['A_SECRET=abcdef0123456789', false, 'A_SECRET', 'abcdef0123456789', null],
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/github": "^5.1.1",
|
"@actions/github": "^5.1.1",
|
||||||
|
"@actions/http-client": "^2.0.1",
|
||||||
"csv-parse": "^5.3.3",
|
"csv-parse": "^5.3.3",
|
||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
"semver": "^7.3.8",
|
"semver": "^7.3.8",
|
||||||
|
@ -2,12 +2,20 @@ import fs from 'fs';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import * as httpm from '@actions/http-client';
|
||||||
import {parse} from 'csv-parse/sync';
|
import {parse} from 'csv-parse/sync';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
|
|
||||||
import {Docker} from './docker';
|
import {Docker} from './docker';
|
||||||
import {Context} from './context';
|
import {Context} from './context';
|
||||||
|
|
||||||
|
export interface GitHubRelease {
|
||||||
|
id: number;
|
||||||
|
tag_name: string;
|
||||||
|
html_url: string;
|
||||||
|
assets: Array<string>;
|
||||||
|
}
|
||||||
|
|
||||||
export interface BuildxOpts {
|
export interface BuildxOpts {
|
||||||
context: Context;
|
context: Context;
|
||||||
standalone?: boolean;
|
standalone?: boolean;
|
||||||
@ -204,6 +212,22 @@ export class Buildx {
|
|||||||
return `${input},builder-id=${this.context.provenanceBuilderID}`;
|
return `${input},builder-id=${this.context.provenanceBuilderID}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async getRelease(version: string): Promise<GitHubRelease> {
|
||||||
|
const url = `https://raw.githubusercontent.com/docker/buildx/master/.github/releases.json`;
|
||||||
|
const http: httpm.HttpClient = new httpm.HttpClient('docker-actions-toolkit');
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
|
||||||
public static hasLocalExporter(exporters: string[]): boolean {
|
public static hasLocalExporter(exporters: string[]): boolean {
|
||||||
return Buildx.hasExporterType('local', exporters);
|
return Buildx.hasExporterType('local', exporters);
|
||||||
}
|
}
|
||||||
|
@ -744,6 +744,7 @@ __metadata:
|
|||||||
"@actions/core": ^1.10.0
|
"@actions/core": ^1.10.0
|
||||||
"@actions/exec": ^1.1.1
|
"@actions/exec": ^1.1.1
|
||||||
"@actions/github": ^5.1.1
|
"@actions/github": ^5.1.1
|
||||||
|
"@actions/http-client": ^2.0.1
|
||||||
"@types/csv-parse": ^1.2.2
|
"@types/csv-parse": ^1.2.2
|
||||||
"@types/node": ^16.18.11
|
"@types/node": ^16.18.11
|
||||||
"@types/semver": ^7.3.13
|
"@types/semver": ^7.3.13
|
||||||
|
Loading…
Reference in New Issue
Block a user