Skip to content

Commit 135d94b

Browse files
authored
ci: add semantic release (#1113)
1 parent 7106bdb commit 135d94b

File tree

7 files changed

+248
-0
lines changed

7 files changed

+248
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: release-automated
2+
on:
3+
push:
4+
branches: [ master, release, alpha, beta ]
5+
jobs:
6+
release:
7+
runs-on: ubuntu-latest
8+
outputs:
9+
current_tag: ${{ steps.tag.outputs.current_tag }}
10+
steps:
11+
- uses: actions/checkout@v2
12+
with:
13+
persist-credentials: false
14+
- uses: actions/setup-node@v2
15+
with:
16+
node-version: 14
17+
- run: npm install -g -E [email protected] @semantic-release/[email protected] @semantic-release/[email protected] @semantic-release/[email protected] @semantic-release/[email protected]
18+
- run: npx semantic-release
19+
env:
20+
GH_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ jacoco.exec
4141

4242
# VSC
4343
.project
44+
45+
# Node
46+
node_modules/
47+
npm-debug.log
48+
package-lock.json

.releaserc/commit.hbs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
*{{#if scope}} **{{scope}}:**
2+
{{~/if}} {{#if subject}}
3+
{{~subject}}
4+
{{~else}}
5+
{{~header}}
6+
{{~/if}}
7+
8+
{{~!-- commit link --}} {{#if @root.linkReferences~}}
9+
([{{shortHash}}](
10+
{{~#if @root.repository}}
11+
{{~#if @root.host}}
12+
{{~@root.host}}/
13+
{{~/if}}
14+
{{~#if @root.owner}}
15+
{{~@root.owner}}/
16+
{{~/if}}
17+
{{~@root.repository}}
18+
{{~else}}
19+
{{~@root.repoUrl}}
20+
{{~/if}}/
21+
{{~@root.commit}}/{{hash}}))
22+
{{~else}}
23+
{{~shortHash}}
24+
{{~/if}}
25+
26+
{{~!-- commit references --}}
27+
{{~#if references~}}
28+
, closes
29+
{{~#each references}} {{#if @root.linkReferences~}}
30+
[
31+
{{~#if this.owner}}
32+
{{~this.owner}}/
33+
{{~/if}}
34+
{{~this.repository}}#{{this.issue}}](
35+
{{~#if @root.repository}}
36+
{{~#if @root.host}}
37+
{{~@root.host}}/
38+
{{~/if}}
39+
{{~#if this.repository}}
40+
{{~#if this.owner}}
41+
{{~this.owner}}/
42+
{{~/if}}
43+
{{~this.repository}}
44+
{{~else}}
45+
{{~#if @root.owner}}
46+
{{~@root.owner}}/
47+
{{~/if}}
48+
{{~@root.repository}}
49+
{{~/if}}
50+
{{~else}}
51+
{{~@root.repoUrl}}
52+
{{~/if}}/
53+
{{~@root.issue}}/{{this.issue}})
54+
{{~else}}
55+
{{~#if this.owner}}
56+
{{~this.owner}}/
57+
{{~/if}}
58+
{{~this.repository}}#{{this.issue}}
59+
{{~/if}}{{/each}}
60+
{{~/if}}
61+

.releaserc/footer.hbs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{#if noteGroups}}
2+
{{#each noteGroups}}
3+
4+
### {{title}}
5+
6+
{{#each notes}}
7+
* {{#if commit.scope}}**{{commit.scope}}:** {{/if}}{{text}} ([{{commit.shortHash}}]({{commit.shortHash}}))
8+
{{/each}}
9+
{{/each}}
10+
11+
{{/if}}

.releaserc/header.hbs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{{#if isPatch~}}
2+
##
3+
{{~else~}}
4+
#
5+
{{~/if}} {{#if @root.linkCompare~}}
6+
[{{version}}](
7+
{{~#if @root.repository~}}
8+
{{~#if @root.host}}
9+
{{~@root.host}}/
10+
{{~/if}}
11+
{{~#if @root.owner}}
12+
{{~@root.owner}}/
13+
{{~/if}}
14+
{{~@root.repository}}
15+
{{~else}}
16+
{{~@root.repoUrl}}
17+
{{~/if~}}
18+
/compare/{{previousTag}}...{{currentTag}})
19+
{{~else}}
20+
{{~version}}
21+
{{~/if}}
22+
{{~#if title}} "{{title}}"
23+
{{~/if}}
24+
{{~#if date}} ({{date}})
25+
{{/if}}

.releaserc/template.hbs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{> header}}
2+
3+
{{#each commitGroups}}
4+
5+
{{#if title}}
6+
### {{title}}
7+
8+
{{/if}}
9+
{{#each commits}}
10+
{{> commit root=@root}}
11+
{{/each}}
12+
{{/each}}
13+
14+
{{> footer}}

release.config.js

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* Semantic Release Config
3+
*/
4+
5+
const fs = require('fs').promises;
6+
const path = require('path');
7+
8+
// Get env vars
9+
const ref = process.env.GITHUB_REF;
10+
const serverUrl = process.env.GITHUB_SERVER_URL;
11+
const repository = process.env.GITHUB_REPOSITORY;
12+
const repositoryUrl = serverUrl + '/' + repository;
13+
14+
// Declare params
15+
const resourcePath = './.releaserc/';
16+
const templates = {
17+
main: { file: 'template.hbs', text: undefined },
18+
header: { file: 'header.hbs', text: undefined },
19+
commit: { file: 'commit.hbs', text: undefined },
20+
footer: { file: 'footer.hbs', text: undefined },
21+
};
22+
23+
// Declare semantic config
24+
async function config() {
25+
26+
// Get branch
27+
const branch = ref.split('/').pop();
28+
console.log(`Running on branch: ${branch}`);
29+
30+
// Set changelog file
31+
const changelogFile = `./changelogs/CHANGELOG_${branch}.md`;
32+
console.log(`Changelog file output to: ${changelogFile}`);
33+
34+
// Load template file contents
35+
await loadTemplates();
36+
37+
const config = {
38+
branches: [
39+
'master',
40+
// { name: 'alpha', prerelease: true },
41+
// { name: 'beta', prerelease: true },
42+
'next-major',
43+
// Long-Term-Support branches
44+
// { name: 'release-1', range: '1.x.x', channel: '1.x' },
45+
// { name: 'release-2', range: '2.x.x', channel: '2.x' },
46+
// { name: 'release-3', range: '3.x.x', channel: '3.x' },
47+
// { name: 'release-4', range: '4.x.x', channel: '4.x' },
48+
],
49+
dryRun: true,
50+
debug: true,
51+
ci: true,
52+
tagFormat: '${version}',
53+
plugins: [
54+
['@semantic-release/commit-analyzer', {
55+
preset: 'angular',
56+
releaseRules: [
57+
{ type: 'docs', scope: 'README', release: 'patch' },
58+
{ scope: 'no-release', release: false },
59+
],
60+
parserOpts: {
61+
noteKeywords: [ 'BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING' ],
62+
},
63+
}],
64+
['@semantic-release/release-notes-generator', {
65+
preset: 'angular',
66+
parserOpts: {
67+
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING']
68+
},
69+
writerOpts: {
70+
commitsSort: ['subject', 'scope'],
71+
mainTemplate: templates.main.text,
72+
headerPartial: templates.header.text,
73+
commitPartial: templates.commit.text,
74+
footerPartial: templates.footer.text,
75+
},
76+
}],
77+
['@semantic-release/changelog', {
78+
'changelogFile': changelogFile,
79+
}],
80+
['@semantic-release/git', {
81+
assets: [changelogFile],
82+
}],
83+
['@semantic-release/github', {
84+
successComment: getReleaseComment(),
85+
labels: ['type:ci'],
86+
releasedLabels: ['state:released<%= nextRelease.channel ? `-\${nextRelease.channel}` : "" %>']
87+
}],
88+
],
89+
};
90+
91+
return config;
92+
}
93+
94+
async function loadTemplates() {
95+
for (const template of Object.keys(templates)) {
96+
const text = await readFile(path.resolve(__dirname, resourcePath, templates[template].file));
97+
templates[template].text = text;
98+
}
99+
}
100+
101+
async function readFile(filePath) {
102+
return await fs.readFile(filePath, 'utf-8');
103+
}
104+
105+
function getReleaseComment() {
106+
const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}';
107+
let comment = '🎉 This pull request has been released in version [${nextRelease.version}](' + url + ')';
108+
return comment;
109+
}
110+
111+
module.exports = config();

0 commit comments

Comments
 (0)