This repository has been archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
202 lines (188 loc) · 6.29 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
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: core.getBooleanInput('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') || GITHUB_GRAPHQL_URL,
token: core.getInput('token', { required: true })
}
}
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 } = getGitHubInput()
const [owner, repo] = repoUrl.split('/')
const githubCreateOpts = {
owner,
repo,
apiUrl,
graphqlUrl,
token
}
if (defaultBranch) githubCreateOpts.defaultBranch = defaultBranch
return GitHub.create(githubCreateOpts)
}
async function manifestInstance (github) {
const { fork } = getGitHubInput()
const bumpMinorPreMajor = core.getBooleanInput('bump-minor-pre-major')
const bumpPatchForMinorPreMajor = core.getBooleanInput('bump-patch-for-minor-pre-major')
const monorepoTags = core.getBooleanInput('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 draft = core.getBooleanInput('draft')
const draftPullRequest = core.getBooleanInput('draft-pull-request')
return await Manifest.fromConfig(
github,
github.repository.defaultBranch,
{
bumpMinorPreMajor,
bumpPatchForMinorPreMajor,
packageName,
releaseType,
changelogPath,
changelogHost,
changelogSections,
versionFile,
extraFiles,
includeComponentInTag: monorepoTags,
pullRequestTitlePattern,
draftPullRequest
},
{
draft,
signoff,
fork
},
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
}