mirror of
https://github.com/googleapis/release-please-action.git
synced 2026-03-26 06:02:20 +00:00
feat(release-please)!: consolidate manifest and individual releasers (#398)
Major update to release-please which consolidates the manifest and single releaser behavior into a single set of strategies, which can be used on both split and mono-repos. feat: adds support for draft pull requests. feat: adds support for draft releases. refactor!: if switching to manifest releaser, release_created will only be set if "." path is published. refactor!: switch to using @actions/core getBooleanInput, accepted values for true = ["true", "True", "TRUE"], accepted values for false = ["false", "False", "FALSE"]
This commit is contained in:
14
README.md
14
README.md
@@ -20,7 +20,7 @@ Automate releases with Conventional Commit Messages.
|
||||
release-please:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: GoogleCloudPlatform/release-please-action@v2
|
||||
- uses: GoogleCloudPlatform/release-please-action@v3
|
||||
with:
|
||||
release-type: node
|
||||
package-name: release-please-action
|
||||
@@ -37,7 +37,7 @@ Automate releases with Conventional Commit Messages.
|
||||
```yaml
|
||||
#...(same as above)
|
||||
steps:
|
||||
- uses: GoogleCloudPlatform/release-please-action@v2
|
||||
- uses: GoogleCloudPlatform/release-please-action@v3
|
||||
with:
|
||||
command: manifest
|
||||
```
|
||||
@@ -138,7 +138,7 @@ jobs:
|
||||
release-please:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: GoogleCloudPlatform/release-please-action@v2
|
||||
- uses: GoogleCloudPlatform/release-please-action@v3
|
||||
with:
|
||||
release-type: node
|
||||
package-name: release-please-action
|
||||
@@ -161,7 +161,7 @@ jobs:
|
||||
release-please:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: GoogleCloudPlatform/release-please-action@v2
|
||||
- uses: GoogleCloudPlatform/release-please-action@v3
|
||||
with:
|
||||
release-type: node
|
||||
package-name: release-please-action
|
||||
@@ -178,7 +178,7 @@ jobs:
|
||||
release-please:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: GoogleCloudPlatform/release-please-action@v2
|
||||
- uses: GoogleCloudPlatform/release-please-action@v3
|
||||
with:
|
||||
release-type: node
|
||||
package-name: release-please-action
|
||||
@@ -200,7 +200,7 @@ jobs:
|
||||
release-please:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: GoogleCloudPlatform/release-please-action@v2
|
||||
- uses: GoogleCloudPlatform/release-please-action@v3
|
||||
id: release
|
||||
with:
|
||||
release-type: node
|
||||
@@ -248,7 +248,7 @@ jobs:
|
||||
release-please:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: GoogleCloudPlatform/release-please-action@v2
|
||||
- uses: GoogleCloudPlatform/release-please-action@v3
|
||||
id: release
|
||||
with:
|
||||
release-type: node
|
||||
|
||||
30
action.yml
30
action.yml
@@ -32,18 +32,10 @@ inputs:
|
||||
description: "create a release from a path other than the repository's root"
|
||||
required: false
|
||||
default: ''
|
||||
monorepo-tags:
|
||||
description: 'add prefix to tags and branches, allowing multiple libraries to be released from the same repository'
|
||||
required: false
|
||||
default: false
|
||||
changelog-path:
|
||||
description: 'specify a CHANGELOG path other than the root CHANGELOG.md'
|
||||
required: false
|
||||
default: ''
|
||||
changelog-types:
|
||||
description: 'changlelog commit types'
|
||||
required: false
|
||||
default: ''
|
||||
command:
|
||||
description: 'release-please command to run, either "github-release", or "release-pr" (defaults to running both)'
|
||||
required: false
|
||||
@@ -56,10 +48,10 @@ inputs:
|
||||
description: 'branch to open pull release PR against (detected by default)'
|
||||
required: false
|
||||
default: ''
|
||||
pull-request-title-pattern:
|
||||
description: 'add title pattern to make release PR, defaults to using "chore${scope}: release${component} ${version}".'
|
||||
changelog-types:
|
||||
description: 'changlelog commit types'
|
||||
required: false
|
||||
default: 'chore${scope}: release${component} ${version}'
|
||||
default: ''
|
||||
config-file:
|
||||
description: 'where can the config file be found in the project?'
|
||||
required: false
|
||||
@@ -84,6 +76,22 @@ inputs:
|
||||
description: 'configure github repository URL. Default `process.env.GITHUB_REPOSITORY`'
|
||||
required: false
|
||||
default: ''
|
||||
monorepo-tags:
|
||||
description: 'add prefix to tags and branches, allowing multiple libraries to be released from the same repository'
|
||||
required: false
|
||||
default: false
|
||||
pull-request-title-pattern:
|
||||
description: 'add title pattern to make release PR, defaults to using "chore${scope}: release${component} ${version}"'
|
||||
required: false
|
||||
default: ''
|
||||
draft:
|
||||
description: 'mark release as a draft'
|
||||
required: false
|
||||
default: false
|
||||
draft-pull-request:
|
||||
description: 'mark pull request as a draft'
|
||||
required: false
|
||||
default: false
|
||||
|
||||
runs:
|
||||
using: 'node12'
|
||||
|
||||
42961
dist/index.js
vendored
42961
dist/index.js
vendored
File diff suppressed because one or more lines are too long
228
index.js
228
index.js
@@ -1,10 +1,10 @@
|
||||
const core = require('@actions/core')
|
||||
const { factory } = require('release-please/build/src')
|
||||
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 RELEASE_LABEL = 'autorelease: pending'
|
||||
const GITHUB_RELEASE_COMMAND = 'github-release'
|
||||
const GITHUB_RELEASE_PR_COMMAND = 'release-pr'
|
||||
const GITHUB_API_URL = 'https://api.github.com'
|
||||
@@ -12,18 +12,9 @@ const GITHUB_GRAPHQL_URL = 'https://api.github.com'
|
||||
|
||||
const signoff = core.getInput('signoff') || undefined
|
||||
|
||||
function getBooleanInput (input) {
|
||||
const trueValue = ['true', 'True', 'TRUE', 'yes', 'Yes', 'YES', 'y', 'Y', 'on', 'On', 'ON']
|
||||
const falseValue = ['false', 'False', 'FALSE', 'no', 'No', 'NO', 'n', 'N', 'off', 'Off', 'OFF']
|
||||
const stringInput = core.getInput(input)
|
||||
if (trueValue.indexOf(stringInput) > -1) return true
|
||||
if (falseValue.indexOf(stringInput) > -1) return false
|
||||
throw TypeError(`Wrong boolean value of the input '${input}'`)
|
||||
}
|
||||
|
||||
function getGitHubInput () {
|
||||
return {
|
||||
fork: getBooleanInput('fork'),
|
||||
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,
|
||||
@@ -41,29 +32,123 @@ function getManifestInput () {
|
||||
}
|
||||
|
||||
async function runManifest (command) {
|
||||
const githubOpts = getGitHubInput()
|
||||
const manifestOpts = { ...githubOpts, ...getManifestInput() }
|
||||
const pr = await factory.runCommand('manifest-pr', manifestOpts)
|
||||
if (pr) {
|
||||
core.setOutput('pr', pr)
|
||||
}
|
||||
// Create the Manifest and GitHub instance from
|
||||
// argument provided to GitHub action:
|
||||
const { fork } = getGitHubInput()
|
||||
const manifestOpts = getManifestInput()
|
||||
const github = await getGitHubInstance()
|
||||
const 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') return
|
||||
outputReleases(await manifest.createReleases())
|
||||
}
|
||||
|
||||
const releasesCreated = await factory.runCommand('manifest-release', manifestOpts)
|
||||
async function main () {
|
||||
const command = core.getInput('command') || undefined
|
||||
if (MANIFEST_COMMANDS.includes(command)) {
|
||||
return await runManifest(command)
|
||||
}
|
||||
|
||||
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')
|
||||
const path = core.getInput('path') || undefined
|
||||
const releaseType = core.getInput('release-type', { required: true })
|
||||
const changelogPath = core.getInput('changelog-path') || undefined
|
||||
const changelogTypes = core.getInput('changelog-types') || undefined
|
||||
const changelogSections = changelogTypes && JSON.parse(changelogTypes)
|
||||
const versionFile = core.getInput('version-file') || undefined
|
||||
const github = await getGitHubInstance()
|
||||
const pullRequestTitlePattern = core.getInput('pull-request-title-pattern') || undefined
|
||||
const draft = core.getBooleanInput('draft')
|
||||
const draftPullRequest = core.getBooleanInput('draft-pull-request')
|
||||
const manifest = await Manifest.fromConfig(
|
||||
github,
|
||||
github.repository.defaultBranch,
|
||||
{
|
||||
bumpMinorPreMajor,
|
||||
bumpPatchForMinorPreMajor,
|
||||
packageName,
|
||||
releaseType,
|
||||
changelogPath,
|
||||
changelogSections,
|
||||
versionFile,
|
||||
includeComponentInTag: monorepoTags,
|
||||
pullRequestTitlePattern,
|
||||
draftPullRequest
|
||||
},
|
||||
{
|
||||
draft,
|
||||
signoff,
|
||||
fork
|
||||
},
|
||||
path
|
||||
)
|
||||
|
||||
// First we check for any merged release PRs (PRs merged with the label
|
||||
// "autorelease: pending"):
|
||||
if (!command || command === GITHUB_RELEASE_COMMAND) {
|
||||
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) {
|
||||
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)
|
||||
}
|
||||
|
||||
function outputReleases (releases) {
|
||||
releases = releases.filter(release => release !== undefined)
|
||||
const pathsReleased = []
|
||||
if (releasesCreated) {
|
||||
if (releases.length) {
|
||||
core.setOutput('releases_created', true)
|
||||
for (const [path, release] of Object.entries(releasesCreated)) {
|
||||
if (!release) {
|
||||
continue
|
||||
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)
|
||||
}
|
||||
}
|
||||
pathsReleased.push(path)
|
||||
if (path === '.') {
|
||||
core.setOutput('release_created', true)
|
||||
} else {
|
||||
core.setOutput(`${path}--release_created`, true)
|
||||
}
|
||||
for (const [key, val] of Object.entries(release)) {
|
||||
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 (path === '.') {
|
||||
core.setOutput(key, val)
|
||||
} else {
|
||||
@@ -77,85 +162,12 @@ async function runManifest (command) {
|
||||
core.setOutput('paths_released', JSON.stringify(pathsReleased))
|
||||
}
|
||||
|
||||
async function main () {
|
||||
const command = core.getInput('command') || undefined
|
||||
if (MANIFEST_COMMANDS.includes(command)) {
|
||||
return await runManifest(command)
|
||||
function outputPRs (prs) {
|
||||
prs = prs.filter(pr => pr !== undefined)
|
||||
if (prs.length) {
|
||||
core.setOutput('pr', prs[0])
|
||||
core.setOutput('prs', JSON.stringify(prs))
|
||||
}
|
||||
|
||||
const { token, fork, defaultBranch, apiUrl, graphqlUrl, repoUrl } = getGitHubInput()
|
||||
|
||||
const bumpMinorPreMajor = getBooleanInput('bump-minor-pre-major')
|
||||
const bumpPatchForMinorPreMajor = getBooleanInput('bump-patch-for-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 changelogPath = core.getInput('changelog-path') || undefined
|
||||
const changelogTypes = core.getInput('changelog-types') || undefined
|
||||
const changelogSections = changelogTypes && JSON.parse(changelogTypes)
|
||||
const versionFile = core.getInput('version-file') || undefined
|
||||
const pullRequestTitlePattern = core.getInput('pull-request-title-pattern') || undefined
|
||||
|
||||
// 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,
|
||||
packageName,
|
||||
path,
|
||||
monorepoTags,
|
||||
token,
|
||||
changelogPath,
|
||||
releaseType,
|
||||
defaultBranch,
|
||||
pullRequestTitlePattern,
|
||||
apiUrl,
|
||||
graphqlUrl
|
||||
})
|
||||
|
||||
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,
|
||||
graphqlUrl,
|
||||
repoUrl,
|
||||
fork,
|
||||
token,
|
||||
label: RELEASE_LABEL,
|
||||
bumpMinorPreMajor,
|
||||
bumpPatchForMinorPreMajor,
|
||||
changelogPath,
|
||||
changelogSections,
|
||||
versionFile,
|
||||
defaultBranch,
|
||||
pullRequestTitlePattern,
|
||||
signoff
|
||||
})
|
||||
|
||||
if (pr) {
|
||||
core.setOutput('pr', pr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const releasePlease = {
|
||||
main,
|
||||
getBooleanInput
|
||||
}
|
||||
|
||||
/* c8 ignore next 4 */
|
||||
|
||||
7975
package-lock.json
generated
7975
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -25,15 +25,16 @@
|
||||
},
|
||||
"homepage": "https://github.com/bcoe/release-please-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"release-please": "^12.6.0"
|
||||
"@actions/core": "^1.6.0",
|
||||
"release-please": "^13.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vercel/ncc": "^0.27.0",
|
||||
"c8": "^7.5.0",
|
||||
"mocha": "^8.2.1",
|
||||
"mocha": "^9.1.3",
|
||||
"nock": "^13.2.1",
|
||||
"sinon": "^9.2.4",
|
||||
"standard": "^16.0.3"
|
||||
"standard": "^16.0.4"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": "dist/"
|
||||
|
||||
@@ -3,9 +3,9 @@ const action = require('../')
|
||||
const assert = require('assert')
|
||||
const core = require('@actions/core')
|
||||
const sinon = require('sinon')
|
||||
const { factory, GitHubRelease } = require('release-please/build/src')
|
||||
const nock = require('nock')
|
||||
const { Manifest } = require('release-please/build/src/manifest')
|
||||
const { Node } = require('release-please/build/src/releasers/node')
|
||||
// const { Node } = require('release-please/build/src/strategies/node')
|
||||
// As defined in action.yml
|
||||
const defaultInput = {
|
||||
fork: 'false',
|
||||
@@ -20,7 +20,9 @@ const defaultInput = {
|
||||
'version-file': '',
|
||||
'default-branch': '',
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
'pull-request-title-pattern': 'chore${scope}: release${component} ${version}'
|
||||
'pull-request-title-pattern': 'chore${scope}: release${component} ${version}',
|
||||
draft: 'false',
|
||||
'draft-pull-request': 'false'
|
||||
}
|
||||
|
||||
let input
|
||||
@@ -29,6 +31,8 @@ let output
|
||||
const sandbox = sinon.createSandbox()
|
||||
process.env.GITHUB_REPOSITORY = 'google/cloud'
|
||||
|
||||
nock.disableNetConnect()
|
||||
|
||||
describe('release-please-action', () => {
|
||||
beforeEach(() => {
|
||||
input = {}
|
||||
@@ -43,230 +47,230 @@ describe('release-please-action', () => {
|
||||
return input[name]
|
||||
}
|
||||
}
|
||||
core.getBooleanInput = name => {
|
||||
// Float our own helper, for mocking purposes:
|
||||
const trueValue = ['true', 'True', 'TRUE']
|
||||
const falseValue = ['false', 'False', 'FALSE']
|
||||
const val = core.getInput(name)
|
||||
if (trueValue.includes(val)) { return true }
|
||||
if (falseValue.includes(val)) { return false }
|
||||
throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${name}\n` +
|
||||
'Support boolean input list: `true | True | TRUE | false | False | FALSE`')
|
||||
}
|
||||
// Default branch lookup:
|
||||
nock('https://api.github.com')
|
||||
.get('/repos/google/cloud')
|
||||
.reply(200, {
|
||||
default_branch: 'main'
|
||||
})
|
||||
})
|
||||
afterEach(() => {
|
||||
sandbox.restore()
|
||||
})
|
||||
|
||||
const trueValue = ['true', 'True', 'TRUE', 'yes', 'Yes', 'YES', 'y', 'Y', 'on', 'On', 'ON']
|
||||
const falseValue = ['false', 'False', 'FALSE', 'no', 'No', 'NO', 'n', 'N', 'off', 'Off', 'OFF']
|
||||
|
||||
trueValue.forEach(value => {
|
||||
it(`get the boolean true with the input of '${value}'`, () => {
|
||||
input = {
|
||||
fork: value
|
||||
}
|
||||
const actual = action.getBooleanInput('fork')
|
||||
assert.strictEqual(actual, true)
|
||||
})
|
||||
})
|
||||
|
||||
falseValue.forEach(value => {
|
||||
it(`get the boolean with the input of '${value}'`, () => {
|
||||
input = {
|
||||
fork: value
|
||||
}
|
||||
const actual = action.getBooleanInput('fork')
|
||||
assert.strictEqual(actual, false)
|
||||
})
|
||||
})
|
||||
|
||||
it('get an error when inputting the wrong boolean value', () => {
|
||||
input = {
|
||||
fork: 'wrong'
|
||||
}
|
||||
assert.throws(
|
||||
() => {
|
||||
action.getBooleanInput('fork')
|
||||
},
|
||||
{ name: 'TypeError', message: "Wrong boolean value of the input 'fork'" }
|
||||
)
|
||||
})
|
||||
|
||||
it('sets pull pullRequestTitlePattern to undefined, if empty string provided', async () => {
|
||||
input = {
|
||||
'release-type': 'node',
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
'pull-request-title-pattern': ''
|
||||
}
|
||||
|
||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||
const githubReleasePRStub = runCommandStub.withArgs('release-pr').returns(25)
|
||||
|
||||
await action.main()
|
||||
|
||||
sinon.assert.calledOnce(githubReleasePRStub)
|
||||
sinon.assert.calledWith(
|
||||
githubReleasePRStub,
|
||||
'release-pr',
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
sinon.match.hasOwn('pullRequestTitlePattern', undefined)
|
||||
)
|
||||
})
|
||||
|
||||
it('opens PR with custom changelogSections', async () => {
|
||||
input = {
|
||||
command: 'release-pr',
|
||||
'release-type': 'node',
|
||||
'changelog-types':
|
||||
'[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]'
|
||||
}
|
||||
|
||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||
const githubReleasePRStub = runCommandStub.withArgs('release-pr').returns(25)
|
||||
|
||||
const createPullRequestsFake = sandbox.fake.returns([22])
|
||||
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||
createPullRequests: createPullRequestsFake
|
||||
})
|
||||
await action.main()
|
||||
|
||||
sinon.assert.calledOnce(githubReleasePRStub)
|
||||
sinon.assert.calledOnce(createPullRequestsFake)
|
||||
sinon.assert.calledWith(
|
||||
githubReleasePRStub,
|
||||
'release-pr',
|
||||
createManifestCommand,
|
||||
sinon.match.any,
|
||||
'main',
|
||||
sinon.match.hasOwn(
|
||||
'changelogSections',
|
||||
JSON.parse(
|
||||
'[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]'
|
||||
)
|
||||
)
|
||||
),
|
||||
sinon.match.any
|
||||
)
|
||||
})
|
||||
|
||||
it('opens PR with custom title', async () => {
|
||||
input = {
|
||||
command: 'release-pr',
|
||||
'release-type': 'node',
|
||||
'pull-request-title-pattern': 'beep boop'
|
||||
}
|
||||
|
||||
const createPullRequestsFake = sandbox.fake.returns([22])
|
||||
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||
createPullRequests: createPullRequestsFake
|
||||
})
|
||||
await action.main()
|
||||
|
||||
sinon.assert.calledOnce(createPullRequestsFake)
|
||||
sinon.assert.calledWith(
|
||||
createManifestCommand,
|
||||
sinon.match.any,
|
||||
'main',
|
||||
sinon.match.hasOwn(
|
||||
'pullRequestTitlePattern',
|
||||
'beep boop'
|
||||
),
|
||||
sinon.match.any
|
||||
)
|
||||
})
|
||||
|
||||
it('both opens PR to the default branch and tags GitHub releases by default', async () => {
|
||||
input = {
|
||||
'release-type': 'node'
|
||||
}
|
||||
input = {}
|
||||
|
||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||
|
||||
const githubReleaseStub = runCommandStub.withArgs('github-release').returns({
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0'
|
||||
const createReleasesFake = sandbox.fake.returns([
|
||||
{
|
||||
upload_url: 'http://example.com',
|
||||
tagName: 'v1.0.0'
|
||||
}
|
||||
])
|
||||
const createPullRequestsFake = sandbox.fake.returns([22])
|
||||
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||
createPullRequests: createPullRequestsFake,
|
||||
createReleases: createReleasesFake
|
||||
})
|
||||
|
||||
const githubReleasePRStub = runCommandStub.withArgs('release-pr').returns(25)
|
||||
|
||||
await action.main()
|
||||
|
||||
sinon.assert.calledOnce(githubReleaseStub)
|
||||
sinon.assert.calledOnce(githubReleasePRStub)
|
||||
sinon.assert.calledWith(
|
||||
githubReleaseStub,
|
||||
'github-release',
|
||||
sinon.match.hasOwn('defaultBranch', undefined)
|
||||
)
|
||||
sinon.assert.calledWith(
|
||||
githubReleasePRStub,
|
||||
'release-pr',
|
||||
sinon.match.hasOwn('defaultBranch', undefined)
|
||||
)
|
||||
sinon.assert.calledOnce(createManifestCommand)
|
||||
sinon.assert.calledOnce(createPullRequestsFake)
|
||||
sinon.assert.calledWith(createReleasesFake)
|
||||
assert.deepStrictEqual(output, {
|
||||
release_created: true,
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0',
|
||||
pr: 25
|
||||
pr: 22,
|
||||
prs: '[22]',
|
||||
releases_created: true,
|
||||
paths_released: '["."]'
|
||||
})
|
||||
})
|
||||
|
||||
it('both opens PR to a different default branch and tags GitHub releases by default', async () => {
|
||||
input = {
|
||||
'release-type': 'node',
|
||||
'default-branch': 'dev'
|
||||
}
|
||||
|
||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||
|
||||
const githubReleaseStub = runCommandStub.withArgs('github-release').returns({
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0'
|
||||
const createReleasesFake = sandbox.fake.returns([
|
||||
{
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0'
|
||||
}
|
||||
])
|
||||
const createPullRequestsFake = sandbox.fake.returns([22])
|
||||
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||
createPullRequests: createPullRequestsFake,
|
||||
createReleases: createReleasesFake
|
||||
})
|
||||
|
||||
const githubReleasePRStub = runCommandStub.withArgs('release-pr').returns(25)
|
||||
|
||||
await action.main()
|
||||
|
||||
sinon.assert.calledOnce(githubReleaseStub)
|
||||
sinon.assert.calledOnce(createPullRequestsFake)
|
||||
sinon.assert.calledWith(createReleasesFake)
|
||||
sinon.assert.calledWith(
|
||||
githubReleaseStub,
|
||||
'github-release',
|
||||
sinon.match.hasOwn('defaultBranch', 'dev')
|
||||
createManifestCommand,
|
||||
sinon.match.any,
|
||||
'dev',
|
||||
sinon.match.any,
|
||||
sinon.match.any
|
||||
)
|
||||
sinon.assert.calledOnce(githubReleasePRStub)
|
||||
sinon.assert.calledWith(
|
||||
githubReleasePRStub,
|
||||
'release-pr',
|
||||
sinon.match.hasOwn('defaultBranch', 'dev')
|
||||
)
|
||||
|
||||
assert.deepStrictEqual(output, {
|
||||
release_created: true,
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0',
|
||||
pr: 25
|
||||
pr: 22,
|
||||
prs: '[22]',
|
||||
releases_created: true,
|
||||
paths_released: '["."]'
|
||||
})
|
||||
})
|
||||
|
||||
it('only opens PR, if command set to release-pr', async () => {
|
||||
input = {
|
||||
'release-type': 'node',
|
||||
command: 'release-pr'
|
||||
}
|
||||
|
||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||
|
||||
const githubReleaseStub = runCommandStub.withArgs('github-release').returns({
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0'
|
||||
const createReleasesFake = sandbox.fake.returns([
|
||||
{
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0'
|
||||
}
|
||||
])
|
||||
const createPullRequestsFake = sandbox.fake.returns([22])
|
||||
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||
createPullRequests: createPullRequestsFake,
|
||||
createReleases: createReleasesFake
|
||||
})
|
||||
|
||||
const githubReleasePRStub = runCommandStub.withArgs('release-pr').returns(25)
|
||||
|
||||
await action.main()
|
||||
sinon.assert.notCalled(githubReleaseStub)
|
||||
sinon.assert.calledOnce(githubReleasePRStub)
|
||||
|
||||
sinon.assert.calledOnce(createManifestCommand)
|
||||
sinon.assert.calledOnce(createPullRequestsFake)
|
||||
sinon.assert.notCalled(createReleasesFake)
|
||||
assert.deepStrictEqual(output, {
|
||||
pr: 22,
|
||||
prs: '[22]'
|
||||
})
|
||||
})
|
||||
|
||||
it('only creates GitHub release, if command set to github-release', async () => {
|
||||
input = {
|
||||
'release-type': 'node',
|
||||
command: 'github-release'
|
||||
}
|
||||
|
||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||
|
||||
const githubReleaseStub = runCommandStub.withArgs('github-release').returns({
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0'
|
||||
const createReleasesFake = sandbox.fake.returns([
|
||||
{
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0'
|
||||
}
|
||||
])
|
||||
const createPullRequestsFake = sandbox.fake.returns([22])
|
||||
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||
createPullRequests: createPullRequestsFake,
|
||||
createReleases: createReleasesFake
|
||||
})
|
||||
|
||||
const githubReleasePRStub = runCommandStub.withArgs('release-pr').returns(25)
|
||||
|
||||
await action.main()
|
||||
sinon.assert.calledOnce(githubReleaseStub)
|
||||
sinon.assert.notCalled(githubReleasePRStub)
|
||||
|
||||
sinon.assert.calledOnce(createManifestCommand)
|
||||
sinon.assert.notCalled(createPullRequestsFake)
|
||||
sinon.assert.calledOnce(createReleasesFake)
|
||||
assert.deepStrictEqual(output, {
|
||||
release_created: true,
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0',
|
||||
releases_created: true,
|
||||
paths_released: '["."]'
|
||||
})
|
||||
})
|
||||
|
||||
it('sets appropriate outputs when GitHub release created', async () => {
|
||||
const expected = {
|
||||
release_created: true,
|
||||
releases_created: true,
|
||||
upload_url: 'http://example.com',
|
||||
html_url: 'http://example2.com',
|
||||
tag_name: 'v1.0.0',
|
||||
tag_name: 'v1.2.3',
|
||||
major: 1,
|
||||
minor: 2,
|
||||
patch: 3,
|
||||
version: 'v1.2.3',
|
||||
sha: 'abc123',
|
||||
pr: 33
|
||||
pr: 33,
|
||||
paths_released: '["."]'
|
||||
}
|
||||
input = {
|
||||
'release-type': 'node',
|
||||
command: 'github-release'
|
||||
}
|
||||
|
||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||
|
||||
runCommandStub.withArgs('github-release').returns(expected)
|
||||
|
||||
runCommandStub.withArgs('release-pr').returns(25)
|
||||
|
||||
const createReleasesFake = sandbox.fake.returns([expected])
|
||||
sandbox.stub(Manifest, 'fromConfig').returns({
|
||||
createReleases: createReleasesFake
|
||||
})
|
||||
await action.main()
|
||||
assert.deepStrictEqual(output, expected)
|
||||
})
|
||||
@@ -276,13 +280,18 @@ describe('release-please-action', () => {
|
||||
'release-type': 'node',
|
||||
command: 'release-pr'
|
||||
}
|
||||
|
||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||
|
||||
runCommandStub.withArgs('release-pr').returns(95)
|
||||
|
||||
const createPullRequestsFake = sandbox.fake.returns([22])
|
||||
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||
createPullRequests: createPullRequestsFake
|
||||
})
|
||||
await action.main()
|
||||
assert.strictEqual(output.pr, 95)
|
||||
|
||||
sinon.assert.calledOnce(createManifestCommand)
|
||||
sinon.assert.calledOnce(createPullRequestsFake)
|
||||
assert.deepStrictEqual(output, {
|
||||
pr: 22,
|
||||
prs: '[22]'
|
||||
})
|
||||
})
|
||||
|
||||
it('does not set PR output, when no release PR is returned', async () => {
|
||||
@@ -290,99 +299,129 @@ describe('release-please-action', () => {
|
||||
'release-type': 'node',
|
||||
command: 'release-pr'
|
||||
}
|
||||
|
||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||
|
||||
runCommandStub.withArgs('release-pr').returns(undefined)
|
||||
|
||||
const createPullRequestsFake = sandbox.fake.returns([undefined])
|
||||
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||
createPullRequests: createPullRequestsFake
|
||||
})
|
||||
await action.main()
|
||||
sinon.assert.calledOnce(createManifestCommand)
|
||||
sinon.assert.calledOnce(createPullRequestsFake)
|
||||
assert.strictEqual(Object.hasOwnProperty.call(output, 'pr'), false)
|
||||
})
|
||||
|
||||
it('creates and runs a ReleasePR instance, using factory', async () => {
|
||||
let maybeReleasePR
|
||||
sandbox.replace(factory, 'call', runnable => {
|
||||
maybeReleasePR = runnable
|
||||
})
|
||||
input = {
|
||||
'release-type': 'node',
|
||||
command: 'release-pr'
|
||||
}
|
||||
await action.main()
|
||||
assert.ok(maybeReleasePR instanceof Node)
|
||||
})
|
||||
|
||||
it('creates and runs a GitHubRelease, using factory', async () => {
|
||||
let maybeGitHubRelease
|
||||
sandbox.replace(factory, 'call', runnable => {
|
||||
maybeGitHubRelease = runnable
|
||||
})
|
||||
it('does not set release output, when no release is returned', async () => {
|
||||
input = {
|
||||
'release-type': 'node',
|
||||
command: 'github-release'
|
||||
}
|
||||
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
|
||||
const createReleasesFake = sandbox.fake.returns([undefined])
|
||||
sandbox.stub(Manifest, 'fromConfig').returns({
|
||||
createReleases: createReleasesFake
|
||||
})
|
||||
input = { command: 'manifest' }
|
||||
await action.main()
|
||||
assert.ok(maybeManifest instanceof Manifest)
|
||||
assert.deepStrictEqual(output, { paths_released: '[]' })
|
||||
})
|
||||
|
||||
it('opens PR creates GitHub releases by default for manifest', async () => {
|
||||
it('creates and runs a manifest release', async () => {
|
||||
input = { command: 'manifest' }
|
||||
|
||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||
|
||||
const manifestReleaseStub = runCommandStub.withArgs('manifest-release').resolves(
|
||||
const createReleasesFake = sandbox.fake.returns([
|
||||
{
|
||||
'path/pkgA':
|
||||
{
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0'
|
||||
},
|
||||
'.': {
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0'
|
||||
}
|
||||
})
|
||||
|
||||
const manifestReleasePRStub = runCommandStub.withArgs('manifest-pr').returns(25)
|
||||
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0'
|
||||
}
|
||||
])
|
||||
const createPullRequestsFake = sandbox.fake.returns([22])
|
||||
const createManifestCommand = sandbox.stub(Manifest, 'fromManifest').returns({
|
||||
createPullRequests: createPullRequestsFake,
|
||||
createReleases: createReleasesFake
|
||||
})
|
||||
await action.main()
|
||||
|
||||
sinon.assert.calledOnce(manifestReleaseStub)
|
||||
sinon.assert.calledOnce(manifestReleasePRStub)
|
||||
sinon.assert.calledOnce(createPullRequestsFake)
|
||||
sinon.assert.calledWith(createReleasesFake)
|
||||
sinon.assert.calledWith(
|
||||
createManifestCommand,
|
||||
sinon.match.any,
|
||||
'main',
|
||||
sinon.match.any,
|
||||
sinon.match.any
|
||||
)
|
||||
assert.deepStrictEqual(output, {
|
||||
releases_created: true,
|
||||
release_created: true,
|
||||
'path/pkgA--upload_url': 'http://example.com',
|
||||
'path/pkgA--tag_name': 'v1.0.0',
|
||||
'path/pkgA--release_created': true,
|
||||
tag_name: 'v1.0.0',
|
||||
upload_url: 'http://example.com',
|
||||
pr: 25,
|
||||
paths_released: '["path/pkgA","."]'
|
||||
tag_name: 'v1.0.0',
|
||||
pr: 22,
|
||||
prs: '[22]',
|
||||
releases_created: true,
|
||||
paths_released: '["."]'
|
||||
})
|
||||
})
|
||||
|
||||
it('opens PR only for manifest-pr', async () => {
|
||||
input = { command: 'manifest-pr' }
|
||||
|
||||
const runCommandStub = sandbox.stub(factory, 'runCommand')
|
||||
const manifestReleasePRStub = runCommandStub.withArgs('manifest-pr').returns(25)
|
||||
|
||||
const createPullRequestsFake = sandbox.fake.returns([22])
|
||||
const createManifestCommand = sandbox.stub(Manifest, 'fromManifest').returns({
|
||||
createPullRequests: createPullRequestsFake
|
||||
})
|
||||
await action.main()
|
||||
|
||||
sinon.assert.calledOnce(manifestReleasePRStub)
|
||||
sinon.assert.calledOnce(createPullRequestsFake)
|
||||
sinon.assert.calledWith(
|
||||
createManifestCommand,
|
||||
sinon.match.any,
|
||||
'main',
|
||||
sinon.match.any,
|
||||
sinon.match.any
|
||||
)
|
||||
assert.deepStrictEqual(output, {
|
||||
pr: 25
|
||||
pr: 22,
|
||||
prs: '[22]'
|
||||
})
|
||||
})
|
||||
|
||||
it('sets appropriate output if multiple releases and prs created', async () => {
|
||||
input = { command: 'manifest' }
|
||||
const createReleasesFake = sandbox.fake.returns([
|
||||
{
|
||||
upload_url: 'http://example.com',
|
||||
tag_name: 'v1.0.0',
|
||||
path: 'a'
|
||||
},
|
||||
{
|
||||
upload_url: 'http://example2.com',
|
||||
tag_name: 'v1.2.0',
|
||||
path: 'b'
|
||||
}
|
||||
])
|
||||
const createPullRequestsFake = sandbox.fake.returns([22, 33])
|
||||
const createManifestCommand = sandbox.stub(Manifest, 'fromManifest').returns({
|
||||
createPullRequests: createPullRequestsFake,
|
||||
createReleases: createReleasesFake
|
||||
})
|
||||
await action.main()
|
||||
|
||||
sinon.assert.calledOnce(createPullRequestsFake)
|
||||
sinon.assert.calledWith(createReleasesFake)
|
||||
sinon.assert.calledWith(
|
||||
createManifestCommand,
|
||||
sinon.match.any,
|
||||
'main',
|
||||
sinon.match.any,
|
||||
sinon.match.any
|
||||
)
|
||||
assert.deepStrictEqual(output, {
|
||||
pr: 22,
|
||||
prs: '[22,33]',
|
||||
releases_created: true,
|
||||
'a--release_created': true,
|
||||
'a--upload_url': 'http://example.com',
|
||||
'a--tag_name': 'v1.0.0',
|
||||
'a--path': 'a',
|
||||
'b--release_created': true,
|
||||
'b--upload_url': 'http://example2.com',
|
||||
'b--tag_name': 'v1.2.0',
|
||||
'b--path': 'b',
|
||||
paths_released: '["a","b"]'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user