From 278510a90a9f26c7db806de3b885bae1119c8ac2 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 7 Jun 2021 03:40:39 -0400 Subject: [PATCH] Make a master tag of the extensions API (#2888) * Make a master tag of the extensions API Signed-off-by: Sebastian Malton * use the gitref as a prerelease header Signed-off-by: Sebastian Malton * Reduce the number of releases Signed-off-by: Sebastian Malton * Fix if Signed-off-by: Sebastian Malton --- .github/workflows/publish-master-npm.yml | 38 +++++++++++++++++++ ...ublish-npm.yml => publish-release-npm.yml} | 4 +- Makefile | 3 +- build/set_npm_version.ts | 18 +++++++-- 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/publish-master-npm.yml rename .github/workflows/{publish-npm.yml => publish-release-npm.yml} (90%) diff --git a/.github/workflows/publish-master-npm.yml b/.github/workflows/publish-master-npm.yml new file mode 100644 index 0000000000..e470289e9e --- /dev/null +++ b/.github/workflows/publish-master-npm.yml @@ -0,0 +1,38 @@ +name: Publish NPM Package `master` +on: + pull_request: + branches: + - master + types: + - closed +jobs: + publish: + name: Publish NPM Package `master` + runs-on: ubuntu-latest + if: | + ${{ github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'area/extension') }} + strategy: + matrix: + node-version: [12.x] + steps: + - name: Checkout Release + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Using Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Generate NPM package + run: | + make build-npm + + - name: publish new release + if: contains(github.ref, 'refs/tags/v') + run: | + make publish-npm + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + NPM_RELEASE_TAG: master diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-release-npm.yml similarity index 90% rename from .github/workflows/publish-npm.yml rename to .github/workflows/publish-release-npm.yml index 2502249ee3..5a8bd9aff5 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-release-npm.yml @@ -1,11 +1,11 @@ -name: Publish NPM +name: Publish NPM Package Release on: release: types: - published jobs: publish: - name: Publish NPM + name: Publish NPM Package Release runs-on: ubuntu-latest strategy: matrix: diff --git a/Makefile b/Makefile index fc764d0a94..3139b077b4 100644 --- a/Makefile +++ b/Makefile @@ -110,7 +110,8 @@ build-extension-types: node_modules src/extensions/npm/extensions/dist .PHONY: publish-npm 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 + 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..c0b24b54a6 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", `git.${gitRef.trim()}`); +} + +packageInfo.version = version.format(); + +fs.writeFileSync(path.join(__dirname, "../src/extensions/npm/extensions/package.json"), `${JSON.stringify(packageInfo, null, 2)}\n`);