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. Fix nightly builds versioning

ISSUES CLOSED: #420, #468
  • Loading branch information
christophercr committed Mar 13, 2019
1 parent 03cd514 commit 7cca2ab
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 10 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
7 changes: 5 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ On Travis, the following should be configured:
First of all: _Never_ edit CHANGELOG.md manually!

The changelog will be updated automatically as part of the release process and based on the commit log using conventional-changelog (https://github.com/conventional-changelog)
We use the Angular format for our changelog and for it to work properly, please make sure to respect our commit conventions (see CONTRIBUTING guide).
We use the Angular format for our changelog and for it to work properly, please make sure to respect our commit conventions (see our [CONTRIBUTING](./CONTRIBUTING.md) guide).

## Creating a release

Expand All @@ -29,9 +29,12 @@ Make sure that:
- all changes have merged into master
- everything is up to date locally
- everything is clean locally
- the base version set for nightly builds (at `config.nightlyVersion` in the root `package.json`) is higher than the version to be released
- execute `npm run release`

Enjoy the show.
Enjoy the show!

_NOTE:_ If any of the pre-conditions mentioned above are not met, no worries, the npm command will fail with the proper description about what needs to be fixed.

## Publishing the release on npm

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 as version prefix!" 1
VERSION_PREFIX=$(node -p "require('./package.json').config.nightlyVersion")
else
logInfo "Normal build. Using current version as version prefix" 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 the 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 "Adapting the tag next to point to the new release" 2
npm dist-tag add @nationalbankbelgium/${PACKAGE}@${TRAVIS_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 7cca2ab

Please sign in to comment.