-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
release.config.js
114 lines (101 loc) · 3.42 KB
/
release.config.js
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
// Generic release configuration.
//
// Required parameters are:
// 1. KIRA_RELEASE_ASSETS
// to release static files with gitlab
// 2. CI_PROJECT_NAMESPACE and CI_PROJECT_NAME
// to correctly set name of your docker image
// if you are using docker releases
//
// See README.md for more options and their description.
// Configuration:
const assets = process.env.KIRA_RELEASE_ASSETS || []
const replaceConfig = JSON.parse(
process.env.KIRA_RELEASE_REPLACE_CONFIG || '{}',
)
const execConfig = JSON.parse(process.env.KIRA_RELEASE_EXEC_CONFIG || '{}')
const skipDocker = process.env.KIRA_RELEASE_SKIP_DOCKER
const branches = JSON.parse(process.env.KIRA_RELEASE_BRANCHES || '["master", "main"]')
const includeComments = process.env.KIRA_INCLUDE_COMMENTS || 'off'
const gitlabComments = {
'off': false,
'issue': '<% return issue %>',
'mergeRequest': '<% return mergeRequest %>',
'all': '<% return issue || mergeRequest %>',
}
if (!(includeComments in gitlabComments)) {
throw new Error(
`Invalid value: ${includeComments} for: ${Object.keys(gitlabComments)}`,
)
}
// Files to be committed back to the repo later on:
const toBeCommitted = ['CHANGELOG.md']
if (replaceConfig.project) {
console.log('Found replacement configuration')
console.log(replaceConfig)
toBeCommitted.push(replaceConfig.project)
}
if (Object.keys(execConfig).length !== 0) {
console.log('Found exec configuration')
console.log(execConfig)
}
console.log('Going to commit:', toBeCommitted)
// Pipeline definition:
const releasePipeline = {
'branches': branches,
'plugins': [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
'@semantic-release/changelog',
],
}
// Maybe we should update some files with versions?
if (replaceConfig) {
releasePipeline.plugins.push([
'semantic-release-replace-plugin', {
'replacements': [{
'files': [replaceConfig.project],
'from': replaceConfig.from,
'to': replaceConfig.to,
'results': [
{
'file': replaceConfig.project,
'hasChanged': true,
'numMatches': 1,
'numReplacements': 1,
}
],
'countMatches': true,
}],
},
])
}
// We want to have this commit in a build before any `docker` stuff:
releasePipeline.plugins.push(['@semantic-release/git', { 'assets': toBeCommitted }])
// Maybe we should execute some extra steps before making a deployment?
if (Object.keys(execConfig).length !== 0) {
releasePipeline.plugins.push([
// See: https://github.com/semantic-release/exec
'@semantic-release/exec', execConfig,
])
}
// Back to basic release pipeline:
const successComment = 'This issue has been resolved in version ${nextRelease.version} 🎉'
const gitlabConfig = {
assets,
successComment,
'successCommentCondition': gitlabComments[includeComments],
}
releasePipeline.plugins.push(['@semantic-release/gitlab', gitlabConfig])
// Maybe we should crete a docker release?
// If it is not a docker-based app, this step will be ignored:
if (!skipDocker || skipDocker.toLowerCase() !== 'true') {
const imageName = `${process.env.CI_PROJECT_NAMESPACE}/${process.env.CI_PROJECT_NAME}`
console.log('Preparing docker image release:', imageName)
releasePipeline.plugins.push(['kira-release', { imageName }])
} else {
console.log(
`Skipping docker, because KIRA_RELEASE_SKIP_DOCKER is set to ${skipDocker}`,
)
}
module.exports = releasePipeline