-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (25 loc) · 984 Bytes
/
index.js
File metadata and controls
32 lines (25 loc) · 984 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
29
30
31
32
const core = require('@actions/core')
const {execSync} = require('child_process')
const commitCountCommand = 'git rev-list --count HEAD'
const descriptionHashCommand = 'git describe --always'
const branchCommand = 'git rev-parse --abbrev-ref HEAD'
try {
const commitCount = execSync(commitCountCommand).toString().trim()
const descriptionHash = execSync(descriptionHashCommand).toString().trim()
let branch = execSync(branchCommand).toString().trim()
if (branch == null || branch === '') {
core.setFailed('Could not extract branch name')
return
}
if (branch === 'master' || branch === 'main') {
branch = 'dev'
}
const num = branch.replace('release/', '')
.replace('test/', '')
.replace(/[/\\?%*:|"<>]/g, '-')
const version = `${num}.${commitCount}-${descriptionHash}`
core.info('Version is: ' + version)
core.setOutput('version', version)
} catch (error) {
core.setFailed(error.message)
}