Skip to content

Commit f9b74e3

Browse files
committed
feat(defaults): update commit message version in semantic-release run
1 parent 7e5699e commit f9b74e3

File tree

5 files changed

+152
-4
lines changed

5 files changed

+152
-4
lines changed

pre-commit_semantic-release.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ sed -i -e '1,4s/-/=/g' CHANGELOG.rst
2828

2929
# Return back to the main directory
3030
cd ..
31+
32+
33+
###############################################################################
34+
# (C) Update `ssf/defaults.yaml` with `${nextRelease.version}`
35+
###############################################################################
36+
sed -i -e "s_^\(\s\+body: '\* Automated using \`ssf-formula\` (\).*\()'\)_\1${1}\2_" ssf/defaults.yaml

release.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
prepareCmd: 'sh ./pre-commit_semantic-release.sh ${nextRelease.version}',
1515
}],
1616
['@semantic-release/git', {
17-
assets: ['*.md', 'docs/*.rst', 'FORMULA'],
17+
assets: ['*.md', 'docs/*.rst', 'FORMULA', 'ssf/defaults.yaml'],
1818
}],
1919
'@semantic-release/github',
2020
],

ssf/defaults.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ ssf_node_anchors:
1010
base: master
1111
pr: chore/standardise-structure
1212
commit:
13-
# TODO: Replace the inline version number with a solution based upon getting the latest tag in the branch, i.e.
14-
# `git describe --abbrev=0 --tags`
15-
# Or may be even easier (and more sensible) to do via. `pre-commit_semantic-release.sh`
13+
# NOTE: The version number in the `body` is automatically updated during the release phase
14+
# via. `pre-commit_semantic-release.sh`
15+
# An alternative method could be to use: `git describe --abbrev=0 --tags`
1616
title: 'chore: use `semantic-release` cross-formula standard structure'
1717
body: '* Automated using `ssf-formula` (v0.1.0-rc.6)'
1818
github:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
3+
###############################################################################
4+
# (A) Update `FORMULA` with `${nextRelease.version}`
5+
###############################################################################
6+
sed -i -e "s_^\(version:\).*_\1 ${1}_" FORMULA
7+
8+
9+
###############################################################################
10+
# (B) Use `m2r` to convert automatically produced `.md` docs to `.rst`
11+
###############################################################################
12+
13+
# Install `m2r`
14+
sudo -H pip install m2r
15+
16+
# Copy and then convert the `.md` docs
17+
cp *.md docs/
18+
cd docs/
19+
m2r --overwrite *.md
20+
21+
# Change excess `H1` headings to `H2` in converted `CHANGELOG.rst`
22+
sed -i -e '/^=.*$/s/=/-/g' CHANGELOG.rst
23+
sed -i -e '1,4s/-/=/g' CHANGELOG.rst
24+
25+
# Use for debugging output, when required
26+
# cat AUTHORS.rst
27+
# cat CHANGELOG.rst
28+
29+
# Return back to the main directory
30+
cd ..
31+
32+
33+
###############################################################################
34+
# (C) Update `ssf/defaults.yaml` with `${nextRelease.version}`
35+
###############################################################################
36+
sed -i -e "s_^\(\s\+body: '\* Automated using \`ssf-formula\` (\).*\()'\)_\1${1}\2_" ssf/defaults.yaml
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 ./pre-commit_semantic-release.sh ${nextRelease.version}',
15+
}],
16+
['@semantic-release/git', {
17+
assets: ['*.md', 'docs/*.rst', 'FORMULA', 'ssf/defaults.yaml'],
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+
// NOTE: Any changes here must be reflected in `CONTRIBUTING.md`.
35+
if (commit.type === `feat`) {
36+
commit.type = `Features`
37+
} else if (commit.type === `fix`) {
38+
commit.type = `Bug Fixes`
39+
} else if (commit.type === `perf`) {
40+
commit.type = `Performance Improvements`
41+
} else if (commit.type === `revert`) {
42+
commit.type = `Reverts`
43+
} else if (commit.type === `docs`) {
44+
commit.type = `Documentation`
45+
} else if (commit.type === `style`) {
46+
commit.type = `Styles`
47+
} else if (commit.type === `refactor`) {
48+
commit.type = `Code Refactoring`
49+
} else if (commit.type === `test`) {
50+
commit.type = `Tests`
51+
} else if (commit.type === `build`) {
52+
commit.type = `Build System`
53+
// } else if (commit.type === `chore`) {
54+
// commit.type = `Maintenance`
55+
} else if (commit.type === `ci`) {
56+
commit.type = `Continuous Integration`
57+
} else {
58+
return
59+
}
60+
61+
if (commit.scope === `*`) {
62+
commit.scope = ``
63+
}
64+
65+
if (typeof commit.hash === `string`) {
66+
commit.hash = commit.hash.substring(0, 7)
67+
}
68+
69+
if (typeof commit.subject === `string`) {
70+
let url = context.repository
71+
? `${context.host}/${context.owner}/${context.repository}`
72+
: context.repoUrl
73+
if (url) {
74+
url = `${url}/issues/`
75+
// Issue URLs.
76+
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
77+
issues.push(issue)
78+
return `[#${issue}](${url}${issue})`
79+
})
80+
}
81+
if (context.host) {
82+
// User URLs.
83+
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
84+
if (username.includes('/')) {
85+
return `@${username}`
86+
}
87+
88+
return `[@${username}](${context.host}/${username})`
89+
})
90+
}
91+
}
92+
93+
// remove references that already appear in the subject
94+
commit.references = commit.references.filter(reference => {
95+
if (issues.indexOf(reference.issue) === -1) {
96+
return true
97+
}
98+
99+
return false
100+
})
101+
102+
return commit
103+
},
104+
},
105+
},
106+
};

0 commit comments

Comments
 (0)