From 848cd3ffdb6eee7e9e8294ce6206e6ae4e7a5360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Thu, 21 Apr 2022 00:02:46 +0200 Subject: [PATCH] fix: add release script --- .github/workflows/release.yaml | 30 ++++++++++++++++++++++++++++++ scripts/npm-tag.js | 18 ++++++++++++++++++ tsconfig.json | 3 ++- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yaml create mode 100644 scripts/npm-tag.js diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000000..c001aaf9bc --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,30 @@ +name: 'Publish to npm' +on: + push: + tags: + - 'v*' + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x] + + steps: + - uses: actions/checkout@v3 + - name: Publish to npm + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + registry-url: 'https://registry.npmjs.org' + - run: | + yarn install --frozen-lockfile + - run: | + LATEST=$(npm show unleash-server version) + TAG=$(node scripts/npm-tag.js $LATEST) + npm publish --tag ${TAG:-latest} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/scripts/npm-tag.js b/scripts/npm-tag.js new file mode 100644 index 0000000000..a3bf86dd9c --- /dev/null +++ b/scripts/npm-tag.js @@ -0,0 +1,18 @@ +const semver = require('semver'); + +const latestUnleashVersion = process.argv[2]; + +const version = require('../package.json').version; + +function isPrerelease(version) { + const arr = semver.prerelease(version); + return arr && arr.length > 0; +} + +if(isPrerelease(version)){ + console.log('beta') +}else if(semver.gt(version, latestUnleashVersion)) { + console.log('latest'); +} else { + console.log('previous'); +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 5a20ffaf59..433c29adee 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -76,6 +76,7 @@ "snapshots", "coverage", "website", - "setupJest.js" + "setupJest.js", + "scripts" ] }