-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-next-version.ts
66 lines (57 loc) · 1.71 KB
/
get-next-version.ts
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { fromEnv } from '@bifravst/from-env'
import { execSync } from 'child_process'
import { appendFileSync } from 'fs'
import * as os from 'os'
import semanticRelease from 'semantic-release'
import { WritableStreamBuffer } from 'stream-buffers'
const { outputsFile, githubRepository } = fromEnv({
outputsFile: 'GITHUB_OUTPUT',
githubRepository: 'GITHUB_REPOSITORY',
})(process.env)
const stdoutBuffer = new WritableStreamBuffer()
const stderrBuffer = new WritableStreamBuffer()
const branch = process.argv[process.argv.length - 2]
const defaultVersion = process.argv[process.argv.length - 1]
const workdir = process.cwd()
console.debug('cwd', workdir)
console.debug('branch', branch)
console.debug('repository', githubRepository)
console.debug('outputsFile', outputsFile)
execSync(`git config --global --add safe.directory ${workdir}`)
const main = async () => {
const result = await semanticRelease(
{
// Core options
branch,
repositoryUrl: `https://github.com/${githubRepository}.git`,
plugins: ['@semantic-release/commit-analyzer'],
dryRun: true,
ci: false,
},
{
cwd: workdir,
stdout: stdoutBuffer as unknown as NodeJS.WriteStream,
stderr: stderrBuffer as unknown as NodeJS.WriteStream,
},
)
if (result !== false) {
const { nextRelease } = result
appendFileSync(
outputsFile,
`nextRelease=${nextRelease.version}${os.EOL}`,
'utf-8',
)
} else {
console.error('No new release.')
process.stderr.write(stdoutBuffer.getContentsAsString('utf8') as string)
if (stderrBuffer.size() > 0) {
process.stderr.write(stderrBuffer.getContentsAsString('utf8') as string)
}
appendFileSync(
outputsFile,
`nextRelease=${defaultVersion}${os.EOL}`,
'utf-8',
)
}
}
void main()