Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
feat: manifest based releaser https://git.io/JmVD4 (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldodge79 committed Mar 24, 2021
1 parent 3428959 commit 45c32cc
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 7 deletions.
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -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

Expand Down
59 changes: 52 additions & 7 deletions 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'
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
39 changes: 39 additions & 0 deletions test/release-please.js
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
})
})
})

0 comments on commit 45c32cc

Please sign in to comment.