Skip to content

Commit

Permalink
feat(build): added release and publish support. Closes NationalBankBe…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsebastien committed Apr 25, 2018
1 parent 75ff9c5 commit 108e077
Show file tree
Hide file tree
Showing 14 changed files with 432 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ dist/
dist/
.tmp/
/.tmp/
tmp/


# Reports directory
reports/
Expand Down
47 changes: 47 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"non-interactive": false,
"dry-run": false,
"verbose": false,
"force": false,
"pkgFiles": ["package.json"],
"increment": "patch",
"buildCommand": false,
"safeBump": true,
"beforeChangelogCommand": false,
"requireCleanWorkingDir": true,
"requireUpstream": true,
"src": {
"commit": true,
"commitMessage": "chore(release): release %s",
"commitArgs": "",
"tag": true,
"tagName": "%s",
"tagAnnotation": "%s",
"push": true,
"pushArgs": "",
"pushRepo": null,
"beforeStartCommand": false,
"afterReleaseCommand": false
},
"npm": {
"publish": false
},
"github": {
"release": true,
"releaseName": "Release %s",
"draft": false,
"tokenRef": "GITHUB_TOKEN",
"assets": null,
"host": null
},
"prompt": {
"src": {
"status": false,
"commit": true,
"tag": true,
"push": true,
"release": true,
"publish": true
}
}
}
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
language: node_js
node_js:
- "6"
- "8"
- "6"

dist: trusty
sudo: false # better for performance

before_install:
- export TZ=Europe/Brussels
# TODO remove this variable as it's probably not needed (defined by travis by default?): https://docs.travis-ci.com/user/environment-variables/
- TRAVIS=1 # used by build.sh
- npm i -g npm@5.8.0
# This ensures that we are authenticated without requiring to have an actual .npmrc file within the project
- 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'

install:
# Create file & folder for Travis logs
Expand Down Expand Up @@ -42,5 +46,8 @@ cache:
script:
- npm run lint:all
- npm run test:ci:all
- npm run release:publish
- bash ./scripts/ci/print-logs.sh

after_success:
- npm run test:ci:coveralls:stark-core
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<a name="10.0.0-alpha.1"></a>
# 10.0.0-alpha.1 (2018-03-29)


### Bug Fixes

* **build:** fixed issue with prettier config name with webpack plugin and added new scripts at root ([51be4f6](https://github.com/nationalbankbelgium/stark/commit/51be4f6))
* **http:** fix unit tests. Enhance http demo in Starter ([#268](https://github.com/nationalbankbelgium/stark/issues/268)) ([6d609b8](https://github.com/nationalbankbelgium/stark/commit/6d609b8)), closes [#68](https://github.com/nationalbankbelgium/stark/issues/68) [#68](https://github.com/nationalbankbelgium/stark/issues/68) [#84](https://github.com/nationalbankbelgium/stark/issues/84) [#93](https://github.com/nationalbankbelgium/stark/issues/93) [angular/zone.js#1015](https://github.com/angular/zone.js/issues/1015) [#96](https://github.com/nationalbankbelgium/stark/issues/96)
* **lazy-loading:** Remove PreloadAllModules preloading strategy from routing coneiguration to make lazy-loaded modules to be actually lazy loaded :) ([9634dac](https://github.com/nationalbankbelgium/stark/commit/9634dac))
* **lazy-loading:** Remove PreloadAllModules preloading strategy from routing coneiguration tz makz lazz-loaded modules to be actually lazy loaded :) ([80d09ce](https://github.com/nationalbankbelgium/stark/commit/80d09ce))
* **linting:** clean stark-build/tslint.json. Remove obsolete options for 'ban' rule ([86ed26c](https://github.com/nationalbankbelgium/stark/commit/86ed26c))
* **linting:** fix some TS linting issues ([8d5d6a8](https://github.com/nationalbankbelgium/stark/commit/8d5d6a8))


### Features

* **build:** added .gitattributes. Closes [#144](https://github.com/nationalbankbelgium/stark/issues/144). ([b4c3ef2](https://github.com/nationalbankbelgium/stark/commit/b4c3ef2))
* **build:** added support for building a subset of the packages ([55ec4c1](https://github.com/nationalbankbelgium/stark/commit/55ec4c1))
* **http:** create StarkHttp module. Fixed imports. Implemented small demo in Starter [[#96](https://github.com/nationalbankbelgium/stark/issues/96)] ([201edb8](https://github.com/nationalbankbelgium/stark/commit/201edb8))
* **http:** implement Stark Http in stark-core (unit tests to be completed) [[#96](https://github.com/nationalbankbelgium/stark/issues/96)] ([579c59b](https://github.com/nationalbankbelgium/stark/commit/579c59b))
* **http:** implement Stark Http in stark-core (unit tests to be completed) [[#96](https://github.com/nationalbankbelgium/stark/issues/96)] ([719d92d](https://github.com/nationalbankbelgium/stark/commit/719d92d))
* **polyfills:** Update polyfills.browser.ts with the relevant polyfills needed only for IE11 and some special features from Angular. Add needed npm dependencies for those polyfils ([2b6a160](https://github.com/nationalbankbelgium/stark/commit/2b6a160))
* **routing:** adapt CSP style-src directive to allow inline styles from UI Router visualizer ([8a1a8fa](https://github.com/nationalbankbelgium/stark/commit/8a1a8fa))
* **routing:** add UI Router visualizer. Adapt CSP img-src directive to allow png images from UI Router visualizer ([3bc995b](https://github.com/nationalbankbelgium/stark/commit/3bc995b))
* **routing:** replace Angular Router by UI Router ([24b70d4](https://github.com/nationalbankbelgium/stark/commit/24b70d4))
* **stark-testing:** create separate stark-testing package and use it in all stark packages and starter ([#267](https://github.com/nationalbankbelgium/stark/issues/267)) ([204dc35](https://github.com/nationalbankbelgium/stark/commit/204dc35)), closes [#68](https://github.com/nationalbankbelgium/stark/issues/68) [#68](https://github.com/nationalbankbelgium/stark/issues/68) [#84](https://github.com/nationalbankbelgium/stark/issues/84) [#93](https://github.com/nationalbankbelgium/stark/issues/93) [angular/zone.js#1015](https://github.com/angular/zone.js/issues/1015)



12 changes: 1 addition & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,7 @@ If you want to clean up completely the installed node_modules and reinstall late
* execute the `clean:modules:all` npm script to clean up every modules files in your project; for example: `npm run clean:modules:all`

## Releasing a version
* commit all changes to include in the release
* edit the version in package.json
* respect semver
* update CHANGELOG.MD
* commit
* git tag <version>
* git push --tags
* draft the release on GitHub (add description, etc)
* npm publish

TODO: review/complete; see #31
See [this page](/RELEASE.md)

## <a name="commit"></a> Commit Message Guidelines
We have precise rules over how our git commit messages can be formatted. This leads to **more readable messages** that are easy to follow when looking through the **project history**.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ TODO add links to developer guide sections
### Contributing
Please follow our [contribution guidelines](/CONTRIBUTING.md)

### Releasing Stark
See [this page](/RELEASE.md)

## Authors

### Sebastien Dubois
Expand Down
57 changes: 57 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Releasing Stark

## Pre-reqs
### Local
On your local machine, you must configure the `GITHUB_TOKEN` environment variable.
It will be used by release-it to push to and create the release page on GitHub (cfr release:prepare section below).

### Travis
On Travis, the following should be configured:
* NPM_TOKEN environment variable
* if 2FA is enabled for the account the only auth-only level can be used: https://docs.npmjs.com/getting-started/using-two-factor-authentication#levels-of-authentication
* that variable MUST NEVER be logged/exposed. If exposed then the token MUST be revoked and the account password changed ASAP

## Changelog
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).

## Creating a release
Make sure that:
* all changes have merged into master
* everything is up to date locally
* everything is clean locally
* execute `npm run release`

Enjoy the show.

## Publishing the release on npm
Once you have pushed the tag, Travis will handle things from there

## What happens once a release is triggered

### release
* first we make sure that there are no local changes (if there are we stop right there)
* then we execute release-it: https://github.com/webpro/release-it which
* bumps the version in the root package.json automatically (determines the bump type to use depending on the commit message logs)
* that version number will be used as basis in the build to adapt all other package.json files
* generates/updates the CHANGELOG.md file using: conventional-changelog: https://github.com/conventional-changelog
* commits both package.json and CHANGELOG.md
* creates a new git tag and pushes it
* creates a github release page and makes it final

After this, the release is tagged and visible on github

### publish
Once the tag is pushed to GitHub, Travis picks it up and initiates a build.
Travis executes builds, tests, then executes `npm run release:publish`.

That script makes some checks then, if all succeed it publishes the different packages on npm.
Checks that are performed:
* node version: should be "8"
* NPM_TOKEN environment variable should be defined
* TRAVIS_REPO_SLUG should be "NationalBankBelgium/stark"
* TRAVIS_TAG should be defined and not empty (this is the case when Travis builds for a tag)

Other details can be found here: https://github.com/NationalBankBelgium/stark/issues/54
48 changes: 0 additions & 48 deletions build-functions.sh
Original file line number Diff line number Diff line change
@@ -1,53 +1,5 @@
#!/usr/bin/env bash

# Three-Fingered Claw technique :)
# Reference: https://stackoverflow.com/questions/1378274/in-a-bash-script-how-can-i-exit-the-entire-script-if-a-certain-condition-occurs
yell() { echo "$0: $*" >&2; }
die() { yell "$*"; exit 111; }
try() { "$@" || die "cannot $*"; }

#######################################
# Echo the passed message if verbose mode is enabled
# Arguments:
# param1 - message to log if verbose mode is enabled
# param2 - depth: spaces to add before the string
#######################################
logDebug() {
if [[ ${VERBOSE} == true ]] || [[ ${TRACE} == true ]]; then
logInfo "$@"
fi
}

#######################################
# Echo the passed message if trace mode is enabled
# Arguments:
# param1 - message to log if trace mode is enabled
# param2 - depth: spaces to add before the string
#######################################
logTrace() {
if [[ ${TRACE} == true ]]; then
logInfo "$@"
fi
}

#######################################
# Echo the passed message
# Arguments:
# param1 - message to log if verbose mode is enabled
# param2 - (optional) depth: spaces to add before the string (defaults to 0)
#######################################
#log() {
# local message=${1:-NO MESSAGE TO LOG GIVEN TO log function (this is probably a mistake)}
# local numSpaces=${2:-0}
# printf "%${numSpaces}s$message\n"
#}
logInfo() {
local message="${1:-NO MESSAGE TO LOG GIVEN TO log function (this is probably a mistake)}"
local numSpaces="${2:-0}"
printf -v spacing '%*s' "$numSpaces"
printf "${spacing}%s\n" "$message"
}

#######################################
# Verifies a directory isn't in the ignored list
# Arguments:
Expand Down
39 changes: 26 additions & 13 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ readonly currentDir=$(cd $(dirname $0); pwd)
export NODE_PATH=${NODE_PATH:-}:${currentDir}/node_modules

source ${currentDir}/scripts/ci/_travis-fold.sh
source ${currentDir}/util-functions.sh
source ${currentDir}/build-functions.sh

cd ${currentDir}
Expand All @@ -27,12 +28,15 @@ TSC_PACKAGES=()
# Packages that should not be compiled at all
NODE_PACKAGES=(stark-build stark-testing)

ALL_PACKAGES=(stark-build stark-testing stark-core)
# We read from a file because the list is also shared with release-publish.sh
# Not using readarray because it does not handle \r\n
OLD_IFS=$IFS # save old IFS value
IFS=$'\r\n' GLOBIGNORE='*' command eval 'ALL_PACKAGES=($(cat ./modules.txt))'
IFS=$OLD_IFS # restore IFS

BUILD_ALL=true
BUNDLE=true
VERSION_PREFIX=$(node -p "require('./package.json').version")
VERSION_SUFFIX="-$(git log --oneline -1 | awk '{print $1}')" # last commit id
COMPILE_SOURCE=true
TYPECHECK_ALL=true

Expand All @@ -41,13 +45,6 @@ TRAVIS=${TRAVIS:-}
VERBOSE=false
TRACE=false

PROJECT_ROOT_DIR=`pwd`
logTrace "PROJECT_ROOT_DIR: ${PROJECT_ROOT_DIR}" 1
ROOT_DIR=${PROJECT_ROOT_DIR}/packages
logTrace "ROOT_DIR: ${ROOT_DIR}" 1
ROOT_OUT_DIR=${PROJECT_ROOT_DIR}/dist/packages
logTrace "ROOT_OUT_DIR: ${ROOT_OUT_DIR}" 1

for ARG in "$@"; do
case "$ARG" in
--quick-bundle=*)
Expand All @@ -60,7 +57,6 @@ for ARG in "$@"; do

# parse to identify the packages to build
PACKAGES_STR=${ARG#--packages=}
PACKAGES_STR=${ARG#--packages=}
PACKAGES_STR="${PACKAGES_STR//,/ }" # replace , by ' '
PACKAGES_STR="${PACKAGES_STR//;/ }" # replace ; by ' '
PACKAGES_STR="${PACKAGES_STR// /_}" # replace all spaces by '_'
Expand Down Expand Up @@ -113,9 +109,6 @@ for ARG in "$@"; do
--bundle=*)
BUNDLE=( "${ARG#--bundle=}" )
;;
--publish)
VERSION_SUFFIX=""
;;
--compile=*)
COMPILE_SOURCE=${ARG#--compile=}
;;
Expand All @@ -139,6 +132,26 @@ for ARG in "$@"; do
esac
done

PROJECT_ROOT_DIR=`pwd`
logTrace "PROJECT_ROOT_DIR: ${PROJECT_ROOT_DIR}" 1
ROOT_DIR=${PROJECT_ROOT_DIR}/packages
logTrace "ROOT_DIR: ${ROOT_DIR}" 1
ROOT_OUT_DIR=${PROJECT_ROOT_DIR}/dist/packages
logTrace "ROOT_OUT_DIR: ${ROOT_OUT_DIR}" 1

# Making sure the variable exists
if [[ -z ${TRAVIS_TAG+x} ]]; then
TRAVIS_TAG=""
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
fi

VERSION="${VERSION_PREFIX}${VERSION_SUFFIX}"

logInfo "============================================="
Expand Down
3 changes: 3 additions & 0 deletions modules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
stark-build
stark-testing
stark-core
Loading

0 comments on commit 108e077

Please sign in to comment.