forked from googleapis/release-please-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
86 lines (77 loc) · 2.63 KB
/
index.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const core = require('@actions/core')
const { factory } = require('release-please/build/src')
const RELEASE_LABEL = 'autorelease: pending'
const GITHUB_RELEASE_COMMAND = 'github-release'
const GITHUB_RELEASE_PR_COMMAND = 'release-pr'
async function main () {
const bumpMinorPreMajor = Boolean(core.getInput('bump-minor-pre-major'))
const monorepoTags = Boolean(core.getInput('monorepo-tags'))
const packageName = core.getInput('package-name')
const path = core.getInput('path') ? core.getInput('path') : undefined
const releaseType = core.getInput('release-type')
const token = core.getInput('token')
const fork = core.getInput('fork') ? true : undefined
const changelogPath = core.getInput('changelog-path') ? core.getInput('changelog-path') : undefined
const changelogTypes = core.getInput('changelog-types')
const command = core.getInput('command') ? core.getInput('command') : undefined
const versionFile = core.getInput('version-file') ? core.getInput('version-file') : undefined
const defaultBranch = core.getInput('default-branch') ? core.getInput('default-branch') : undefined
// Parse the changelogTypes if there are any
let changelogSections
if (changelogTypes) {
changelogSections = JSON.parse(changelogTypes)
}
// First we check for any merged release PRs (PRs merged with the label
// "autorelease: pending"):
if (!command || command === GITHUB_RELEASE_COMMAND) {
const releaseCreated = await factory.runCommand(GITHUB_RELEASE_COMMAND, {
label: RELEASE_LABEL,
repoUrl: process.env.GITHUB_REPOSITORY,
packageName,
path,
monorepoTags,
token,
changelogPath,
releaseType,
defaultBranch
})
if (releaseCreated) {
core.setOutput('release_created', true)
for (const key of Object.keys(releaseCreated)) {
core.setOutput(key, releaseCreated[key])
}
}
}
// Next we check for PRs merged since the last release, and groom the
// release PR:
if (!command || command === GITHUB_RELEASE_PR_COMMAND) {
const pr = await factory.runCommand(GITHUB_RELEASE_PR_COMMAND, {
releaseType,
monorepoTags,
packageName,
path,
apiUrl: 'https://api.github.com',
repoUrl: process.env.GITHUB_REPOSITORY,
fork,
token: token,
label: RELEASE_LABEL,
bumpMinorPreMajor,
changelogSections,
versionFile,
defaultBranch
})
if (pr) {
core.setOutput('pr', pr)
}
}
}
const releasePlease = {
main
}
if (require.main === module) {
main().catch(err => {
core.setFailed(`release-please failed: ${err.message}`)
})
} else {
module.exports = releasePlease
}