support local
This commit is contained in:
+9
-1
@@ -33,9 +33,17 @@ export type RefDic = {
|
||||
>;
|
||||
};
|
||||
|
||||
export interface Version {
|
||||
export interface GitVersion {
|
||||
version: string;
|
||||
sha: Sha;
|
||||
type: keyof RefDic | 'sha';
|
||||
repo: Repo;
|
||||
}
|
||||
|
||||
export interface LocalVersion {
|
||||
type: 'local';
|
||||
path: string;
|
||||
version: undefined;
|
||||
}
|
||||
|
||||
export type Version = GitVersion | LocalVersion;
|
||||
|
||||
+35
-21
@@ -1,32 +1,46 @@
|
||||
import * as core from '@actions/core';
|
||||
import core from '@actions/core';
|
||||
import { exec } from '@actions/exec';
|
||||
import * as io from '@actions/io';
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import io from '@actions/io';
|
||||
import toolCache from '@actions/tool-cache';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import semver from 'semver';
|
||||
import * as git from './git';
|
||||
import { Version } from './interfaces';
|
||||
|
||||
async function install(sourceDir: string, binDir: string): Promise<void> {
|
||||
await exec('make', ['build'], { cwd: sourceDir });
|
||||
await exec('make', ['install', `prefix=${binDir}`], { cwd: sourceDir });
|
||||
}
|
||||
|
||||
export async function unixInstall(version: Version): Promise<void> {
|
||||
const ver = version.version;
|
||||
let toolDir = toolCache.find('xmake', ver);
|
||||
if (!toolDir) {
|
||||
const sourceDir = await core.group(`download xmake ${String(version)}`, () =>
|
||||
git.create(version.repo, version.sha),
|
||||
);
|
||||
toolDir = await core.group(`install xmake ${String(version)}`, async () => {
|
||||
await exec('make', ['build'], { cwd: sourceDir });
|
||||
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
|
||||
await exec('make', ['install', `prefix=${binDir}`], { cwd: sourceDir });
|
||||
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', ver);
|
||||
await io.rmRF(binDir);
|
||||
await git.cleanup(version.sha);
|
||||
return cacheDir;
|
||||
let toolDir: string;
|
||||
if (version.type !== 'local') {
|
||||
const ver = version.version;
|
||||
toolDir = toolCache.find('xmake', ver);
|
||||
if (!toolDir) {
|
||||
const sourceDir = await core.group(`download xmake ${String(version)}`, () =>
|
||||
git.create(version.repo, version.sha),
|
||||
);
|
||||
toolDir = await core.group(`install xmake ${String(version)}`, async () => {
|
||||
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
|
||||
await install(sourceDir, binDir);
|
||||
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', ver);
|
||||
await io.rmRF(binDir);
|
||||
await git.cleanup(version.sha);
|
||||
return cacheDir;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// no tool cache for local install
|
||||
toolDir = await core.group(`install local xmake at '${version.path}'`, async () => {
|
||||
const binDir = path.join(os.tmpdir(), `xmake-${Date.now()}`);
|
||||
await install(version.path, binDir);
|
||||
return binDir;
|
||||
});
|
||||
}
|
||||
// for versions 2.3.2 and above, xmake will be installed directly into the bin directory, and no script will be used to wrap it.
|
||||
if (version.type !== 'tags' || semver.gt(ver, '2.3.1')) {
|
||||
if (version.type !== 'tags' || semver.gt(version.version, '2.3.1')) {
|
||||
core.addPath(path.join(toolDir, 'bin'));
|
||||
} else {
|
||||
core.addPath(path.join(toolDir, 'share', 'xmake')); // only for <= 2.3.1
|
||||
|
||||
@@ -271,6 +271,7 @@ jest.mock('./git', () => ({
|
||||
}));
|
||||
import { selectVersion } from './versions';
|
||||
import { Repo } from './interfaces';
|
||||
import { resolve } from 'path';
|
||||
|
||||
describe('selectVersion', () => {
|
||||
it('should return correct version for latest', async () => {
|
||||
@@ -411,4 +412,25 @@ describe('selectVersion', () => {
|
||||
type: 'heads',
|
||||
});
|
||||
});
|
||||
|
||||
it('should return local cwd', async () => {
|
||||
await expect(selectVersion('local#')).resolves.toEqual({
|
||||
path: process.cwd(),
|
||||
type: 'local',
|
||||
});
|
||||
});
|
||||
|
||||
it('should return absolute path', async () => {
|
||||
await expect(selectVersion('local#/usr/bin')).resolves.toEqual({
|
||||
path: resolve('/usr/bin'),
|
||||
type: 'local',
|
||||
});
|
||||
});
|
||||
|
||||
it('should return relative path', async () => {
|
||||
await expect(selectVersion('local#xmake')).resolves.toEqual({
|
||||
path: resolve('xmake'),
|
||||
type: 'local',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+33
-14
@@ -1,7 +1,8 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as semver from 'semver';
|
||||
import semver from 'semver';
|
||||
import { lsRemote } from './git';
|
||||
import { RefDic, Sha, Version, Repo } from './interfaces';
|
||||
import { RefDic, Sha, Version, Repo, GitVersion, LocalVersion } from './interfaces';
|
||||
import p from 'path';
|
||||
|
||||
const DEFAULT_REPO = Repo('xmake-io/xmake');
|
||||
|
||||
@@ -14,12 +15,12 @@ async function getVersions(repo: Repo): Promise<RefDic> {
|
||||
return result;
|
||||
}
|
||||
|
||||
class VersionImpl implements Version {
|
||||
class GitVersionImpl implements GitVersion {
|
||||
constructor(
|
||||
readonly repo: Repo,
|
||||
readonly version: string,
|
||||
readonly sha: Sha,
|
||||
readonly type: Version['type'],
|
||||
readonly type: GitVersion['type'],
|
||||
toString: string,
|
||||
) {
|
||||
this.#string = toString;
|
||||
@@ -30,10 +31,18 @@ class VersionImpl implements Version {
|
||||
}
|
||||
}
|
||||
|
||||
class LocalVersionImpl implements LocalVersion {
|
||||
readonly type = 'local';
|
||||
readonly version: undefined;
|
||||
constructor(readonly path: string) {
|
||||
this.path = p.resolve(path);
|
||||
}
|
||||
}
|
||||
|
||||
async function selectBranch(repo: Repo, branch: string): Promise<Version> {
|
||||
const versions = await getVersions(repo);
|
||||
if (branch in versions.heads) {
|
||||
return new VersionImpl(repo, branch, versions.heads[branch], 'heads', `branch ${branch}`);
|
||||
return new GitVersionImpl(repo, branch, versions.heads[branch], 'heads', `branch ${branch}`);
|
||||
}
|
||||
throw new Error(`Branch ${branch} not found`);
|
||||
}
|
||||
@@ -41,10 +50,10 @@ async function selectBranch(repo: Repo, branch: string): Promise<Version> {
|
||||
async function selectPr(repo: Repo, pr: number): Promise<Version> {
|
||||
const versions = await getVersions(repo);
|
||||
if (pr in versions.pull) {
|
||||
const prheads = versions.pull[pr];
|
||||
const sha = prheads.merge ?? prheads.head;
|
||||
const prHeads = versions.pull[pr];
|
||||
const sha = prHeads.merge ?? prHeads.head;
|
||||
if (sha) {
|
||||
return new VersionImpl(repo, `pr#${pr}`, sha, 'pull', `pull request #${pr}`);
|
||||
return new GitVersionImpl(repo, `pr#${pr}`, sha, 'pull', `pull request #${pr}`);
|
||||
}
|
||||
}
|
||||
throw new Error(`Pull requrest #${pr} not found`);
|
||||
@@ -64,7 +73,7 @@ async function selectSemver(repo: Repo, version: string): Promise<Version> {
|
||||
}
|
||||
|
||||
const sha = versions.tags[ver];
|
||||
return new VersionImpl(repo, ver, sha, 'tags', ver);
|
||||
return new GitVersionImpl(repo, ver, sha, 'tags', ver);
|
||||
}
|
||||
|
||||
async function selectSha(repo: Repo, sha: string): Promise<Version> {
|
||||
@@ -87,7 +96,7 @@ async function selectSha(repo: Repo, sha: string): Promise<Version> {
|
||||
}
|
||||
}
|
||||
return Promise.resolve(
|
||||
new VersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substr(0, 8)}`),
|
||||
new GitVersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substr(0, 8)}`),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -98,6 +107,12 @@ export async function selectVersion(version?: string): Promise<Version> {
|
||||
|
||||
let repo = DEFAULT_REPO;
|
||||
let ret: Version | undefined;
|
||||
// select local
|
||||
if (version.startsWith('local#')) {
|
||||
const path = version.slice('local#'.length);
|
||||
ret = new LocalVersionImpl(path);
|
||||
}
|
||||
|
||||
{
|
||||
const match = /^([^/#]+\/[^/#]+)#(.+)$/.exec(version);
|
||||
if (match) {
|
||||
@@ -131,9 +146,13 @@ export async function selectVersion(version?: string): Promise<Version> {
|
||||
if (!ret) {
|
||||
throw new Error(`Invalid input xmake-version ${core.getInput('xmake-version')}`);
|
||||
}
|
||||
core.info(
|
||||
`Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` +
|
||||
(repo !== DEFAULT_REPO ? ` of ${repo}` : ''),
|
||||
);
|
||||
if (ret.type === 'local') {
|
||||
core.info(`Use local xmake at '${ret.path}'`);
|
||||
} else {
|
||||
core.info(
|
||||
`Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` +
|
||||
(repo !== DEFAULT_REPO ? ` of ${repo}` : ''),
|
||||
);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
+5
-3
@@ -5,9 +5,9 @@ import * as toolCache from '@actions/tool-cache';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import { Version } from './interfaces';
|
||||
import { Version, GitVersion } from './interfaces';
|
||||
|
||||
function getInstallerUrl(version: Version): string {
|
||||
function getInstallerUrl(version: GitVersion): string {
|
||||
const ver = version.version;
|
||||
switch (version.type) {
|
||||
case 'heads': {
|
||||
@@ -30,7 +30,6 @@ function getInstallerUrl(version: Version): string {
|
||||
}
|
||||
default: {
|
||||
// check that we have tested all types
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const _: never = version.type;
|
||||
throw new Error('Unknown version type');
|
||||
}
|
||||
@@ -38,6 +37,9 @@ function getInstallerUrl(version: Version): string {
|
||||
}
|
||||
|
||||
export async function winInstall(version: Version): Promise<void> {
|
||||
if (version.type === 'local') {
|
||||
throw new Error('Local builds for windows is not supported');
|
||||
}
|
||||
const ver = version.version;
|
||||
let toolDir = toolCache.find('xmake', ver);
|
||||
if (!toolDir) {
|
||||
|
||||
Reference in New Issue
Block a user