Skip to content

Commit 0efaae8

Browse files
committed
feat: change publish hook to prepare
BREAKING CHANGE: The plugin require sementic-release >=15.0.0 and has to be used in the `prepare` step rather than in `publish`.
1 parent c579428 commit 0efaae8

File tree

6 files changed

+46
-58
lines changed

6 files changed

+46
-58
lines changed

README.md

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Set of [Semantic-release](https://github.com/semantic-release/semantic-release)
1313

1414
Verify the access to the remote Git repository, the commit `message` format and the `assets` option configuration.
1515

16-
## publish
16+
## prepare
1717

18-
Publish a release commit, including configurable files.
18+
Create a release commit, including configurable files.
1919

2020
## Configuration
2121

@@ -83,42 +83,30 @@ Options can be set within the plugin definition in the Semantic-release configur
8383
```json
8484
{
8585
"release": {
86-
"publish": [
86+
"prepare": [
8787
"@semantic-release/npm",
8888
{
8989
"path": "@semantic-release/git",
9090
"assets": ["package.json", "dist/**/*.{js|css}", "docs"],
9191
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
92-
},
93-
"@semantic-release/github"
94-
]
92+
}
93+
],
94+
"publish": ["@semantic-release/github"]
9595
}
9696
}
9797
```
9898

99-
When using with the [changelog](https://github.com/semantic-release/changelog), [npm](https://github.com/semantic-release/npm) or [github](https://github.com/semantic-release/github) plugins:
99+
When using with the [changelog](https://github.com/semantic-release/changelog) or [npm](https://github.com/semantic-release/npm) plugins:
100100
- The [changelog](https://github.com/semantic-release/changelog) plugin must be called first in order to update the changelog file so the [git](https://github.com/semantic-release/git) and [npm](https://github.com/semantic-release/npm) plugin can include it in the release.
101101
- The [npm](https://github.com/semantic-release/npm) plugin must be called second in order to update the `package.json` file so the [git](https://github.com/semantic-release/git) plugin can include it in the release commit.
102-
- The [github](https://github.com/semantic-release/github) plugin must be called last to create a [GitHub Release](https://help.github.com/articles/about-releases/) that reference the tag created by the [git](https://github.com/semantic-release/git) plugin.
103102

104-
To use with the [changelog](https://github.com/semantic-release/changelog), [github](https://github.com/semantic-release/github) and [npm](https://github.com/semantic-release/npm) plugins:
103+
To use with the [changelog](https://github.com/semantic-release/changelog) and [npm](https://github.com/semantic-release/npm) plugins:
105104

106105
```json
107106
{
108107
"release": {
109-
"verifyConditions": ["@semantic-release/changelog", "@semantic-release/npm", "@semantic-release/git", "@semantic-release/github"],
110-
"publish": ["@semantic-release/changelog", "@semantic-release/npm", "@semantic-release/git", "@semantic-release/github"]
111-
}
112-
}
113-
```
114-
115-
To use with [github](https://github.com/semantic-release/github):
116-
117-
```json
118-
{
119-
"release": {
120-
"verifyConditions": ["@semantic-release/git", "@semantic-release/github"],
121-
"publish": ["@semantic-release/git", "@semantic-release/github"]
108+
"verifyConditions": ["@semantic-release/changelog", "@semantic-release/npm", "@semantic-release/git"],
109+
"prepare": ["@semantic-release/changelog", "@semantic-release/npm", "@semantic-release/git"]
122110
}
123111
}
124112
```

index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
const {castArray} = require('lodash');
22
const verifyGit = require('./lib/verify');
3-
const publishGit = require('./lib/publish');
3+
const prepareGit = require('./lib/prepare');
44

55
let verified;
66

77
async function verifyConditions(pluginConfig, context) {
88
const {options} = context;
9-
// If the Git publish plugin is used and has `assets` or `message` configured, validate them now in order to prevent any release if the configuration is wrong
10-
if (options.publish) {
11-
const publishPlugin =
12-
castArray(options.publish).find(config => config.path && config.path === '@semantic-release/git') || {};
9+
// If the Git prepare plugin is used and has `assets` or `message` configured, validate them now in order to prevent any release if the configuration is wrong
10+
if (options.prepare) {
11+
const preparePlugin =
12+
castArray(options.prepare).find(config => config.path && config.path === '@semantic-release/git') || {};
1313

14-
pluginConfig.assets = pluginConfig.assets || publishPlugin.assets;
15-
pluginConfig.message = pluginConfig.message || publishPlugin.message;
14+
pluginConfig.assets = pluginConfig.assets || preparePlugin.assets;
15+
pluginConfig.message = pluginConfig.message || preparePlugin.message;
1616
}
1717
await verifyGit(pluginConfig);
1818
verified = true;
1919
}
2020

21-
async function publish(pluginConfig, context) {
21+
async function prepare(pluginConfig, context) {
2222
if (!verified) {
2323
await verifyGit(pluginConfig);
2424
verified = true;
2525
}
26-
await publishGit(pluginConfig, context);
26+
await prepareGit(pluginConfig, context);
2727
}
2828

29-
module.exports = {verifyConditions, publish};
29+
module.exports = {verifyConditions, prepare};

lib/publish.js renamed to lib/prepare.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const PKG_LOCK = 'package-lock.json';
1313
const SKW_JSON = 'npm-shrinkwrap.json';
1414

1515
/**
16-
* Publish a release commit including configurable files.
16+
* Prepare a release commit including configurable files.
1717
*
1818
* @param {Object} pluginConfig The plugin configuration.
1919
* @param {String|Array<String>} [pluginConfig.assets] Files to include in the release commit. Can be files path or globs.
@@ -88,5 +88,5 @@ module.exports = async (pluginConfig, {options: {branch, repositoryUrl}, lastRel
8888

8989
logger.log('Creating tag %s', nextRelease.gitTag);
9090
await push(repositoryUrl, branch);
91-
logger.log('Published Git release: %s', nextRelease.gitTag);
91+
logger.log('Prepared Git release: %s', nextRelease.gitTag);
9292
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"all": true
7575
},
7676
"peerDependencies": {
77-
"semantic-release": ">=13.3.0 <15.0.0"
77+
"semantic-release": ">=15.0.0 <16.0.0"
7878
},
7979
"prettier": {
8080
"printWidth": 120

test/integration.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test.afterEach.always(() => {
4040
process.chdir(cwd);
4141
});
4242

43-
test.serial('Publish from a shallow clone', async t => {
43+
test.serial('Prepare from a shallow clone', async t => {
4444
process.env.GIT_EMAIL = 'user@email.com';
4545
process.env.GIT_USERNAME = 'user';
4646
const branch = 'master';
@@ -62,7 +62,7 @@ test.serial('Publish from a shallow clone', async t => {
6262
message: `Release version \${nextRelease.version} from branch \${branch}\n\n\${nextRelease.notes}`,
6363
assets: '**/*.{js,json}',
6464
};
65-
await t.context.m.publish(pluginConfig, {logger: t.context.logger, options: {repositoryUrl, branch}, nextRelease});
65+
await t.context.m.prepare(pluginConfig, {logger: t.context.logger, options: {repositoryUrl, branch}, nextRelease});
6666

6767
t.deepEqual(await gitCommitedFiles(), ['dist/file.js', 'package.json']);
6868
const [commit] = await gitGetCommits();
@@ -73,7 +73,7 @@ test.serial('Publish from a shallow clone', async t => {
7373
t.is(commit.author.email, process.env.GIT_EMAIL);
7474
});
7575

76-
test.serial('Publish from a detached head repository', async t => {
76+
test.serial('Prepare from a detached head repository', async t => {
7777
const branch = 'master';
7878
const repositoryUrl = await gitRepo(true);
7979
await outputFile('package.json', "{name: 'test-package', version: '1.0.0'}");
@@ -93,7 +93,7 @@ test.serial('Publish from a detached head repository', async t => {
9393
message: `Release version \${nextRelease.version} from branch \${branch}\n\n\${nextRelease.notes}`,
9494
assets: '**/*.{js,json}',
9595
};
96-
await t.context.m.publish(pluginConfig, {logger: t.context.logger, options: {repositoryUrl, branch}, nextRelease});
96+
await t.context.m.prepare(pluginConfig, {logger: t.context.logger, options: {repositoryUrl, branch}, nextRelease});
9797

9898
t.deepEqual(await gitCommitedFiles(), ['dist/file.js', 'package.json']);
9999
const [commit] = await gitGetCommits();
@@ -106,16 +106,16 @@ test.serial('Verify authentication only on the fist call', async t => {
106106
const branch = 'master';
107107
const repositoryUrl = await gitRepo(true);
108108
const nextRelease = {version: '2.0.0', gitTag: 'v2.0.0'};
109-
const options = {repositoryUrl, branch, publish: ['@semantic-release/npm']};
109+
const options = {repositoryUrl, branch, prepare: ['@semantic-release/npm']};
110110

111111
await t.notThrows(t.context.m.verifyConditions({}, {options, logger: t.context.logger}));
112-
await t.context.m.publish({}, {logger: t.context.logger, options: {repositoryUrl, branch}, nextRelease});
112+
await t.context.m.prepare({}, {logger: t.context.logger, options: {repositoryUrl, branch}, nextRelease});
113113
});
114114

115-
test('Throw SemanticReleaseError if publish config is invalid', async t => {
115+
test('Throw SemanticReleaseError if prepare config is invalid', async t => {
116116
const message = 42;
117117
const assets = true;
118-
const options = {publish: ['@semantic-release/npm', {path: '@semantic-release/git', message, assets}]};
118+
const options = {prepare: ['@semantic-release/npm', {path: '@semantic-release/git', message, assets}]};
119119

120120
const errors = [...(await t.throws(t.context.m.verifyConditions({}, {options, logger: t.context.logger})))];
121121

test/publish.test.js renamed to test/prepare.test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava';
22
import {outputFile} from 'fs-extra';
33
import {stub} from 'sinon';
4-
import publish from '../lib/publish';
4+
import prepare from '../lib/prepare';
55
import {gitRepo, gitGetCommits, gitCommitedFiles} from './helpers/git-utils';
66

77
// Save the current process.env
@@ -40,7 +40,7 @@ test.serial(
4040
await outputFile('package-lock.json', "{name: 'test-package'}");
4141
await outputFile('npm-shrinkwrap.json', "{name: 'test-package'}");
4242

43-
await publish(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
43+
await prepare(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
4444

4545
// Verify the remote repo has a the version referencing the same commit sha at the local head
4646
const [commit] = await gitGetCommits();
@@ -60,7 +60,7 @@ test.serial(
6060
t.deepEqual(t.context.log.args[3], ['Add %s to the release commit', 'npm-shrinkwrap.json']);
6161
t.deepEqual(t.context.log.args[4], ['Found %d file(s) to commit', 4]);
6262
t.deepEqual(t.context.log.args[5], ['Creating tag %s', nextRelease.gitTag]);
63-
t.deepEqual(t.context.log.args[6], ['Published Git release: %s', nextRelease.gitTag]);
63+
t.deepEqual(t.context.log.args[6], ['Prepared Git release: %s', nextRelease.gitTag]);
6464
}
6565
);
6666

@@ -75,12 +75,12 @@ test.serial(
7575
await outputFile('package-lock.json', "{name: 'test-package'}");
7676
await outputFile('npm-shrinkwrap.json', "{name: 'test-package'}");
7777

78-
await publish(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
78+
await prepare(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
7979

8080
// Verify no files have been commited
8181
t.deepEqual(await gitCommitedFiles(), []);
8282
t.deepEqual(t.context.log.args[0], ['Creating tag %s', nextRelease.gitTag]);
83-
t.deepEqual(t.context.log.args[1], ['Published Git release: %s', nextRelease.gitTag]);
83+
t.deepEqual(t.context.log.args[1], ['Prepared Git release: %s', nextRelease.gitTag]);
8484
}
8585
);
8686

@@ -95,7 +95,7 @@ Last release: \${lastRelease.version}
9595
const nextRelease = {version: '2.0.0', gitTag: 'v2.0.0', notes: 'Test release note'};
9696
await outputFile('CHANGELOG.md', 'Initial CHANGELOG');
9797

98-
await publish(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
98+
await prepare(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
9999

100100
// Verify the files that have been commited
101101
t.deepEqual(await gitCommitedFiles(), ['CHANGELOG.md']);
@@ -122,7 +122,7 @@ test.serial('Commit files matching the patterns in "assets"', async t => {
122122
await outputFile('dir2/file6.js', 'Test content');
123123
await outputFile('dir2/file7.css', 'Test content');
124124

125-
await publish(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
125+
await prepare(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
126126

127127
// Verify file2 and file1 have been commited
128128
// file4.js is excluded as no glob matching
@@ -151,7 +151,7 @@ test.serial('Commit files matching the patterns in "assets" as Objects', async t
151151
await outputFile('dir2/file6.js', 'Test content');
152152
await outputFile('dir2/file7.css', 'Test content');
153153

154-
await publish(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
154+
await prepare(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
155155

156156
// Verify file2 and file1 have been commited
157157
// file4.js is excluded as no glob matching
@@ -170,7 +170,7 @@ test.serial('Commit files matching the patterns in "assets" as single glob', asy
170170
await outputFile('dist/file1.js', 'Test content');
171171
await outputFile('dist/file2.css', 'Test content');
172172

173-
await publish(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
173+
await prepare(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
174174

175175
t.deepEqual(await gitCommitedFiles(), ['dist/file1.js']);
176176

@@ -184,7 +184,7 @@ test.serial('Commit files matching the patterns in "assets", including dot files
184184

185185
await outputFile('dist/.dotfile', 'Test content');
186186

187-
await publish(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
187+
await prepare(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
188188

189189
t.deepEqual(await gitCommitedFiles(), ['dist/.dotfile']);
190190

@@ -198,7 +198,7 @@ test.serial('Skip negated pattern if its alone in its group', async t => {
198198

199199
await outputFile('file.js', 'Test content');
200200

201-
await publish(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
201+
await prepare(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
202202

203203
t.deepEqual(await gitCommitedFiles(), ['file.js']);
204204

@@ -210,12 +210,12 @@ test.serial('Skip commit if there is no files to commit', async t => {
210210
const lastRelease = {};
211211
const nextRelease = {version: '2.0.0', gitTag: 'v2.0.0', notes: 'Test release note'};
212212

213-
await publish(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
213+
await prepare(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
214214

215215
// Verify the files that have been commited
216216
t.deepEqual(await gitCommitedFiles(), []);
217217
t.deepEqual(t.context.log.args[0], ['Creating tag %s', nextRelease.gitTag]);
218-
t.deepEqual(t.context.log.args[1], ['Published Git release: %s', nextRelease.gitTag]);
218+
t.deepEqual(t.context.log.args[1], ['Prepared Git release: %s', nextRelease.gitTag]);
219219
});
220220

221221
test.serial('Skip commit if all the modified files are in .gitignore', async t => {
@@ -226,10 +226,10 @@ test.serial('Skip commit if all the modified files are in .gitignore', async t =
226226
await outputFile('dist/files1.js', 'Test content');
227227
await outputFile('.gitignore', 'dist/**/*');
228228

229-
await publish(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
229+
await prepare(pluginConfig, {options: t.context.options, lastRelease, nextRelease, logger: t.context.logger});
230230

231231
// Verify the files that have been commited
232232
t.deepEqual(await gitCommitedFiles(), []);
233233
t.deepEqual(t.context.log.args[0], ['Creating tag %s', nextRelease.gitTag]);
234-
t.deepEqual(t.context.log.args[1], ['Published Git release: %s', nextRelease.gitTag]);
234+
t.deepEqual(t.context.log.args[1], ['Prepared Git release: %s', nextRelease.gitTag]);
235235
});

0 commit comments

Comments
 (0)