Skip to content

Commit

Permalink
Deploy dist files and bower.json (tags)
Browse files Browse the repository at this point in the history
Add a new Travis deploy task to push dist/*.js and bower.json files into tag sources:
- requires Travis GITHUB_AUTH_TOKEN and GITHUB_AUTH_EMAIL environment variables
- skipped if not built from the "release" branch
- release.sh must be executable (see comment)
- reads tag version from package.json
- fails if tag already exists
  • Loading branch information
simonbrunel committed Oct 23, 2016
1 parent a12a737 commit 24b4db9
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/dist
/node_modules
.DS_Store
bower.json
/.vscode
16 changes: 13 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ script:
- gulp lint
- gulp build
- gulp package
- gulp bower

deploy:
provider: releases
api_key:
secure: ejOLLIcHVw+MEUFVoCeQIHD4CuHSMeG7CJ1PGH74BPSzK2t5crBkCchhO9G4lRjrra3fI7O/8iz9EQknLLXEqWah5oi/jy2hpsD+7etfxyL0KBw9JBpbBM/Klc3M200KaWUvcSZIO4rsuObAPQV0OWkVFvZiA3EIVEerkXR3ms1JHueD9qXWuRniiNoalSedfVrOmlj6yqA+D2tdLDcj4AcLOO86oGNVcc5zeTFXljtuxpwedcQS4kcarwQC4arROQx7XNdPgiO7egGZej31/DoTB4PYV70M0UtDztvj1JYz53thgElX6w6c6lF41HHAMoGhP6Rpiw0TiF9a37GCivzD7aKUSek+ekP+DxV6HdOgaLlsBk8Ryw9p3GQ9p/shYjCRxjSRduQoxgSYnf10yS8j9m3moDvuY4//uchu9pvMTeTIXkRx1z913isyIaa8GM9SHxiIPYBOKIltLcq3g2/s0WUsyBC8bSY1I8DRLmZn2HOEgJBkI3kWmO8zL1Y3ZtRAg/pAN84h2DeM52toFC0Pw8MZ0YedVOWa3k1HpQddi7x4pvvG4c9S/BHwGOnr3O2O3ahL24pNB4QNrqvp770fd9GDgjmXbHpsw8FNOSYCd9eoi7FWSWgc6CkQI8VuYThXV8D7K+70WxZfbBLQBSM8M6sSres661k39RwoKro=
# Creates a tag containing dist files and bower.json
# Requires GITHUB_AUTH_TOKEN and GITHUB_AUTH_EMAIL environment variables
# IMPORTANT: the script has to be set executable in the Git repository (error 127)
# https://github.com/travis-ci/travis-ci/issues/5538#issuecomment-225025939
# http://stackoverflow.com/a/15572639
- provider: script
script: ./scripts/release.sh
skip_cleanup: true
on:
branch: release
- provider: releases
api_key: $GITHUB_AUTH_TOKEN
file:
- "./dist/Chart.Deferred.js"
- "./dist/Chart.Deferred.min.js"
Expand Down
16 changes: 16 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var argv = require('yargs').argv
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var insert = require('gulp-insert');
var file = require('gulp-file');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var streamify = require('gulp-streamify');
Expand Down Expand Up @@ -29,6 +30,7 @@ var header = "/*!\n\
gulp.task('build', buildTask);
gulp.task('lint', lintTask);
gulp.task('package', packageTask);
gulp.task('bower', bowerTask);
gulp.task('default', ['build']);

function watch(glob, task) {
Expand Down Expand Up @@ -86,3 +88,17 @@ function packageTask() {
.pipe(zip('Chart.Deferred.js.zip'))
.pipe(gulp.dest(outDir));
}

function bowerTask() {
var json = JSON.stringify({
name: package.name,
description: package.description,
homepage: package.homepage,
license: package.license,
version: package.version,
main: outDir + "Chart.Deferred.js"
}, null, 2);

return file('bower.json', json, { src: true })
.pipe(gulp.dest('./'));
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-eslint": "^2.0.0",
"gulp-eslint": "^2.1.0",
"gulp-insert": "^0.5.0",
"gulp-file": "^0.3.0",
"gulp-replace": "^0.5.4",
"gulp-rename": "^1.2.2",
"gulp-streamify": "^1.0.2",
Expand Down
29 changes: 29 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -e

if [ "$TRAVIS_BRANCH" != "release" ]; then
echo "Skipping release because this is not the 'release' branch"
exit 0
fi

# Travis executes this script from the repository root, so at the same level than package.json
VERSION=$(node -p -e "require('./package.json').version")

# Make sure that the associated tag doesn't already exist
GITTAG=$(git ls-remote origin refs/tags/v$VERSION)
if [ "$GITTAG" != "" ]; then
echo "Tag for package.json version already exists, aborting release"
exit 1
fi

git remote add auth-origin https://$GITHUB_AUTH_TOKEN@github.com/$TRAVIS_REPO_SLUG.git
git config --global user.email "$GITHUB_AUTH_EMAIL"
git config --global user.name "Chart.js"
git checkout --detach --quiet
git add -f dist/*.js bower.json
git commit -m "Release $VERSION"
git tag -a "v$VERSION" -m "Version $VERSION"
git push -q auth-origin refs/tags/v$VERSION 2>/dev/null
git remote rm auth-origin
git checkout -f @{-1}

0 comments on commit 24b4db9

Please sign in to comment.