|
1 | 1 | const exec = require('shell-utils').exec;
|
2 | 2 | const p = require('path');
|
3 | 3 |
|
| 4 | +// Export buildkite variables for Release build |
| 5 | +// We cast toString() because function returns 'object' |
| 6 | +const IS_SNAPSHOT = process.env.BUILDKITE_MESSAGE?.match(/^snapshot$/i); |
| 7 | +const VERSION_TAG = IS_SNAPSHOT ? 'snapshot' : 'latest'; |
| 8 | + |
4 | 9 | function run() {
|
5 | 10 | if (!validateEnv()) {
|
6 | 11 | return;
|
7 | 12 | }
|
8 | 13 |
|
| 14 | + const packageJsonVersion = require('../package.json').version; |
9 | 15 | const currentPublished = findCurrentPublishedVersion();
|
10 |
| - const packageJson = require('../package.json'); |
11 |
| - const newVersion = packageJson.version; |
| 16 | + const newVersion = IS_SNAPSHOT |
| 17 | + ? `${packageJsonVersion}-snapshot.${process.env.BUILDKITE_BUILD_NUMBER}` |
| 18 | + : packageJsonVersion; |
12 | 19 |
|
13 |
| - if (currentPublished !== newVersion) { |
| 20 | + if (currentPublished !== packageJsonVersion) { |
14 | 21 | createNpmRc();
|
15 | 22 | versionTagAndPublish(currentPublished, newVersion);
|
16 | 23 | }
|
@@ -49,8 +56,13 @@ function tryPublishAndTag(version) {
|
49 | 56 | }
|
50 | 57 |
|
51 | 58 | function tagAndPublish(newVersion) {
|
52 |
| - console.log(`Trying to publish ${newVersion}...`); |
53 |
| - exec.execSync(`npm publish`); |
| 59 | + console.log(`trying to publish ${newVersion}...`); |
| 60 | + exec.execSync(`npm --no-git-tag-version version ${newVersion}`); |
| 61 | + exec.execSync(`npm publish --tag ${VERSION_TAG}`); |
| 62 | + if (!IS_SNAPSHOT) { |
| 63 | + exec.execSync(`git tag -a ${newVersion} -m "${newVersion}"`); |
| 64 | + } |
| 65 | + exec.execSyncSilent(`git push deploy ${newVersion} || true`); |
54 | 66 | }
|
55 | 67 |
|
56 | 68 | run();
|
0 commit comments