check latest and tagged releases using releases-json

This commit is contained in:
CrazyMax
2023-01-29 16:03:29 +01:00
parent 4c84b78119
commit c26e09cbb4
4 changed files with 49 additions and 35 deletions

View File

@@ -1,12 +0,0 @@
import * as httpm from '@actions/http-client';
export interface GitHubRelease {
id: number;
tag_name: string;
}
export const getRelease = async (version: string): Promise<GitHubRelease | null> => {
const url = `https://github.com/upx/upx/releases/${version}`;
const http: httpm.HttpClient = new httpm.HttpClient('ghaction-upx');
return (await http.getJson<GitHubRelease>(url)).result;
};

View File

@@ -1,22 +1,40 @@
import * as os from 'os';
import * as path from 'path';
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();
const osArch: string = os.arch();
export async function getUPX(version: string): Promise<string> {
core.startGroup(`Checking UPX ${version} release...`);
const release: github.GitHubRelease | null = await github.getRelease(version);
if (!release) {
throw new Error(`Cannot find UPX ${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-upx/master/.github/upx-releases.json`;
const http: httpm.HttpClient = new httpm.HttpClient('ghaction-upx');
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 UPX 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 UPX release ${version} in ${url}`);
}
return releases[version];
};
export async function getUPX(version: string): Promise<string> {
const release: GitHubRelease = await getRelease(version);
const semver: string = release.tag_name.replace(/^v/, '');
core.info(`UPX ${semver} found`);
core.endGroup();
const filename = util.format('%s.%s', getName(semver), osPlat == 'win32' ? 'zip' : 'tar.xz');
const downloadUrl = util.format('https://github.com/upx/upx/releases/download/v%s/%s', semver, filename);