This repository has been archived by the owner on Mar 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
release.config.js
203 lines (183 loc) · 5.49 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
const { existsSync } = require("fs");
const { sync, commandSync } = require("execa");
const log = require("npmlog");
const plugins = [];
const noteKeywords = [
"BREAKING CHANGE",
"BREAKING CHANGES",
"BREAKING"
];
const {
GITHUB_SHA,
GITHUB_REPOSITORY,
GIT_COMMITTER_NAME,
GIT_COMMITTER_EMAIL,
GIT_AUTHOR_NAME,
GIT_AUTHOR_EMAIL,
} = process.env;
const successCmd = `
echo 'RELEASE_TAG=v\${nextRelease.version}' >> $GITHUB_ENV
echo 'RELEASE_VERSION=\${nextRelease.version}' >> $GITHUB_ENV
echo '::set-output name=release-tag::v\${nextRelease.version}'
echo '::set-output name=release-version::\${nextRelease.version}'
`;
const [owner, repo] = String(GITHUB_REPOSITORY).toLowerCase().split("/");
const addPlugin = (plugin, options) => {
log.info(`${plugin} enabled ${options && 'with options:'}`);
options && log.info(null, options);
return plugins.push([plugin, options]);
};
log.info(`Executing semantic-release config setup`);
!GIT_COMMITTER_NAME && (process.env.GIT_COMMITTER_NAME = "open-sauced[bot]");
!GIT_COMMITTER_EMAIL && (process.env.GIT_COMMITTER_EMAIL = "63161813+open-sauced[bot]@users.noreply.github.com");
try {
const { stdout: authorName } = sync("git", ["log", "-1", "--pretty=format:%an", GITHUB_SHA]);
const { stdout: authorEmail } = sync("git", ["log", "-1", "--pretty=format:%ae", GITHUB_SHA]);
authorName && !GIT_AUTHOR_NAME && (process.env.GIT_AUTHOR_NAME = `${authorName}`);
authorEmail && !GIT_AUTHOR_EMAIL && (process.env.GIT_AUTHOR_EMAIL = `${authorEmail}`);
} catch (e) {
log.error(`Unable to set GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL`, e);
}
addPlugin("@semantic-release/commit-analyzer", {
"preset": "conventionalcommits",
"releaseRules": [
{type: "feat", release: "minor"},
{type: "fix", release: "patch"},
{type: "perf", release: "patch"},
{type: "revert", release: "patch"},
{type: "docs", release: "minor"},
{type: "style", release: "patch"},
{type: "refactor", release: "patch"},
{type: "test", release: "patch"},
{type: "build", release: "patch"},
{type: "ci", release: "patch"},
{type: "chore", release: false}
],
"parserOpts": {
noteKeywords
}
});
addPlugin("@semantic-release/release-notes-generator", {
"preset": "conventionalcommits",
"parserOpts": {
noteKeywords
},
"writerOpts": {
"commitsSort": ["subject", "scope"]
},
"presetConfig": {
types: [
{type: "feat", section: "🍕 Features"},
{type: "feature", section: "🍕 Features"},
{type: "fix", section: "🐛 Bug Fixes"},
{type: "perf", section: "🔥 Performance Improvements"},
{type: "revert", section: "⏩ Reverts"},
{type: "docs", section: "📝 Documentation"},
{type: "style", section: "🎨 Styles"},
{type: "refactor", section: "🧑💻 Code Refactoring"},
{type: "test", section: "✅ Tests"},
{type: "build", section: "🤖 Build System"},
{type: "ci", section: "🔁 Continuous Integration"}
]
}
});
addPlugin("@semantic-release/changelog", {
"changelogTitle": `# 📦 ${owner}/${repo} changelog
[![conventional commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![semantic versioning](https://img.shields.io/badge/semantic%20versioning-2.0.0-green.svg)](https://semver.org)
> All notable changes to this project will be documented in this file`
});
addPlugin("@semantic-release/npm", {
"tarballDir": "pack"
});
const actionExists = existsSync("./action.yml");
if (actionExists) {
addPlugin("@google/semantic-release-replace-plugin", {
"replacements": [{
"files": [
"action.yml"
],
"from": `image: 'docker://ghcr.io/${owner}/${repo}:.*'`,
"to": `image: 'docker://ghcr.io/${owner}/${repo}:\${nextRelease.version}'`,
"results": [{
"file": "action.yml",
"hasChanged": true,
"numMatches": 1,
"numReplacements": 1
}],
"countMatches": true
}]
});
}
try {
const {stdout} = commandSync("ls -A1 LICENSE*", {
shell: true,
});
addPlugin("semantic-release-license", {
license: {
path: stdout
}
});
} catch (e) {
log.error(`Unable to run detect license command`, e);
}
addPlugin("@semantic-release/git", {
"assets": [
"LICENSE*",
"CHANGELOG.md",
"package.json",
"package-lock.json",
"npm-shrinkwrap.json",
"public/diagram.svg",
"action.yml"
],
"message": `chore(<%= nextRelease.type %>): release <%= nextRelease.version %> <%= nextRelease.channel !== null ? \`on \${nextRelease.channel} channel \` : '' %>[skip ci]\n\n<%= nextRelease.notes %>`
});
addPlugin("@semantic-release/github", {
"addReleases": "bottom",
"assets": [
{
"path": "pack/*.tgz",
"label": "Static distribution"
}
]
});
const dockerExists = existsSync("./Dockerfile");
if (dockerExists) {
addPlugin("eclass-docker-fork", {
"baseImageName": `${owner}/${repo}`,
"registries": [
{
"url": "ghcr.io",
"imageName": `ghcr.io/${owner}/${repo}`,
"user": "GITHUB_REPOSITORY_OWNER",
"password": "GITHUB_TOKEN"
}
]
});
}
if (process.env.GITHUB_ACTIONS !== undefined) {
addPlugin("@semantic-release/exec", {
successCmd,
});
}
module.exports = {
"branches": [
// maintenance releases
"+([0-9])?(.{+([0-9]),x}).x",
// release channels
"main",
"next",
"next-major",
// pre-releases
{
name: "beta",
prerelease: true
},
{
name: "alpha",
prerelease: true
}
],
plugins,
}