Skip to content
This repository has been archived by the owner on Oct 10, 2018. It is now read-only.

Commit

Permalink
chore(semantic-release): custom script for now to get git head
Browse files Browse the repository at this point in the history
  • Loading branch information
buehler committed Jan 18, 2018
1 parent 4133b69 commit 4244226
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 19 deletions.
102 changes: 102 additions & 0 deletions etc/get-last-release.js
@@ -0,0 +1,102 @@
const fetch = require('node-fetch');
const semver = require('semver');
const getPkg = require('read-pkg-up');
const execa = require('execa');
const registry = 'vs code marketplace';

/**
* Get the commit sha for a given tag.
*
* @param {string} tagName Tag name for which to retrieve the commit sha.
*
* @return {string} The commit sha of the tag in parameter or `null`.
*/
async function gitTagHead(tagName, logger) {
try {
return await execa.stdout('git', ['rev-list', '-1', tagName]);
} catch (err) {
logger.error(err);
return null;
}
}

/**
* Unshallow the git repository (retriving every commits and tags).
*/
async function unshallow() {
await execa('git', ['fetch', '--unshallow', '--tags'], { reject: false });
}

async function getVersionHead(version, logger) {
let tagHead = (await gitTagHead(`v${version}`)) || (await gitTagHead(version));

// Check if tagHead is found
if (tagHead) {
logger.log('Use tagHead: %s', tagHead);
return tagHead;
}
await unshallow();

// Check if tagHead is found
tagHead = (await gitTagHead(`v${version}`)) || (await gitTagHead(version));
if (tagHead) {
logger.log('Use tagHead: %s', tagHead);
return tagHead;
}
}

/**
References:
* https://github.com/Microsoft/vscode/blob/master/src/vs/platform/extensionManagement/node/extensionGalleryService.ts#L423
* https://github.com/Microsoft/vscode/blob/b00945fc8c79f6db74b280ef53eba060ed9a1388/product.json#L17-L21
*/

module.exports = async (_pluginConfig, { logger }) => {
const { pkg: { name, publisher } } = await getPkg();
const extensionId = `${publisher}.${name}`;
logger.log(`Lookup extension details for "${extensionId}".`);
const body = JSON.stringify({
filters: [
{
pageNumber: 1,
pageSize: 1,
criteria: [
{ filterType: 7, value: extensionId }
]
}
],
'assetTypes': [],
'flags': 512
});

const res = await fetch('https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery', {
method: 'POST',
headers: {
'Accept': 'application/json;api-version=3.0-preview.1',
'Content-Type': 'application/json',
'Content-Length': body.length
},
body
});
const { results = [] } = await res.json();
const [{ extensions = [] } = {}] = results;

const [{ versions = [] }] = extensions.filter(({ extensionName, publisher: { publisherName } }) => {
return extensionId === `${publisherName}.${extensionName}`;
});
const [version] = versions
.map(({ version }) => version)
.sort(semver.compare)
.reverse();

if (!version) {
logger.log('No version found of package %s found on %s', extensionId, registry);
return {};
}

logger.log('Found version %s of package %s', version, extensionId);
return {
gitHead: await getVersionHead(version, logger),
version
};
};
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -68,7 +68,7 @@
"semantic-release-vsce",
"@semantic-release/github"
],
"getLastRelease": "semantic-release-visualstudio-marketplace-version",
"getLastRelease": "./etc/get-last-release",
"publish": [
{
"path": "semantic-release-vsce",
Expand All @@ -90,7 +90,6 @@
"filewalker": "^0.1.3",
"jest": "^22.1.2",
"semantic-release": "^12.2.2",
"semantic-release-visualstudio-marketplace-version": "^1.0.0",
"semantic-release-vsce": "^1.0.2",
"ts-jest": "^22.0.1",
"tslint": "^5.9.1",
Expand Down
18 changes: 1 addition & 17 deletions yarn.lock
Expand Up @@ -20,10 +20,6 @@
import-from "^2.1.0"
lodash "^4.17.4"

"@semantic-release/error@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@semantic-release/error/-/error-1.0.0.tgz#bb8f8eeedd5c7f8c46f96b37ef39e1b8c376c1cc"

"@semantic-release/error@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@semantic-release/error/-/error-2.1.0.tgz#44771f676f5b148da309111285a97901aa95a6e0"
Expand Down Expand Up @@ -3293,10 +3289,6 @@ lodash.escape@^3.0.0:
dependencies:
lodash._root "^3.0.0"

lodash.get@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"

lodash.isarguments@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a"
Expand Down Expand Up @@ -4375,7 +4367,7 @@ request@2.81.0:
tunnel-agent "^0.6.0"
uuid "^3.0.0"

request@^2.74.0, request@^2.79.0, request@^2.83.0:
request@^2.74.0, request@^2.83.0:
version "2.83.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.83.0.tgz#ca0b65da02ed62935887808e6f510381034e3356"
dependencies:
Expand Down Expand Up @@ -4520,14 +4512,6 @@ sax@^1.2.1:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"

semantic-release-visualstudio-marketplace-version@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/semantic-release-visualstudio-marketplace-version/-/semantic-release-visualstudio-marketplace-version-1.0.0.tgz#917ef82ba19ee6a860cf835273a8e0b78778bd2d"
dependencies:
"@semantic-release/error" "^1.0.0"
lodash.get "^4.4.2"
request "^2.79.0"

semantic-release-vsce@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/semantic-release-vsce/-/semantic-release-vsce-1.0.2.tgz#333fe5121f004dddd1d3eccc79ff0d84cc231175"
Expand Down

0 comments on commit 4244226

Please sign in to comment.