diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index eb33cd8..3ef66d1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,5 +1,6 @@ name: Publish NPM on: + workflow_dispatch: release: types: [published] jobs: @@ -18,4 +19,11 @@ jobs: - name: Update npm run: npm install -g npm@latest - run: npm ci - - run: npm publish + - name: Publish release to NPM + if: github.event_name == 'release' + run: npm publish + - name: Publish @next to NPM + if: github.event_name == 'workflow_dispatch' + run: | + node utils/update_canary_version.js + # npm publish --tag=next diff --git a/utils/update_canary_version.js b/utils/update_canary_version.js new file mode 100755 index 0000000..94d3aa6 --- /dev/null +++ b/utils/update_canary_version.js @@ -0,0 +1,31 @@ +#!/usr/bin/env node +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +const timestamp = execSync('git show -s --format=%ct HEAD', { + stdio: ['ignore', 'pipe', 'ignore'] +}).toString('utf8').trim(); + +const packageJSON = require('../package.json'); +const newVersion = `${packageJSON.version}-alpha-${timestamp}000`; +console.log('Setting version to ' + newVersion); + +packageJSON.version = newVersion; +fs.writeFileSync(path.join(__dirname, '../package.json'), JSON.stringify(packageJSON, null, 2) + '\n');