diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000000..c001aaf9bcf --- /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 00000000000..a3bf86dd9ca --- /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 5a20ffaf592..433c29adeea 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -76,6 +76,7 @@ "snapshots", "coverage", "website", - "setupJest.js" + "setupJest.js", + "scripts" ] }