mirror of
https://github.com/googleapis/release-please-action.git
synced 2026-03-25 13:43:09 +00:00
feat: manifest based releaser https://git.io/JmVD4 (#273)
This commit is contained in:
11
README.md
11
README.md
@@ -30,6 +30,17 @@ Automate releases with Conventional Commit Messages.
|
||||
the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
|
||||
convention, [release-please](https://github.com/googleapis/release-please)
|
||||
will start creating Release PRs for you.
|
||||
4. For an alternative configuration that provides easier bootstrapping options
|
||||
for initial setup, follow [these instructions](https://github.com/googleapis/release-please/blob/master/docs/manifest-releaser.md)
|
||||
(ignore the cli section) and then configure this action as follows:
|
||||
|
||||
```yaml
|
||||
#...(same as above)
|
||||
steps:
|
||||
- uses: GoogleCloudPlatform/release-please-action@v2
|
||||
with:
|
||||
command: manifest
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
|
||||
59
index.js
59
index.js
@@ -1,6 +1,9 @@
|
||||
const core = require('@actions/core')
|
||||
const { factory } = require('release-please/build/src')
|
||||
|
||||
const CONFIG_FILE = 'release-please-config.json'
|
||||
const MANIFEST_FILE = '.release-please-manifest.json'
|
||||
const MANIFEST_COMMAND = 'manifest'
|
||||
const RELEASE_LABEL = 'autorelease: pending'
|
||||
const GITHUB_RELEASE_COMMAND = 'github-release'
|
||||
const GITHUB_RELEASE_PR_COMMAND = 'release-pr'
|
||||
@@ -14,20 +17,62 @@ function getBooleanInput (input) {
|
||||
throw TypeError(`Wrong boolean value of the input '${input}'`)
|
||||
}
|
||||
|
||||
function getGitHubInput () {
|
||||
return {
|
||||
fork: getBooleanInput('fork'),
|
||||
defaultBranch: core.getInput('default-branch') || undefined,
|
||||
repoUrl: process.env.GITHUB_REPOSITORY,
|
||||
apiUrl: 'https://api.github.com',
|
||||
token: core.getInput('token', { required: true })
|
||||
}
|
||||
}
|
||||
|
||||
function getManifestInput () {
|
||||
return {
|
||||
configFile: core.getInput('config-file') || CONFIG_FILE,
|
||||
manifestFile: core.getInput('manifest-file') || MANIFEST_FILE
|
||||
}
|
||||
}
|
||||
|
||||
async function runManifest () {
|
||||
const githubOpts = getGitHubInput()
|
||||
const manifestOpts = { ...githubOpts, ...getManifestInput() }
|
||||
const pr = await factory.runCommand('manifest-pr', manifestOpts)
|
||||
if (pr) {
|
||||
core.setOutput('pr', pr)
|
||||
}
|
||||
|
||||
const releasesCreated = await factory.runCommand('manifest-release', manifestOpts)
|
||||
if (releasesCreated) {
|
||||
core.setOutput('releases_created', true)
|
||||
for (const [path, release] of Object.entries(releasesCreated)) {
|
||||
if (!release) {
|
||||
continue
|
||||
}
|
||||
for (const [key, val] of Object.entries(release)) {
|
||||
core.setOutput(`${path}--${key}`, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function main () {
|
||||
const command = core.getInput('command') || undefined
|
||||
if (command === MANIFEST_COMMAND) {
|
||||
return await runManifest()
|
||||
}
|
||||
|
||||
const { token, fork, defaultBranch, apiUrl, repoUrl } = getGitHubInput()
|
||||
|
||||
const bumpMinorPreMajor = getBooleanInput('bump-minor-pre-major')
|
||||
const monorepoTags = getBooleanInput('monorepo-tags')
|
||||
const packageName = core.getInput('package-name')
|
||||
const path = core.getInput('path') || undefined
|
||||
const releaseType = core.getInput('release-type', { required: true })
|
||||
const token = core.getInput('token', { required: true })
|
||||
const fork = getBooleanInput('fork')
|
||||
const changelogPath = core.getInput('changelog-path') || undefined
|
||||
const changelogTypes = core.getInput('changelog-types') || undefined
|
||||
const changelogSections = changelogTypes && JSON.parse(changelogTypes)
|
||||
const command = core.getInput('command') || undefined
|
||||
const versionFile = core.getInput('version-file') || undefined
|
||||
const defaultBranch = core.getInput('default-branch') || undefined
|
||||
const pullRequestTitlePattern = core.getInput('pull-request-title-pattern') || undefined
|
||||
|
||||
// First we check for any merged release PRs (PRs merged with the label
|
||||
@@ -62,10 +107,10 @@ async function main () {
|
||||
monorepoTags,
|
||||
packageName,
|
||||
path,
|
||||
apiUrl: 'https://api.github.com',
|
||||
repoUrl: process.env.GITHUB_REPOSITORY,
|
||||
apiUrl,
|
||||
repoUrl,
|
||||
fork,
|
||||
token: token,
|
||||
token,
|
||||
label: RELEASE_LABEL,
|
||||
bumpMinorPreMajor,
|
||||
changelogSections,
|
||||
|
||||
@@ -4,6 +4,7 @@ const assert = require('assert')
|
||||
const core = require('@actions/core')
|
||||
const sinon = require('sinon')
|
||||
const { factory, GitHubRelease } = require('release-please/build/src')
|
||||
const { Manifest } = require('release-please/build/src/manifest')
|
||||
const { Node } = require('release-please/build/src/releasers/node')
|
||||
// As defined in action.yml
|
||||
const defaultInput = {
|
||||
@@ -322,4 +323,42 @@ describe('release-please-action', () => {
|
||||
await action.main()
|
||||
assert.ok(maybeGitHubRelease instanceof GitHubRelease)
|
||||
})
|
||||
|
||||
it('creates and runs a Manifest, using factory', async () => {
|
||||
let maybeManifest
|
||||
sandbox.replace(factory, 'call', runnable => {
|
||||
maybeManifest = runnable
|
||||
})
|
||||
input = { command: 'manifest' }
|
||||
await action.main()
|
||||
assert.ok(maybeManifest instanceof Manifest)
|
||||
})
|
||||
|
||||
it('opens PR creates GitHub releases by default for manifest', async () => {
|
||||
input = { command: 'manifest' }
|
||||
|
||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||
|
||||
const manifestReleaseStub = runCommandStub.withArgs('manifest-release').resolves(
|
||||
{
|
||||
'path/pkgA':
|
||||
{
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0'
|
||||
}
|
||||
})
|
||||
|
||||
const manifestReleasePRStub = runCommandStub.withArgs('manifest-pr').returns(25)
|
||||
|
||||
await action.main()
|
||||
|
||||
sinon.assert.calledOnce(manifestReleaseStub)
|
||||
sinon.assert.calledOnce(manifestReleasePRStub)
|
||||
assert.deepStrictEqual(output, {
|
||||
releases_created: true,
|
||||
'path/pkgA--upload_url': 'http://example.com',
|
||||
'path/pkgA--tag_name': 'v1.0.0',
|
||||
pr: 25
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user