Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ await new Releaser({

| Step | Description |
| --- | --- |
| setUser | Set git user configuration. |
| checkout | Checkout the desired branch. |
| bump | Bump the version of the project and generate changelog. |
| commit | Commit the changes with the new version. |
Expand Down
20 changes: 20 additions & 0 deletions packages/core/src/releaser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ describe('core', () => {
expect(project.versionUpdates).toEqual([])
})

it('should set git user configuration', async () => {
const { cwd } = await forkProject('set-user', packageJsonProject())
const project = new PackageJsonProject({
path: join(cwd, 'package.json')
})
const releaser = new Releaser({
project,
silent: true
})
.setUser({
username: 'Release Bot',
email: 'release-bot@example.com'
})

await releaser.run()

expect(await project.gitClient.getConfig('user.name')).toBe('Release Bot')
expect(await project.gitClient.getConfig('user.email')).toBe('release-bot@example.com')
})

it('should create maintenance branches', async () => {
const { cwd } = await forkProject('maintenance-branch', packageJsonProject({
version: '3.0.0'
Expand Down
64 changes: 46 additions & 18 deletions packages/core/src/releaser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ReleaserOptions,
ReleaserCommitOptions,
ReleaserMaintenanceBranchOptions,
ReleaserSetUserOptions,
ReleaserTagOptions,
ReleaserPushOptions,
ReleaserStepsOptions
Expand Down Expand Up @@ -106,6 +107,51 @@ export class Releaser<
return this
}

/**
* Enqueue a task to set git user configuration.
* @param options
* @returns Project releaser instance for chaining.
*/
setUser(options?: ReleaserSetUserOptions) {
return this.enqueue(async () => {
const {
logger,
gitClient
} = this
const { dryRun } = this.options
const {
username,
email
} = {
...this.stepsOptions.setUser,
...options
}

logger.info('set-user', 'Setting git user...')

if (!username && !email) {
logger.info('set-user', 'No git user configuration provided.')
return
}

if (username) {
logger.verbose('set-user', `Setting git user.name to "${username}".`)

if (!dryRun) {
await gitClient.setConfig('user.name', username)
}
}

if (email) {
logger.verbose('set-user', `Setting git user.email to "${email}".`)

if (!dryRun) {
await gitClient.setConfig('user.email', email)
}
}
})
}

/**
* Enqueue a task to checkout a branch.
* @param branch - The branch to checkout, defaults to `'simple-release'`.
Expand All @@ -121,8 +167,6 @@ export class Releaser<
const { dryRun } = this.options
const {
branch: headBranch = 'simple-release',
username,
email,
fetch,
force
} = {
Expand All @@ -140,22 +184,6 @@ export class Releaser<
this.state.headBranch = headBranch
this.state.baseBranch = await this.getBaseBranch()

if (username) {
logger.verbose('checkout', `Setting git user.name to "${username}".`)

if (!dryRun) {
await gitClient.setConfig('user.name', username)
}
}

if (email) {
logger.verbose('checkout', `Setting git user.email to "${email}".`)

if (!dryRun) {
await gitClient.setConfig('user.email', email)
}
}

if (fetch) {
logger.verbose('checkout', `Fetching all commits and tags from the remote repository...`)

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/releaser.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export interface ReleaserCheckoutOptions {
* Force fetch all commits and tags from the remote repository.
*/
fetch?: boolean
}

export interface ReleaserSetUserOptions {
/**
* Set git user name configuration.
*/
Expand Down Expand Up @@ -77,6 +80,7 @@ export interface ReleaserStepsOptions<
checkout?: {
branch?: string
} & ReleaserCheckoutOptions
setUser?: ReleaserSetUserOptions
bump?: PickOverridableOptions<P['bump']>
commit?: ReleaserCommitOptions
maintenanceBranch?: ReleaserMaintenanceBranchOptions
Expand Down
2 changes: 2 additions & 0 deletions packages/github-action/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ To fetch and parse comments you should use `fetchOptions` step after `checkout`

```js
action
.setUser()
.checkout()
.fetchOptions()
.bump()
Comment on lines 149 to 153
Expand All @@ -160,6 +161,7 @@ action

```js
action
.setUser()
.maintenanceBranch()
.tag()
.push()
Expand Down
13 changes: 11 additions & 2 deletions packages/github-action/src/releaser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
type PickOverridableOptions,
type Project,
type ReleaserOptions,
type ReleaserSetUserOptions,
Releaser
} from '@simple-release/core'
import {
Expand Down Expand Up @@ -36,10 +37,16 @@ export class ReleaserGithubAction<P extends Project = Project> extends Releaser<
})
}

override checkout(branch?: string) {
return super.checkout(branch, {
override setUser(options?: ReleaserSetUserOptions) {
return super.setUser({
username: 'github-actions[bot]',
email: 'github-actions[bot]@users.noreply.github.com',
...options
})
Comment on lines +41 to +45
}

override checkout(branch?: string) {
return super.checkout(branch, {
fetch: true,
force: true
})
Expand Down Expand Up @@ -122,6 +129,7 @@ export class ReleaserGithubAction<P extends Project = Project> extends Releaser<
*/
async runPullRequestAction() {
await this
.setUser()
.checkout()
.fetchOptions()
.bump()
Comment on lines 131 to 135
Expand All @@ -137,6 +145,7 @@ export class ReleaserGithubAction<P extends Project = Project> extends Releaser<
*/
async runReleaseAction(check = true) {
await this
.setUser()
.maintenanceBranch()
.tag()
.push()
Expand Down