forked from salsify/action-detect-and-tag-new-version
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetermine-version.ts
More file actions
28 lines (24 loc) · 835 Bytes
/
determine-version.ts
File metadata and controls
28 lines (24 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { existsSync } from 'fs';
import { sync as glob } from 'glob';
import { getInput } from '@actions/core';
import execa from 'execa';
export async function determineVersion(): Promise<string> {
let command = determineVersionCommand();
let result = await execa.command(command, { shell: true });
return result.stdout.trim();
}
function determineVersionCommand(): string {
let command = getInput('version-command');
if (command) {
return command;
}
if (existsSync('package.json')) {
return `node -p 'require("./package.json").version'`;
} else {
let gemspecs = glob('*.gemspec');
if (gemspecs.length === 1) {
return `ruby -e "puts Gem::Specification.load('${gemspecs[0]}').version"`;
}
}
throw new Error('No `version-command` specified, and unable to guess from repo contents.');
}