forked from hyperledger-archives/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial scripts to deal with problems
- Loading branch information
Simon Stone
committed
Jan 24, 2017
1 parent
c96972c
commit a804bcb
Showing
6 changed files
with
235 additions
and
39 deletions.
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
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 |
---|---|---|
|
@@ -25,14 +25,31 @@ if [[ "${TRAVIS_REPO_SLUG}" != Blockchain-WW-Labs* ]]; then | |
exit 0 | ||
fi | ||
|
||
# Determine the repository wide version. | ||
export VERSION=$(node -e "console.log(require('$DIR/package.json').version)") | ||
|
||
# If this is not for a tagged (release) build, set the prerelease version. | ||
# Push the code to npm. | ||
if [ -z "${TRAVIS_TAG}" ]; then | ||
export TIMESTAMP=$(date +%Y%m%d%H%M%S) | ||
export VERSION="${VERSION}-${TIMESTAMP}" | ||
lerna publish --skip-git --npm-tag unstable --force-publish --yes --repo-version "${VERSION}" 2>&1 | tee | ||
|
||
# Set the prerelease version. | ||
npm run pkgstamp | ||
|
||
# Publish with unstable tag. These are development builds. | ||
echo "Pushing with tag unstable" | ||
lerna exec --ignore '@ibm/concerto-systests' -- npm publish --scope=@ibm --tag=unstable 2>&1 | tee | ||
|
||
else | ||
lerna publish --skip-git --force-publish --yes --repo-version "${VERSION}" 2>&1 | tee | ||
|
||
# Publish with latest tag (default). These are release builds. | ||
echo "Pushing with tag latest" | ||
lerna exec --ignore '@ibm/concerto-systests' -- npm publish --scope=@ibm 2>&1 | tee | ||
|
||
# Bump the version number. | ||
npm run pkgbump | ||
|
||
# Push the changes back into GitHub. | ||
git config user.name "Travis CI" | ||
git config user.email "[email protected]" | ||
git checkout develop | ||
git add . | ||
git commit -m "Automated version bump" | ||
git push | ||
|
||
fi |
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,119 @@ | ||
#!/usr/bin/env node | ||
/* | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const child_process = require('child_process'); | ||
const colors = require('colors'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const semver = require('semver') | ||
|
||
const packages = {}; | ||
const fix = (process.argv.indexOf('--fix') !== -1); | ||
|
||
const lernaDirectory = path.resolve('.'); | ||
const lernaConfigFile = path.resolve(lernaDirectory, 'lerna.json'); | ||
const lernaConfig = require(lernaConfigFile); | ||
const targetVersion = lernaConfig.version; | ||
const targetDependency = `^${targetVersion}`; | ||
packages['lerna.json'] = lernaConfig; | ||
|
||
if (!semver.valid(targetVersion)) { | ||
console.error(`Error: the version "${targetVersion}" in "${lernaConfigFile}" is invalid!`); | ||
process.exit(1); | ||
} | ||
|
||
const masterPackageFile = path.resolve(lernaDirectory, 'package.json'); | ||
const masterPackage = require(masterPackageFile); | ||
packages['package.json'] = masterPackage; | ||
|
||
const packagesDirectory = path.resolve(lernaDirectory, 'packages'); | ||
const packageNames = fs.readdirSync(packagesDirectory); | ||
packageNames.forEach((packageName) => { | ||
const packageFile = path.resolve(packagesDirectory, packageName, 'package.json'); | ||
const thisPackage = require(packageFile); | ||
packages[packageName] = thisPackage; | ||
}); | ||
|
||
let mismatch = false; | ||
const badDependencies = {}; | ||
for (const i in packages) { | ||
const currentPackage = packages[i]; | ||
if (targetVersion !== currentPackage.version) { | ||
mismatch = true; | ||
break; | ||
} | ||
} | ||
|
||
for (const i in packages) { | ||
const currentPackage = packages[i]; | ||
for (const j in packages) { | ||
const otherPackage = packages[j]; | ||
for (const dependency in currentPackage.dependencies) { | ||
const currentValue = currentPackage.dependencies[dependency]; | ||
if (dependency === otherPackage.name) { | ||
if (currentValue !== targetDependency) { | ||
if (!badDependencies[i]) { | ||
badDependencies[i] = []; | ||
} | ||
badDependencies[i].push({ dependency: dependency, currentValue: currentValue }); | ||
mismatch = true; | ||
} | ||
} | ||
} | ||
for (const dependency in currentPackage.devDependencies) { | ||
const currentValue = currentPackage.devDependencies[dependency]; | ||
if (dependency === otherPackage.name) { | ||
if (currentValue !== targetDependency) { | ||
if (!badDependencies[i]) { | ||
badDependencies[i] = []; | ||
} | ||
badDependencies[i].push({ dependency: dependency, currentValue: currentValue }); | ||
mismatch = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (mismatch && !fix) { | ||
console.error('Error: there is a mismatch between the versions of the packages in this repository!\n'); | ||
for (const i in packages) { | ||
const currentPackage = packages[i]; | ||
if (targetVersion !== currentPackage.version) { | ||
console.error(` ${i} ${currentPackage.version.red} (should be ${targetVersion})`); | ||
} else { | ||
console.error(` ${i} ${currentPackage.version.green}`); | ||
} | ||
if (badDependencies[i]) { | ||
badDependencies[i].forEach((badDependency) => { | ||
console.error(` ${badDependency.dependency}@${badDependency.currentValue.red} (should be ${targetDependency})`); | ||
}); | ||
} | ||
} | ||
console.error('\n'); | ||
console.error(`Run "scripts/pkgcheck.js --fix" inside the directory "${lernaDirectory}" to resolve this problem and change the version to "${targetVersion}"`); | ||
process.exit(1); | ||
} else if (mismatch && fix) { | ||
const command = `lerna publish --skip-git --skip-npm --yes --repo-version ${targetVersion}`; | ||
console.warn(`Status: running command ${command} to fix problems ...`) | ||
child_process.execSync(command); | ||
console.warn(`Status: modifying "${masterPackageFile} to fix problems ...`); | ||
masterPackage.version = targetVersion; | ||
fs.writeFileSync(masterPackageFile, JSON.stringify(masterPackage, null, 4), 'utf8'); | ||
} else { | ||
console.log('Status: no problems detected!'); | ||
} |
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,66 @@ | ||
#!/usr/bin/env node | ||
/* | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const moment = require('moment'); | ||
const path = require('path'); | ||
|
||
const timestamp = moment().format('YYYYMMDDHHmmss'); | ||
|
||
const lernaDirectory = path.resolve('.'); | ||
const lernaConfigFile = path.resolve(lernaDirectory, 'lerna.json'); | ||
const lernaConfig = require(lernaConfigFile); | ||
lernaConfig.version.replace(/-.*/, ''); | ||
const targetVersion = lernaConfig.version + '-' + timestamp; | ||
lernaConfig.version = targetVersion; | ||
fs.writeFileSync(lernaConfigFile, JSON.stringify(lernaConfig, null, 4), 'utf8'); | ||
|
||
const masterPackageFile = path.resolve(lernaDirectory, 'package.json'); | ||
const masterPackage = require(masterPackageFile); | ||
masterPackage.version = targetVersion; | ||
fs.writeFileSync(masterPackageFile, JSON.stringify(masterPackage, null, 4), 'utf8'); | ||
|
||
const packagesDirectory = path.resolve(lernaDirectory, 'packages'); | ||
const packageNames = fs.readdirSync(packagesDirectory); | ||
const packages = {}; | ||
packageNames.forEach((packageName) => { | ||
const packageFile = path.resolve(packagesDirectory, packageName, 'package.json'); | ||
const thisPackage = require(packageFile); | ||
thisPackage.version = targetVersion; | ||
packages[packageName] = thisPackage; | ||
}); | ||
|
||
for (const i in packages) { | ||
const currentPackage = packages[i]; | ||
for (const j in packages) { | ||
const otherPackage = packages[j]; | ||
for (const dependency in currentPackage.dependencies) { | ||
const currentValue = currentPackage.dependencies[dependency]; | ||
if (dependency === otherPackage.name) { | ||
currentPackage.dependencies[dependency] = targetVersion; | ||
} | ||
} | ||
for (const dependency in currentPackage.devDependencies) { | ||
const currentValue = currentPackage.devDependencies[dependency]; | ||
if (dependency === otherPackage.name) { | ||
currentPackage.devDependencies[dependency] = targetVersion; | ||
} | ||
} | ||
} | ||
const packageFile = path.resolve(packagesDirectory, i, 'package.json'); | ||
fs.writeFileSync(packageFile, JSON.stringify(currentPackage, null, 4), 'utf8'); | ||
} |