-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1872 from Tyriar/cd
Setup continuous deployment beta builds
- Loading branch information
Showing
5 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ lib/test/ | |
docs/ | ||
/.idea/ | ||
.vscode/ | ||
bin/ | ||
build/ | ||
fixtures/ | ||
coverage/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) 2019 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
const cp = require('child_process'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const packageJson = require('../package.json'); | ||
|
||
// Setup auth | ||
fs.writeFileSync(`${process.env['HOME']}/.npmrc`, `//registry.npmjs.org/:_authToken=${process.env['NPM_AUTH_TOKEN']}`); | ||
|
||
// Get the version | ||
const tag = 'beta' | ||
const nextVersion = getNextVersion(tag); | ||
console.log(`Publishing version: ${nextVersion}`); | ||
|
||
// Set the version in package.json | ||
const packageJsonFile = path.resolve(__dirname, '..', 'package.json'); | ||
packageJson.version = nextVersion; | ||
fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson, null, 2)); | ||
|
||
// Publish | ||
const result = cp.spawn('npm', ['publish', '--tag', tag], { | ||
stdio: 'inherit' | ||
}); | ||
result.on('exit', code => process.exit(code)); | ||
|
||
function getNextVersion(tag) { | ||
if (!/^[0-9]+\.[0-9]+\.[0-9]+$/.exec(packageJson.version)) { | ||
console.error('The package.json version must be of the form x.y.z'); | ||
process.exit(1); | ||
} | ||
const stableVersion = packageJson.version.split('.'); | ||
const nextStableVersion = `${stableVersion[0]}.${parseInt(stableVersion[1]) + 1}.${stableVersion[2]}`; | ||
const publishedVersions = getPublishedVersions(nextStableVersion, tag); | ||
if (publishedVersions.length === 0) { | ||
return `${packageJson.version}-${tag}1`; | ||
} | ||
const latestPublishedVersion = publishedVersions.sort((a, b) => b.localeCompare(a))[0]; | ||
const latestTagVersion = parseInt(latestPublishedVersion.substr(latestPublishedVersion.search(/[0-9]+$/)), 10); | ||
return `${nextStableVersion}-${tag}${latestTagVersion + 1}`; | ||
} | ||
|
||
function getPublishedVersions(version, tag) { | ||
const versionsProcess = cp.spawnSync('npm', ['view', 'xterm', 'versions', '--json']); | ||
const versionsJson = JSON.parse(versionsProcess.stdout); | ||
return versionsJson.filter(v => !v.search(new RegExp(`${version}-${tag}[0-9]+`))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters