-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(release): add git functionality
- Loading branch information
1 parent
5bff270
commit 357141b
Showing
8 changed files
with
61 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {executeWithErrorHandling, hasErrors, throwIfHasErrors} from '../utils'; | ||
import {type ContextWithNextRelease} from '../types'; | ||
|
||
export const gitCommit = async (context: ContextWithNextRelease): Promise<void> => { | ||
const {env, cwd, nextRelease} = context; | ||
|
||
await executeWithErrorHandling( | ||
'git', | ||
['commit', '-am', `chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}`], | ||
{ | ||
cwd, | ||
env, | ||
stdio: 'inherit', | ||
}, | ||
); | ||
|
||
if (!hasErrors()) { | ||
await executeWithErrorHandling('git', ['push', '--tags'], {env, cwd}); | ||
} | ||
|
||
throwIfHasErrors(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {type PrepareCmd} from '../types'; | ||
import {updatePackageJsonVersions} from './updatePackageJsonVersions'; | ||
import {gitCommit} from './gitCommit'; | ||
|
||
export const prepare: PrepareCmd = async (_, context) => { | ||
await updatePackageJsonVersions(context); | ||
await gitCommit(context); | ||
}; |
6 changes: 3 additions & 3 deletions
6
libs/semantic-release-plugin/src/prepare.ts → .../src/prepare/updatePackageJsonVersions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
libs/semantic-release-plugin/src/utils/executeWithErrorHandling.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {type Options} from 'execa'; | ||
import {execute} from './execute'; | ||
import {addError} from './errorHandling'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export const executeWithErrorHandling = async (command: string, args: string[], options?: Options) => { | ||
const result = await execute(command, args, options); | ||
|
||
if (result.stderr) { | ||
addError(new Error(`Command "${command} ${args.join(' ')}" failed: ${result.stderr}`)); | ||
} | ||
|
||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './errorHandling'; | ||
export * from './execute'; | ||
export * from './executeWithErrorHandling'; | ||
export * from './getPackageJson'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
import {addError, throwIfHasErrors} from './utils'; | ||
import {addError, throwIfHasErrors, execute} from './utils'; | ||
import {type VerifyConditionsCmd} from './types'; | ||
|
||
export const verifyConditions: VerifyConditionsCmd = (_, {env}) => { | ||
export const verifyConditions: VerifyConditionsCmd = async (_, {env}) => { | ||
if (!env.NPM_TOKEN) { | ||
addError(new Error('NPM_TOKEN environment variable is required')); | ||
} | ||
|
||
const result = await execute('git', ['push', 'origin', '--dry-run'], {env, stdio: 'ignore'}); | ||
|
||
if (result.stderr) { | ||
addError(new Error(result.stderr)); | ||
} | ||
|
||
throwIfHasErrors(); | ||
}; |