Skip to content

Commit

Permalink
fix(release): set npm tags 'latest' and 'next' correctly after every …
Browse files Browse the repository at this point in the history
…release. Refactor nightly build

ISSUES CLOSED: #420, #468
  • Loading branch information
christophercr committed Mar 13, 2019
1 parent 03cd514 commit d6340e7
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"pkgFiles": ["package.json", "package-lock.json"],
"increment": "conventional:angular",
"scripts": {
"afterBump": "npm run generate:changelog",
"afterBump": "npm run check:nightly:stark-versions -- ${version} && npm run generate:changelog",
"afterRelease": false,
"beforeStage": false,
"beforeStart": "npm run check:starter:stark-versions",
Expand Down
11 changes: 9 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ IFS=${OLD_IFS} # restore IFS

BUILD_ALL=true
BUNDLE=true
VERSION_PREFIX=$(node -p "require('./package.json').version")
COMPILE_SOURCE=true
TYPECHECK_ALL=true

Expand Down Expand Up @@ -144,12 +143,20 @@ if [[ -z ${TRAVIS_TAG+x} ]]; then
TRAVIS_TAG=""
fi

if [[ ${TRAVIS_EVENT_TYPE} == "cron" ]]; then
logInfo "Nightly build initiated by Travis cron job. Using nightly version" 1
VERSION_PREFIX=$(node -p "require('./package.json').config.nightlyVersion")
else
logInfo "Normal build. Using current version" 1
VERSION_PREFIX=$(node -p "require('./package.json').version")
fi

if [[ ${TRAVIS_TAG} == "" ]]; then
logTrace "Setting the version suffix to the latest commit hash" 1
VERSION_SUFFIX="-$(git log --oneline -1 | awk '{print $1}')" # last commit id
else
logTrace "Build executed for a tag. Not using a version suffix!" 1
VERSION_SUFFIX="" # last commit id
VERSION_SUFFIX="" # no suffix
fi

VERSION="${VERSION_PREFIX}${VERSION_SUFFIX}"
Expand Down
27 changes: 27 additions & 0 deletions check-nightly-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const fs = require("fs");

let packageJsonPath = process.argv[2];
let latestVersion = process.argv[3];
let isCorrect = true;

fs.readFile(packageJsonPath, "utf8", function(err, packageJsonData) {
if (err) {
return console.error("Error while reading file => " + err);
}

const validVersionPattern = new RegExp('\\"nightlyVersion\\": \\"' + latestVersion + '\\"', "gi");
if (packageJsonData.match(validVersionPattern)) {
isCorrect = false;
console.error("Nightly version of Stark packages is not correct. It should be higher than latest version: '" + latestVersion + "'");
}

if (!isCorrect) {
throw new Error(
"The version set for nightly builds ('config.nightlyVersion') is not correct in " +
packageJsonPath +
". Please adapt to a valid version (higher than '" +
latestVersion +
"')."
);
}
});
14 changes: 10 additions & 4 deletions check-stark-versions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require("fs");

let packageJsonPath = process.argv[2];
let starkVersion = process.argv[3];
let validVersion = process.argv[3];
let isCorrect = true;

fs.readFile("./modules.txt", "utf8", function(err, modulesData) {
Expand All @@ -19,15 +19,21 @@ fs.readFile("./modules.txt", "utf8", function(err, modulesData) {
}

for (const starkPackage of starkPackagesArray) {
const validVersionPattern = new RegExp('\\"@nationalbankbelgium/' + starkPackage + '\\": \\"' + starkVersion + '\\"', "gi");
const validVersionPattern = new RegExp('\\"@nationalbankbelgium/' + starkPackage + '\\": \\"' + validVersion + '\\"', "gi");
if (!packageJsonData.match(validVersionPattern)) {
isCorrect = false;
console.error("Version of package " + starkPackage + " is not correct. It should be `" + starkVersion + "`");
console.error("Version of package " + starkPackage + " is not correct. It should be '" + validVersion + "'");
}
}

if (!isCorrect) {
throw new Error("The version of some of the Stark packages is not correct in the Starter. Please adapt to a valid version.");
throw new Error(
"The version of some of the Stark packages is not correct in " +
packageJsonPath +
". Please adapt to '" +
validVersion +
"'."
);
}
});
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"build:showcase:ghpages": "cd showcase && npm run build:prod:ghpages && cd ..",
"build:starter": "cd starter && npm run build && cd ..",
"check:starter:stark-versions": "node ./check-stark-versions.js ./starter/package.json latest",
"check:nightly:stark-versions": "node ./check-nightly-version.js ./package.json",
"clean": "npx rimraf ./dist",
"clean:all": "npm run clean && npm run clean:stark-build && npm run clean:stark-core && npm run clean:stark-ui && npm run clean:stark-testing && npm run clean:starter && npm run clean:showcase",
"clean:stark-build": "cd packages/stark-build && npm run clean && cd ../..",
Expand Down Expand Up @@ -170,7 +171,8 @@
"config": {
"commitizen": {
"path": "node_modules/cz-customizable"
}
},
"nightlyVersion": "10.0.0-beta.6"
},
"greenkeeper": {
"commitMessages": {
Expand Down
2 changes: 2 additions & 0 deletions release-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ do
if [[ ${NIGHTLY_BUILD} == false ]]; then
logTrace "Publishing the release (with tag latest)" 2
npm publish ${file} --access public
logTrace "Publishing the release also with tag next" 2
npm publish ${file} --access public --tag next
else
logTrace "Check if nightly build is not already published."
LATEST_NPM_VERSION=`npm view @nationalbankbelgium/${PACKAGE} dist-tags.next`
Expand Down

0 comments on commit d6340e7

Please sign in to comment.