Skip to content

Commit cbcfd75

Browse files
committed
feat(semantic-release): configure for this formula
* https://github.com/semantic-release/semantic-release - Fully automated version management and package publishing. * This commit introduces automation for the following processes: - (1) Version number bumped based on commit message types. - (2) Tags and releases created in GitHub. - (3) Changelog updated using the same content in the GitHub release. - (4) `FORMULA` version number updated. - (5) PR comments sent to inform which release includes the changes.
1 parent 14174c3 commit cbcfd75

File tree

5 files changed

+151
-0
lines changed

5 files changed

+151
-0
lines changed

.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,26 @@ env:
1717
script:
1818
- bundle exec kitchen verify ${INSTANCE}
1919

20+
before_deploy:
21+
# Only deploy if the build passed successfully
22+
- test $TRAVIS_TEST_RESULT = 0
23+
24+
jobs:
25+
# Only run if this is the `master` branch
26+
if: branch = master
27+
include:
28+
# Define the release stage that runs semantic-release
29+
- stage: release
30+
language: node_js
31+
node_js: lts/*
32+
before_install: skip
33+
script:
34+
- npm install @semantic-release/changelog@3 -D
35+
- npm install @semantic-release/exec@3 -D
36+
- npm install @semantic-release/git@7 -D
37+
deploy:
38+
provider: script
39+
skip_cleanup: true
40+
script:
41+
- npx semantic-release@15
42+

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
template-formula
33
================
44

5+
|img_travis| |img_sr|
6+
7+
.. |img_travis| image:: https://travis-ci.com/saltstack-formulas/template-formula.svg?branch=master
8+
:target: https://travis-ci.com/saltstack-formulas/template-formula
9+
.. |img_sr| image:: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
10+
:target: https://github.com/semantic-release/semantic-release
11+
512
A SaltStack formula that is empty. It has dummy content to help with a quick
613
start on a new formula and it serves as a style guide.
714

release-rules.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// No release is triggered for the types commented out below.
2+
// Commits using these types will be incorporated into the next release.
3+
module.exports = [
4+
{breaking: true, release: 'major'},
5+
// {type: 'build', release: 'patch'},
6+
// {type: 'chore', release: 'patch'},
7+
// {type: 'ci', release: 'patch'},
8+
{type: 'docs', release: 'patch'},
9+
{type: 'feat', release: 'minor'},
10+
{type: 'fix', release: 'patch'},
11+
{type: 'perf', release: 'patch'},
12+
{type: 'refactor', release: 'patch'},
13+
{type: 'revert', release: 'patch'},
14+
{type: 'style', release: 'patch'},
15+
{type: 'test', release: 'patch'},
16+
];

release.config.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
module.exports = {
2+
branch: 'master',
3+
plugins: [
4+
['@semantic-release/commit-analyzer', {
5+
preset: 'angular',
6+
releaseRules: './release-rules.js',
7+
}],
8+
'@semantic-release/release-notes-generator',
9+
['@semantic-release/changelog', {
10+
changelogFile: 'CHANGELOG.md',
11+
changelogTitle: '# Changelog',
12+
}],
13+
['@semantic-release/exec', {
14+
prepareCmd: 'sh ./update_FORMULA.sh ${nextRelease.version}',
15+
}],
16+
['@semantic-release/git', {
17+
assets: ['CHANGELOG.md', 'FORMULA'],
18+
}],
19+
'@semantic-release/github',
20+
],
21+
generateNotes: {
22+
preset: 'angular',
23+
writerOpts: {
24+
// Required due to upstream bug preventing all types being displayed.
25+
// Bug: https://github.com/conventional-changelog/conventional-changelog/issues/317
26+
// Fix: https://github.com/conventional-changelog/conventional-changelog/pull/410
27+
transform: (commit, context) => {
28+
const issues = []
29+
30+
commit.notes.forEach(note => {
31+
note.title = `BREAKING CHANGES`
32+
})
33+
34+
if (commit.type === `feat`) {
35+
commit.type = `Features`
36+
} else if (commit.type === `fix`) {
37+
commit.type = `Bug Fixes`
38+
} else if (commit.type === `perf`) {
39+
commit.type = `Performance Improvements`
40+
} else if (commit.type === `revert`) {
41+
commit.type = `Reverts`
42+
} else if (commit.type === `docs`) {
43+
commit.type = `Documentation`
44+
} else if (commit.type === `style`) {
45+
commit.type = `Styles`
46+
} else if (commit.type === `refactor`) {
47+
commit.type = `Code Refactoring`
48+
} else if (commit.type === `test`) {
49+
commit.type = `Tests`
50+
} else if (commit.type === `build`) {
51+
commit.type = `Build System`
52+
} else if (commit.type === `ci`) {
53+
commit.type = `Continuous Integration`
54+
} else {
55+
return
56+
}
57+
58+
if (commit.scope === `*`) {
59+
commit.scope = ``
60+
}
61+
62+
if (typeof commit.hash === `string`) {
63+
commit.hash = commit.hash.substring(0, 7)
64+
}
65+
66+
if (typeof commit.subject === `string`) {
67+
let url = context.repository
68+
? `${context.host}/${context.owner}/${context.repository}`
69+
: context.repoUrl
70+
if (url) {
71+
url = `${url}/issues/`
72+
// Issue URLs.
73+
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
74+
issues.push(issue)
75+
return `[#${issue}](${url}${issue})`
76+
})
77+
}
78+
if (context.host) {
79+
// User URLs.
80+
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
81+
if (username.includes('/')) {
82+
return `@${username}`
83+
}
84+
85+
return `[@${username}](${context.host}/${username})`
86+
})
87+
}
88+
}
89+
90+
// remove references that already appear in the subject
91+
commit.references = commit.references.filter(reference => {
92+
if (issues.indexOf(reference.issue) === -1) {
93+
return true
94+
}
95+
96+
return false
97+
})
98+
99+
return commit
100+
},
101+
},
102+
},
103+
};

update_FORMULA.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
sed -i -e "s_^\(version:\).*_\1 ${1}_" FORMULA

0 commit comments

Comments
 (0)