From 038117ff26d27c68cbba9631c913a26bba6ae8fe Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 28 May 2021 15:32:14 -0400 Subject: [PATCH] use the gitref as a prerelease header Signed-off-by: Sebastian Malton --- Makefile | 1 + build/set_npm_version.ts | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 42704ec933..3139b077b4 100644 --- a/Makefile +++ b/Makefile @@ -111,6 +111,7 @@ build-extension-types: node_modules src/extensions/npm/extensions/dist publish-npm: node_modules build-npm ./node_modules/.bin/npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}" cd src/extensions/npm/extensions && npm publish --access=public --tag=${NPM_RELEASE_TAG:-latest} + git restore src/extensions/npm/extensions/package.json .PHONY: docs docs: diff --git a/build/set_npm_version.ts b/build/set_npm_version.ts index b7614103a2..696503a6bc 100644 --- a/build/set_npm_version.ts +++ b/build/set_npm_version.ts @@ -22,8 +22,20 @@ import * as fs from "fs"; import * as path from "path"; import packageInfo from "../src/extensions/npm/extensions/package.json"; import appInfo from "../package.json"; +import { SemVer } from "semver"; +import { execSync } from "child_process"; -const packagePath = path.join(__dirname, "../src/extensions/npm/extensions/package.json"); +const { NPM_RELEASE_TAG = "latest" } = process.env; +const version = new SemVer(appInfo.version); -packageInfo.version = appInfo.version; -fs.writeFileSync(packagePath, `${JSON.stringify(packageInfo, null, 2)}\n`); +if (NPM_RELEASE_TAG !== "latest") { + const gitRef = execSync("git rev-parse --short HEAD", { + encoding: "utf-8", + }); + + version.inc("prerelease", gitRef.trim()); +} + +packageInfo.version = version.format(); + +fs.writeFileSync(path.join(__dirname, "../src/extensions/npm/extensions/package.json"), `${JSON.stringify(packageInfo, null, 2)}\n`);