Skip to content

Commit 8847380

Browse files
committed
feat: do not create Git tag anymore
BREAKING CHANGE: The Git tag is not created anymore The Git tag must be created by `semantic-release`. The plugin is compatible only with `[email protected]` or above.
1 parent a4273b6 commit 8847380

File tree

5 files changed

+1
-91
lines changed

5 files changed

+1
-91
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ Each individual plugin can be disabled, replaced or used with other plugins in t
8686
{
8787
"release": {
8888
"verifyConditions": ["@semantic-release/github", "@semantic-release/npm", "verify-other-condition"],
89-
"getLastRelease": "@semantic-release/npm",
9089
"publish": ["@semantic-release/npm", "@semantic-release/github", "other-publish"]
9190
}
9291
}

lib/publish.js

-15
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,6 @@ module.exports = async (pluginConfig, {branch, repositoryUrl}, {version, gitHead
2020
debug('release name: %o', gitTag);
2121
debug('release branch: %o', branch);
2222

23-
const ref = `refs/tags/${gitTag}`;
24-
25-
try {
26-
// Test if the tag already exists
27-
await github.gitdata.getReference({owner, repo, ref: `tags/${gitTag}`});
28-
debug('The git tag %o already exists', gitTag);
29-
} catch (err) {
30-
// If the error is 404, the tag doesn't exist, otherwise it's an error
31-
if (err.code !== 404) {
32-
throw err;
33-
}
34-
debug('Create git tag %o with commit %o', gitTag, gitHead);
35-
await github.gitdata.createReference({owner, repo, ref, sha: gitHead});
36-
}
37-
3823
const {data: {html_url: htmlUrl, upload_url: uploadUrl}} = await github.repos.createRelease(release);
3924
logger.log('Published GitHub release: %s', htmlUrl);
4025

lib/verify.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ module.exports = async (pluginConfig, {repositoryUrl}, logger) => {
2828

2929
const {name: repo, owner} = parseGithubUrl(repositoryUrl);
3030
if (!owner || !repo) {
31-
throw new SemanticReleaseError(
32-
`The git repository URL ${repositoryUrl} is not a valid GitHub URL.`,
33-
'EINVALIDGITURL'
34-
);
31+
throw new SemanticReleaseError(`The git repository URL is not a valid GitHub URL.`, 'EINVALIDGITURL');
3532
}
3633

3734
if (githubUrl) {

test/integration.test.js

-8
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ test.serial('Publish a release with an array of assets', async t => {
127127
const github = authenticate()
128128
.get(`/repos/${owner}/${repo}`)
129129
.reply(200, {permissions: {push: true}})
130-
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
131-
.reply(404)
132-
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${nextRelease.gitTag}`, sha: nextRelease.gitHead})
133-
.reply({})
134130
.post(`/repos/${owner}/${repo}/releases`, {
135131
tag_name: nextRelease.gitTag,
136132
target_commitish: options.branch,
@@ -185,10 +181,6 @@ test.serial('Verify GitHub auth and release', async t => {
185181
const github = authenticate()
186182
.get(`/repos/${owner}/${repo}`)
187183
.reply(200, {permissions: {push: true}})
188-
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
189-
.reply(404)
190-
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${nextRelease.gitTag}`, sha: nextRelease.gitHead})
191-
.reply({})
192184
.post(`/repos/${owner}/${repo}/releases`, {
193185
tag_name: nextRelease.gitTag,
194186
target_commitish: options.branch,

test/publish.test.js

-63
Original file line numberDiff line numberDiff line change
@@ -46,39 +46,6 @@ test.serial('Publish a release', async t => {
4646
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
4747

4848
const github = authenticate()
49-
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
50-
.reply(404)
51-
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${nextRelease.gitTag}`, sha: nextRelease.gitHead})
52-
.reply({})
53-
.post(`/repos/${owner}/${repo}/releases`, {
54-
tag_name: nextRelease.gitTag,
55-
target_commitish: options.branch,
56-
name: nextRelease.gitTag,
57-
body: nextRelease.notes,
58-
})
59-
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl});
60-
61-
await publish(pluginConfig, options, nextRelease, t.context.logger);
62-
63-
t.deepEqual(t.context.log.args[0], ['Published GitHub release: %s', releaseUrl]);
64-
t.true(github.isDone());
65-
});
66-
67-
test.serial('Publish a release with an existing tag', async t => {
68-
const owner = 'test_user';
69-
const repo = 'test_repo';
70-
process.env.GITHUB_TOKEN = 'github_token';
71-
const pluginConfig = {};
72-
const nextRelease = {version: '1.0.0', gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
73-
const options = {branch: 'master', repositoryUrl: `https://github.com/${owner}/${repo}.git`};
74-
const releaseUrl = `https://github.com/${owner}/${repo}/releases/${nextRelease.version}`;
75-
const releaseId = 1;
76-
const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`;
77-
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
78-
79-
const github = authenticate({})
80-
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
81-
.reply({ref: `refs/tags/${nextRelease.gitTag}`, object: {sha: 'e23a1bd8d7240c1eb3287374956042ffbcadca84'}})
8249
.post(`/repos/${owner}/${repo}/releases`, {
8350
tag_name: nextRelease.gitTag,
8451
target_commitish: options.branch,
@@ -109,10 +76,6 @@ test.serial('Publish a release with one asset', async t => {
10976
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
11077

11178
const github = authenticate()
112-
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
113-
.reply(404)
114-
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${nextRelease.gitTag}`, sha: nextRelease.gitHead})
115-
.reply({})
11679
.post(`/repos/${owner}/${repo}/releases`, {
11780
tag_name: nextRelease.gitTag,
11881
target_commitish: options.branch,
@@ -161,10 +124,6 @@ test.serial('Publish a release with one asset and custom github url', async t =>
161124
githubUrl: process.env.GH_URL,
162125
githubApiPathPrefix: process.env.GH_PREFIX,
163126
})
164-
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
165-
.reply(404)
166-
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${nextRelease.gitTag}`, sha: nextRelease.gitHead})
167-
.reply({})
168127
.post(`/repos/${owner}/${repo}/releases`, {
169128
tag_name: nextRelease.gitTag,
170129
target_commitish: options.branch,
@@ -202,10 +161,6 @@ test.serial('Publish a release with an array of missing assets', async t => {
202161
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
203162

204163
const github = authenticate()
205-
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
206-
.reply(404)
207-
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${nextRelease.gitTag}`, sha: nextRelease.gitHead})
208-
.reply({})
209164
.post(`/repos/${owner}/${repo}/releases`, {
210165
tag_name: nextRelease.gitTag,
211166
target_commitish: options.branch,
@@ -224,21 +179,3 @@ test.serial('Publish a release with an array of missing assets', async t => {
224179
t.deepEqual(t.context.error.args[1], ['The asset %s is not a file, and will be ignored.', emptyDirectory]);
225180
t.true(github.isDone());
226181
});
227-
228-
test.serial('Throw Error if get tag call return an error other than 404', async t => {
229-
const owner = 'test_user';
230-
const repo = 'test_repo';
231-
process.env.GITHUB_TOKEN = 'github_token';
232-
const pluginConfig = {};
233-
const nextRelease = {version: '1.0.0', gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
234-
const options = {branch: 'master', repositoryUrl: `https://github.com/${owner}/${repo}.git`};
235-
236-
const github = authenticate()
237-
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
238-
.reply(500);
239-
240-
const error = await t.throws(publish(pluginConfig, options, nextRelease, t.context.logger), Error);
241-
242-
t.is(error.code, 500);
243-
t.true(github.isDone());
244-
});

0 commit comments

Comments
 (0)