Skip to content

Commit

Permalink
feat: do not create Git tag anymore
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The Git tag is not created anymore

The Git tag must be created by `semantic-release`. The plugin is compatible only with `semantic-release@13.0.0` or above.
  • Loading branch information
pvdlg committed Jan 27, 2018
1 parent a4273b6 commit 8847380
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 91 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ Each individual plugin can be disabled, replaced or used with other plugins in t
{
"release": {
"verifyConditions": ["@semantic-release/github", "@semantic-release/npm", "verify-other-condition"],
"getLastRelease": "@semantic-release/npm",
"publish": ["@semantic-release/npm", "@semantic-release/github", "other-publish"]
}
}
Expand Down
15 changes: 0 additions & 15 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ module.exports = async (pluginConfig, {branch, repositoryUrl}, {version, gitHead
debug('release name: %o', gitTag);
debug('release branch: %o', branch);

const ref = `refs/tags/${gitTag}`;

try {
// Test if the tag already exists
await github.gitdata.getReference({owner, repo, ref: `tags/${gitTag}`});
debug('The git tag %o already exists', gitTag);
} catch (err) {
// If the error is 404, the tag doesn't exist, otherwise it's an error
if (err.code !== 404) {
throw err;
}
debug('Create git tag %o with commit %o', gitTag, gitHead);
await github.gitdata.createReference({owner, repo, ref, sha: gitHead});
}

const {data: {html_url: htmlUrl, upload_url: uploadUrl}} = await github.repos.createRelease(release);
logger.log('Published GitHub release: %s', htmlUrl);

Expand Down
5 changes: 1 addition & 4 deletions lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ module.exports = async (pluginConfig, {repositoryUrl}, logger) => {

const {name: repo, owner} = parseGithubUrl(repositoryUrl);
if (!owner || !repo) {
throw new SemanticReleaseError(
`The git repository URL ${repositoryUrl} is not a valid GitHub URL.`,
'EINVALIDGITURL'
);
throw new SemanticReleaseError(`The git repository URL is not a valid GitHub URL.`, 'EINVALIDGITURL');
}

if (githubUrl) {
Expand Down
8 changes: 0 additions & 8 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ test.serial('Publish a release with an array of assets', async t => {
const github = authenticate()
.get(`/repos/${owner}/${repo}`)
.reply(200, {permissions: {push: true}})
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
.reply(404)
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${nextRelease.gitTag}`, sha: nextRelease.gitHead})
.reply({})
.post(`/repos/${owner}/${repo}/releases`, {
tag_name: nextRelease.gitTag,
target_commitish: options.branch,
Expand Down Expand Up @@ -185,10 +181,6 @@ test.serial('Verify GitHub auth and release', async t => {
const github = authenticate()
.get(`/repos/${owner}/${repo}`)
.reply(200, {permissions: {push: true}})
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
.reply(404)
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${nextRelease.gitTag}`, sha: nextRelease.gitHead})
.reply({})
.post(`/repos/${owner}/${repo}/releases`, {
tag_name: nextRelease.gitTag,
target_commitish: options.branch,
Expand Down
63 changes: 0 additions & 63 deletions test/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,6 @@ test.serial('Publish a release', async t => {
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;

const github = authenticate()
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
.reply(404)
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${nextRelease.gitTag}`, sha: nextRelease.gitHead})
.reply({})
.post(`/repos/${owner}/${repo}/releases`, {
tag_name: nextRelease.gitTag,
target_commitish: options.branch,
name: nextRelease.gitTag,
body: nextRelease.notes,
})
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl});

await publish(pluginConfig, options, nextRelease, t.context.logger);

t.deepEqual(t.context.log.args[0], ['Published GitHub release: %s', releaseUrl]);
t.true(github.isDone());
});

test.serial('Publish a release with an existing tag', async t => {
const owner = 'test_user';
const repo = 'test_repo';
process.env.GITHUB_TOKEN = 'github_token';
const pluginConfig = {};
const nextRelease = {version: '1.0.0', gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
const options = {branch: 'master', repositoryUrl: `https://github.com/${owner}/${repo}.git`};
const releaseUrl = `https://github.com/${owner}/${repo}/releases/${nextRelease.version}`;
const releaseId = 1;
const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`;
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;

const github = authenticate({})
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
.reply({ref: `refs/tags/${nextRelease.gitTag}`, object: {sha: 'e23a1bd8d7240c1eb3287374956042ffbcadca84'}})
.post(`/repos/${owner}/${repo}/releases`, {
tag_name: nextRelease.gitTag,
target_commitish: options.branch,
Expand Down Expand Up @@ -109,10 +76,6 @@ test.serial('Publish a release with one asset', async t => {
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;

const github = authenticate()
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
.reply(404)
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${nextRelease.gitTag}`, sha: nextRelease.gitHead})
.reply({})
.post(`/repos/${owner}/${repo}/releases`, {
tag_name: nextRelease.gitTag,
target_commitish: options.branch,
Expand Down Expand Up @@ -161,10 +124,6 @@ test.serial('Publish a release with one asset and custom github url', async t =>
githubUrl: process.env.GH_URL,
githubApiPathPrefix: process.env.GH_PREFIX,
})
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
.reply(404)
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${nextRelease.gitTag}`, sha: nextRelease.gitHead})
.reply({})
.post(`/repos/${owner}/${repo}/releases`, {
tag_name: nextRelease.gitTag,
target_commitish: options.branch,
Expand Down Expand Up @@ -202,10 +161,6 @@ test.serial('Publish a release with an array of missing assets', async t => {
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;

const github = authenticate()
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
.reply(404)
.post(`/repos/${owner}/${repo}/git/refs`, {ref: `refs/tags/${nextRelease.gitTag}`, sha: nextRelease.gitHead})
.reply({})
.post(`/repos/${owner}/${repo}/releases`, {
tag_name: nextRelease.gitTag,
target_commitish: options.branch,
Expand All @@ -224,21 +179,3 @@ test.serial('Publish a release with an array of missing assets', async t => {
t.deepEqual(t.context.error.args[1], ['The asset %s is not a file, and will be ignored.', emptyDirectory]);
t.true(github.isDone());
});

test.serial('Throw Error if get tag call return an error other than 404', async t => {
const owner = 'test_user';
const repo = 'test_repo';
process.env.GITHUB_TOKEN = 'github_token';
const pluginConfig = {};
const nextRelease = {version: '1.0.0', gitHead: '123', gitTag: 'v1.0.0', notes: 'Test release note body'};
const options = {branch: 'master', repositoryUrl: `https://github.com/${owner}/${repo}.git`};

const github = authenticate()
.get(`/repos/${owner}/${repo}/git/refs/tags/${nextRelease.gitTag}`)
.reply(500);

const error = await t.throws(publish(pluginConfig, options, nextRelease, t.context.logger), Error);

t.is(error.code, 500);
t.true(github.isDone());
});

0 comments on commit 8847380

Please sign in to comment.