Skip to content
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ GitHub Action that allows you to setup a V environment.
# Target architecture for V to use. Examples: linux, macos, windows. Will use system architecture by default.
architecture: ''

# Directory to install V into.
# Defaults to ~/vlang/vlang_{platform}_{arch} when not provided.
# Example: /opt/v
path: ''

# Cache the V executable to speed up subsequent runs.
# Only applies when the `version` input is specified.
# Default: true
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ inputs:
default: 'false'
architecture:
description: 'Target architecture for V to use. Examples: linux, macos, windows. Will use system architecture by default.'
path:
description: 'Directory to install V into. Defaults to ~/vlang/vlang_{platform}_{arch}'
default: ''
cache:
description: 'Cache the V executable to speed up subsequent runs. Only applies when the version input is specified.'
default: 'true'
Expand Down
15 changes: 10 additions & 5 deletions dist/index.js

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

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

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ async function run() {
arch = os.arch();
}
const useCache = strToBoolean(core.getInput('cache') || 'true');
const customPath = core.getInput('path');
if (useCache && version) {
const cacheKey = `v-${version}-${os.platform()}-${arch}`;
const installDir = installer.getInstallDir(arch);
const installDir = installer.getInstallDir(arch, customPath);
const hit = await cache.restoreCache([installDir], cacheKey);
if (hit) {
core.info(`Cache hit for V ${version}`);
Expand All @@ -86,7 +87,8 @@ async function run() {
version,
checkLatest,
stable,
arch
arch,
installPath: customPath
});
core.info('Adding v to the cache...');
const installedVersion = await getVersion(binPath);
Expand Down
29 changes: 29 additions & 0 deletions src/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import {
getInstallDir,
getVExecutable,
getWindowsBuildCommand,
resolveVersionRef
Expand Down Expand Up @@ -53,6 +54,34 @@ describe('resolveVersionRef', () => {
})
})

describe('getInstallDir', () => {
function expectedDefaultDir(arch: string = os.arch()): string {
const platformMap: Record<string, string> = {
darwin: 'macos',
win32: 'windows'
}
const osArch = platformMap[arch] || arch
return path.join(os.homedir(), 'vlang', `vlang_${os.platform()}_${osArch}`)
}

test('returns the default path when no custom path is provided', () => {
expect(getInstallDir()).toBe(expectedDefaultDir())
})

test('returns the custom path when provided', () => {
expect(getInstallDir('x64', '/opt/v')).toBe('/opt/v')
})

test('resolves a relative custom path to an absolute path', () => {
const result = getInstallDir('x64', 'custom-v')
expect(path.isAbsolute(result)).toBe(true)
})

test('ignores the custom path when it is an empty string', () => {
expect(getInstallDir('x64', '')).toBe(expectedDefaultDir('x64'))
})
})

describe('getWindowsBuildCommand', () => {
let tempDir = ''

Expand Down
14 changes: 11 additions & 3 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ export interface GetVlangRequest {
checkLatest: boolean
stable?: boolean
arch?: string
installPath?: string
}

export function getInstallDir(arch: string = os.arch()): string {
export function getInstallDir(
arch: string = os.arch(),
customPath?: string
): string {
if (customPath) {
return path.resolve(customPath)
}
const osPlat: string = os.platform()
const osArch: string = translateArchToDistUrl(arch)
const vlangDir = path.join(os.homedir(), 'vlang')
Expand Down Expand Up @@ -64,9 +71,10 @@ export async function getVlang({
version,
checkLatest,
stable,
arch = os.arch()
arch = os.arch(),
installPath
}: GetVlangRequest): Promise<string> {
const installDir = getInstallDir(arch)
const installDir = getInstallDir(arch, installPath)
const vBinPath = getVExecutable(installDir)

if (fs.existsSync(installDir)) {
Expand Down
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ async function run(): Promise<void> {
}

const useCache = strToBoolean(core.getInput('cache') || 'true')
const customPath = core.getInput('path')

if (useCache && version) {
const cacheKey = `v-${version}-${os.platform()}-${arch}`
const installDir = installer.getInstallDir(arch)
const installDir = installer.getInstallDir(arch, customPath)
const hit = await cache.restoreCache([installDir], cacheKey)
if (hit) {
core.info(`Cache hit for V ${version}`)
Expand All @@ -60,7 +61,8 @@ async function run(): Promise<void> {
version,
checkLatest,
stable,
arch
arch,
installPath: customPath
})

core.info('Adding v to the cache...')
Expand Down
Loading