Skip to content

Commit 58d995d

Browse files
committed
feat: manifest based releaser https://git.io/JmVD4
1 parent 3428959 commit 58d995d

3 files changed

Lines changed: 102 additions & 8 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ Automate releases with Conventional Commit Messages.
3030
the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
3131
convention, [release-please](https://github.com/googleapis/release-please)
3232
will start creating Release PRs for you.
33+
4. For an alternative configuration that provides easier bootstrapping options
34+
for initial setup, follow [these instructions](https://github.com/googleapis/release-please/blob/master/docs/manifest-releaser.md)
35+
(ignore the cli section) and then configure this action as follows:
36+
37+
```yaml
38+
#...(same as above)
39+
steps:
40+
- uses: GoogleCloudPlatform/release-please-action@v2
41+
with:
42+
command: manifest
43+
```
3344
3445
## Configuration
3546

index.js

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const core = require('@actions/core')
22
const { factory } = require('release-please/build/src')
33

4+
const CONFIG_FILE = 'release-please-config.json'
5+
const MANIFEST_FILE = '.release-please-manifest.json'
6+
const MANIFEST_COMMAND = 'manifest'
47
const RELEASE_LABEL = 'autorelease: pending'
58
const GITHUB_RELEASE_COMMAND = 'github-release'
69
const GITHUB_RELEASE_PR_COMMAND = 'release-pr'
@@ -14,20 +17,62 @@ function getBooleanInput (input) {
1417
throw TypeError(`Wrong boolean value of the input '${input}'`)
1518
}
1619

20+
function getGitHubInput () {
21+
return {
22+
fork: getBooleanInput('fork'),
23+
defaultBranch: core.getInput('default-branch') || undefined,
24+
repoUrl: process.env.GITHUB_REPOSITORY,
25+
apiUrl: 'https://api.github.com',
26+
token: core.getInput('token', { required: true })
27+
}
28+
}
29+
30+
function getManifestInput () {
31+
return {
32+
configFile: core.getInput('config-file') || CONFIG_FILE,
33+
manifestFile: core.getInput('manifest-file') || MANIFEST_FILE
34+
}
35+
}
36+
37+
async function runManifest () {
38+
const githubOpts = getGitHubInput()
39+
const manifestOpts = { ...githubOpts, ...getManifestInput() }
40+
const pr = await factory.runCommand('manifest-pr', manifestOpts)
41+
if (pr) {
42+
core.setOutput('pr', pr)
43+
}
44+
45+
const releasesCreated = await factory.runCommand('manifest-release', manifestOpts)
46+
if (releasesCreated) {
47+
core.setOutput('releases_created', true)
48+
for (const [path, release] of Object.entries(releasesCreated)) {
49+
if (!release) {
50+
continue
51+
}
52+
for (const [key, val] of Object.entries(release)) {
53+
core.setOutput(`${path}--${key}`, val)
54+
}
55+
}
56+
}
57+
}
58+
1759
async function main () {
60+
const command = core.getInput('command') || undefined
61+
if (command === MANIFEST_COMMAND) {
62+
return await runManifest()
63+
}
64+
65+
const { token, fork, defaultBranch, apiUrl, repoUrl } = getGitHubInput()
66+
1867
const bumpMinorPreMajor = getBooleanInput('bump-minor-pre-major')
1968
const monorepoTags = getBooleanInput('monorepo-tags')
2069
const packageName = core.getInput('package-name')
2170
const path = core.getInput('path') || undefined
2271
const releaseType = core.getInput('release-type', { required: true })
23-
const token = core.getInput('token', { required: true })
24-
const fork = getBooleanInput('fork')
2572
const changelogPath = core.getInput('changelog-path') || undefined
2673
const changelogTypes = core.getInput('changelog-types') || undefined
2774
const changelogSections = changelogTypes && JSON.parse(changelogTypes)
28-
const command = core.getInput('command') || undefined
2975
const versionFile = core.getInput('version-file') || undefined
30-
const defaultBranch = core.getInput('default-branch') || undefined
3176
const pullRequestTitlePattern = core.getInput('pull-request-title-pattern') || undefined
3277

3378
// First we check for any merged release PRs (PRs merged with the label
@@ -62,10 +107,10 @@ async function main () {
62107
monorepoTags,
63108
packageName,
64109
path,
65-
apiUrl: 'https://api.github.com',
66-
repoUrl: process.env.GITHUB_REPOSITORY,
110+
apiUrl,
111+
repoUrl,
67112
fork,
68-
token: token,
113+
token,
69114
label: RELEASE_LABEL,
70115
bumpMinorPreMajor,
71116
changelogSections,

test/release-please.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const action = require('../')
33
const assert = require('assert')
44
const core = require('@actions/core')
55
const sinon = require('sinon')
6-
const { factory, GitHubRelease } = require('release-please/build/src')
6+
const { factory, GitHubRelease, Manifest } = require('release-please/build/src')
77
const { Node } = require('release-please/build/src/releasers/node')
88
// As defined in action.yml
99
const defaultInput = {
@@ -322,4 +322,42 @@ describe('release-please-action', () => {
322322
await action.main()
323323
assert.ok(maybeGitHubRelease instanceof GitHubRelease)
324324
})
325+
326+
it('creates and runs a Manifest, using factory', async () => {
327+
let maybeManifest
328+
sandbox.replace(factory, 'call', runnable => {
329+
maybeManifest = runnable
330+
})
331+
input = { command: 'manifest' }
332+
await action.main()
333+
assert.ok(maybeManifest instanceof Manifest)
334+
})
335+
336+
it('opens PR creates GitHub releases by default for manifest', async () => {
337+
input = { command: 'manifest' }
338+
339+
const runCommandStub = sandbox.stub(factory, 'runCommand')
340+
341+
const manifestReleaseStub = runCommandStub.withArgs('manifest-release').resolves(
342+
{
343+
'path/pkgA':
344+
{
345+
upload_url: 'http://example.com',
346+
tag_name: 'v1.0.0'
347+
}
348+
})
349+
350+
const manifestReleasePRStub = runCommandStub.withArgs('manifest-pr').returns(25)
351+
352+
await action.main()
353+
354+
sinon.assert.calledOnce(manifestReleaseStub)
355+
sinon.assert.calledOnce(manifestReleasePRStub)
356+
assert.deepStrictEqual(output, {
357+
releases_created: true,
358+
'path/pkgA--upload_url': 'http://example.com',
359+
'path/pkgA--tag_name': 'v1.0.0',
360+
pr: 25
361+
})
362+
})
325363
})

0 commit comments

Comments
 (0)