Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check latest and tagged releases using releases-json #261

Merged
merged 2 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions __tests__/github.test.ts

This file was deleted.

20 changes: 20 additions & 0 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@ import {describe, expect, it} from '@jest/globals';
import * as fs from 'fs';
import * as installer from '../src/installer';

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

it('returns v0.24.0 buildx GitHub release', async () => {
const release = await installer.getRelease('v0.24.0');
expect(release).not.toBeNull();
expect(release?.id).toEqual(88251102);
expect(release?.tag_name).toEqual('v0.24.0');
expect(release?.html_url).toEqual('https://github.com/crazy-max/xgo/releases/tag/v0.24.0');
});

it('unknown release', async () => {
await expect(installer.getRelease('foo')).rejects.toThrowError(new Error('Cannot find Xgo release foo in https://raw.githubusercontent.com/crazy-max/ghaction-xgo/master/.github/xgo-releases.json'));
});
});

describe('installer', () => {
it('acquires v0.6.0 version of xgo', async () => {
const xgo = await installer.getXgo('v0.6.0');
Expand Down
2 changes: 1 addition & 1 deletion 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.

12 changes: 0 additions & 12 deletions src/github.ts

This file was deleted.

30 changes: 25 additions & 5 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as path from 'path';
import * as os from 'os';
import * as semver from 'semver';
import * as util from 'util';
import * as github from './github';
import * as core from '@actions/core';
import * as httpm from '@actions/http-client';
import * as tc from '@actions/tool-cache';

const osPlat: string = os.platform();
Expand All @@ -15,11 +15,31 @@ export interface Xgo {
version: string;
}

export async function getXgo(version: string): Promise<Xgo> {
const release: github.GitHubRelease | null = await github.getRelease(version);
if (!release) {
throw new Error(`Cannot find xgo ${version} release`);
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/crazy-max/ghaction-xgo/master/.github/xgo-releases.json`;
const http: httpm.HttpClient = new httpm.HttpClient('ghaction-xgo');
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 Xgo 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 Xgo release ${version} in ${url}`);
}
return releases[version];
};

export async function getXgo(version: string): Promise<Xgo> {
const release: GitHubRelease = await getRelease(version);
const fullversion: string = release.tag_name.replace(/^v/, '');
core.debug(`Release found: ${release.tag_name}`);

Expand Down