forked from googleapis/release-please-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
275 lines (258 loc) · 9.04 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
const core = require('@actions/core')
const { GitHub } = require('release-please/build/src/github')
const { Manifest } = require('release-please/build/src/manifest')
const CONFIG_FILE = 'release-please-config.json'
const MANIFEST_FILE = '.release-please-manifest.json'
const MANIFEST_COMMANDS = ['manifest', 'manifest-pr']
const GITHUB_RELEASE_COMMAND = 'github-release'
const GITHUB_RELEASE_PR_COMMAND = 'release-pr'
const GITHUB_API_URL = 'https://api.github.com'
const GITHUB_GRAPHQL_URL = 'https://api.github.com'
const signoff = core.getInput('signoff') || undefined
function getGitHubInput () {
return {
fork: getOptionalBooleanInput('fork'),
defaultBranch: core.getInput('default-branch') || undefined,
repoUrl: core.getInput('repo-url') || process.env.GITHUB_REPOSITORY,
apiUrl: core.getInput('github-api-url') || GITHUB_API_URL,
graphqlUrl: (core.getInput('github-graphql-url') || '').replace(/\/graphql$/, '') || GITHUB_GRAPHQL_URL,
useGraphql: getOptionalBooleanInput('github-use-graphql'),
token: core.getInput('token', { required: true }),
proxyServer: core.getInput('proxy-server') || undefined
}
}
function getOptionalBooleanInput (name) {
const input = core.getInput(name)
if (input === '' || input === undefined) {
return undefined
}
return core.getBooleanInput(name)
}
function getOptionalMultilineInput (name) {
if (core.getInput(name) === '') {
return undefined
}
return core.getMultilineInput(name)
}
function getManifestInput () {
return {
configFile: core.getInput('config-file') || CONFIG_FILE,
manifestFile: core.getInput('manifest-file') || MANIFEST_FILE,
signoff
}
}
async function runManifest (command) {
// Create the Manifest and GitHub instance from
// argument provided to GitHub action:
const { fork } = getGitHubInput()
const manifestOpts = getManifestInput()
const github = await getGitHubInstance()
let manifest = await Manifest.fromManifest(
github,
github.repository.defaultBranch,
manifestOpts.configFile,
manifestOpts.manifestFile,
{
signoff,
fork
}
)
// Create or update release PRs:
outputPRs(await manifest.createPullRequests())
if (command !== 'manifest-pr') {
manifest = await Manifest.fromManifest(
github,
github.repository.defaultBranch,
manifestOpts.configFile,
manifestOpts.manifestFile,
{
signoff,
fork
}
)
outputReleases(await manifest.createReleases())
}
}
async function main () {
const command = core.getInput('command') || undefined
if (MANIFEST_COMMANDS.includes(command)) {
return await runManifest(command)
}
const github = await getGitHubInstance()
// First we check for any merged release PRs (PRs merged with the label
// "autorelease: pending"):
if (!command || command === GITHUB_RELEASE_COMMAND) {
const manifest = await manifestInstance(github)
outputReleases(await manifest.createReleases())
}
// Next we check for PRs merged since the last release, and groom the
// release PR:
if (!command || command === GITHUB_RELEASE_PR_COMMAND) {
const manifest = await manifestInstance(github)
outputPRs(await manifest.createPullRequests())
}
}
const releasePlease = {
main
}
function getGitHubInstance () {
const { token, defaultBranch, apiUrl, graphqlUrl, repoUrl, proxyServer, useGraphql } = getGitHubInput()
const [owner, repo] = repoUrl.split('/')
let proxy
if (proxyServer) {
const [host, port] = proxyServer.split(':')
proxy = { host, port }
}
const githubCreateOpts = {
proxy,
owner,
repo,
apiUrl,
graphqlUrl,
token,
useGraphql
}
if (defaultBranch) githubCreateOpts.defaultBranch = defaultBranch
return GitHub.create(githubCreateOpts)
}
async function manifestInstance (github) {
const { fork } = getGitHubInput()
const bumpMinorPreMajor = getOptionalBooleanInput('bump-minor-pre-major')
const bumpPatchForMinorPreMajor = getOptionalBooleanInput('bump-patch-for-minor-pre-major')
const monorepoTags = getOptionalBooleanInput('monorepo-tags')
const packageName = core.getInput('package-name') || undefined
const path = core.getInput('path') || undefined
const releaseType = core.getInput('release-type', { required: true })
const changelogPath = core.getInput('changelog-path') || undefined
const changelogHost = core.getInput('changelog-host') || undefined
const changelogTypes = core.getInput('changelog-types') || undefined
const changelogSections = changelogTypes && JSON.parse(changelogTypes)
const versionFile = core.getInput('version-file') || undefined
const extraFiles = core.getMultilineInput('extra-files') || undefined
const pullRequestTitlePattern = core.getInput('pull-request-title-pattern') || undefined
const pullRequestHeader = core.getInput('pull-request-header') || undefined
const draft = getOptionalBooleanInput('draft')
const draftPullRequest = getOptionalBooleanInput('draft-pull-request')
const changelogType = core.getInput('changelog-notes-type') || undefined
const versioning = core.getInput('versioning-strategy') || undefined
const releaseAs = core.getInput('release-as') || undefined
const skipGithubRelease = getOptionalBooleanInput('skip-github-release')
const prerelease = getOptionalBooleanInput('prerelease')
const component = core.getInput('component') || undefined
const includeVInTag = getOptionalBooleanInput('include-v-in-tag')
const tagSeparator = core.getInput('tag-separator') || undefined
const snapshotLabels = getOptionalMultilineInput('snapshot-labels')
const bootstrapSha = core.getInput('bootstrap-sha') || undefined
const lastReleaseSha = core.getInput('last-release-sha') || undefined
const alwaysLinkLocal = getOptionalBooleanInput('always-link-local')
const separatePullRequests = getOptionalBooleanInput('separate-pull-requests')
const plugins = core.getMultilineInput('plugins') || undefined
const labels = core.getInput('labels') ? core.getMultilineInput('labels') : undefined
const releaseLabels = getOptionalMultilineInput('release-labels')
const skipLabeling = getOptionalBooleanInput('skip-labeling')
const sequentialCalls = getOptionalBooleanInput('sequential-calls')
const groupPullRequestTitlePattern = core.getInput('group-pull-request-title-pattern') || undefined
const releaseSearchDepth = core.getInput('release-search-depth') || undefined
const commitSearchDepth = core.getInput('commit-search-depth') || undefined
return await Manifest.fromConfig(
github,
github.repository.defaultBranch,
{
bumpMinorPreMajor,
bumpPatchForMinorPreMajor,
packageName,
releaseType,
changelogPath,
changelogHost,
changelogSections,
versionFile,
extraFiles,
includeComponentInTag: monorepoTags,
pullRequestTitlePattern,
pullRequestHeader,
draftPullRequest,
versioning,
releaseAs,
skipGithubRelease,
draft,
prerelease,
component,
includeVInTag,
tagSeparator,
changelogType,
snapshotLabels
},
{
draft,
signoff,
fork,
draftPullRequest,
bootstrapSha,
lastReleaseSha,
alwaysLinkLocal,
separatePullRequests,
plugins,
labels,
releaseLabels,
snapshotLabels,
skipLabeling,
sequentialCalls,
prerelease,
groupPullRequestTitlePattern,
releaseSearchDepth,
commitSearchDepth
},
path
)
}
function outputReleases (releases) {
releases = releases.filter(release => release !== undefined)
const pathsReleased = []
if (releases.length) {
core.setOutput('releases_created', true)
for (const release of releases) {
const path = release.path || '.'
if (path) {
pathsReleased.push(path)
// If the special root release is set (representing project root)
// and this is explicitly a manifest release, set the release_created boolean.
if (path === '.') {
core.setOutput('release_created', true)
} else {
core.setOutput(`${path}--release_created`, true)
}
}
for (let [key, val] of Object.entries(release)) {
// Historically tagName was output as tag_name, keep this
// consistent to avoid breaking change:
if (key === 'tagName') key = 'tag_name'
if (key === 'uploadUrl') key = 'upload_url'
if (key === 'notes') key = 'body'
if (key === 'url') key = 'html_url'
if (path === '.') {
core.setOutput(key, val)
} else {
core.setOutput(`${path}--${key}`, val)
}
}
}
}
// Paths of all releases that were created, so that they can be passed
// to matrix in next step:
core.setOutput('paths_released', JSON.stringify(pathsReleased))
}
function outputPRs (prs) {
prs = prs.filter(pr => pr !== undefined)
if (prs.length) {
core.setOutput('pr', prs[0])
core.setOutput('prs', JSON.stringify(prs))
}
}
/* c8 ignore next 4 */
if (require.main === module) {
main().catch(err => {
core.setFailed(`release-please failed: ${err.message}`)
})
} else {
module.exports = releasePlease
}