From 8847380b9267eddbf8f4e00d450b688ff2ecbd0b Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 23 Jan 2018 02:23:14 -0500 Subject: [PATCH] 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 `semantic-release@13.0.0` or above. --- README.md | 1 - lib/publish.js | 15 ---------- lib/verify.js | 5 +--- test/integration.test.js | 8 ----- test/publish.test.js | 63 ---------------------------------------- 5 files changed, 1 insertion(+), 91 deletions(-) diff --git a/README.md b/README.md index ab139fd0..2dfe33a6 100644 --- a/README.md +++ b/README.md @@ -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"] } } diff --git a/lib/publish.js b/lib/publish.js index 26da0600..e9f9cbbe 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -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); diff --git a/lib/verify.js b/lib/verify.js index a9cf6e2e..8a836ac4 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -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) { diff --git a/test/integration.test.js b/test/integration.test.js index 118693bf..59dc2682 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -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, @@ -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, diff --git a/test/publish.test.js b/test/publish.test.js index 68aca938..a51bc7c0 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -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, @@ -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, @@ -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, @@ -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, @@ -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()); -});