-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
147 lines (125 loc) · 4.17 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
export type Branch =
| string
| { name: string; prerelease?: boolean; channel?: string }
export type Plugin = string | [string, Record<string, any>]
export enum ReleaseConfiguration {
Package = 'package',
}
export const defaultOptions = {
[ReleaseConfiguration.Package]: {
npmPublish: true,
branches: [{ name: 'master', channel: 'latest' }],
releaseMessage: 'chore(release): ${nextRelease.version} [npm-publish]',
},
}
function spruceSemanticRelease(options?: {
/** Use a pre-defined release configuration as your base options. */
config?: ReleaseConfiguration
/** Override the default branch configuration. */
branches?: Branch[]
/** Set the changelog filename to use. Default is CHANGELOG.md */
changelogFile?: string
/** Must be set to true to publish the package to NPM */
npmPublish?: boolean
/**
* Git message to use when creating a new release.
*
* Default: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}'
*/
releaseMessage?: string
}) {
if (!options) {
options = {}
}
if (options.config && defaultOptions[options.config]) {
options = defaultOptions[options.config]
}
const branches: Branch[] =
options.branches ||
defaultOptions[ReleaseConfiguration.Package].branches
const currentBranch = require('child_process')
.execSync('git rev-parse --abbrev-ref HEAD')
.toString()
.trim()
const isReleaseBranch = branches.find((b) => {
if (
b === currentBranch ||
(typeof b === 'object' &&
b.name === currentBranch &&
b.prerelease !== true)
) {
return true
}
return false
})
const verifyConditions = [
'@semantic-release/changelog',
'@semantic-release/github',
]
const publish = ['@semantic-release/github']
const prepare = []
const plugins: Plugin[] = [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
]
// Only bump the package.json version and write the changelog if this is a release branch
if (isReleaseBranch) {
prepare.push({
path: '@semantic-release/changelog',
changelogFile: options.changelogFile || 'CHANGELOG.md',
})
// NPM plugin handles bumping the package.json version
plugins.push([
'@semantic-release/npm',
{ npmPublish: options.npmPublish === true },
])
prepare.push([
'@semantic-release/npm',
{ npmPublish: options.npmPublish === true },
])
prepare.push([
'@semantic-release/git',
{
message:
options.releaseMessage ||
'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
},
])
plugins.push('@semantic-release/git')
plugins.push('@semantic-release/github')
}
if (options.npmPublish === true) {
publish.unshift('@semantic-release/npm')
verifyConditions.unshift('@semantic-release/npm')
}
return {
branches,
plugins,
publishConfig: {
registry: 'https://registry.npmjs.org/',
tag: 'beta',
},
verifyConditions,
prepare,
publish,
success: ['@semantic-release/github'],
fail: ['@semantic-release/github'],
generateNotes: {
config: 'conventional-changelog-sprucelabs',
},
analyzeCommits: {
config: 'conventional-changelog-sprucelabs',
releaseRules: [
{ type: 'BREAKING', release: 'major' },
{ type: 'breaking', release: 'major' },
{ type: 'major', release: 'major' },
{ type: 'feat', release: 'minor' },
{ type: 'minor', release: 'minor' },
{ type: 'bug', release: 'patch' },
// Custom default catch-all, treat it as a patch version
{ release: 'patch' },
],
},
}
}
export default spruceSemanticRelease