From d917683dfdc2ab25d8c729f41fdcf5d8232a1d90 Mon Sep 17 00:00:00 2001 From: Thomas Schlage Date: Fri, 1 Sep 2017 11:08:40 +0200 Subject: [PATCH] feat(deployment): Added automatic version release process and editorconfig (#81) --- .editorconfig | 25 +++++++++++ CHANGELOG.md | 0 circle.yml | 15 ++++++- gulpfile.js | 113 +++++++++++++++++++++++++++++++++++++++++++------- package.json | 6 ++- 5 files changed, 141 insertions(+), 18 deletions(-) create mode 100644 .editorconfig create mode 100644 CHANGELOG.md diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..108839d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,25 @@ +; EditorConfig helps developers define and maintain consistent +; coding styles between different editors and IDEs. + +; For more visit http://editorconfig.org. +root = true + +; Choose between lf or rf on "end_of_line" property +[*] +indent_style = space +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{js,css,scss}] +indent_size = 2 + +[*.html] +indent_style = space + +[*.{py,html,md}] +indent_size = 2 + +[*.md] +trim_trailing_whitespace = true diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/circle.yml b/circle.yml index c84f446..d42525a 100644 --- a/circle.yml +++ b/circle.yml @@ -37,7 +37,20 @@ test: - gulp lint-sass deployment: - master: + release: + branch: master + commands: + - gulp bump-version changelog + - git add package.json doc dist + - git commit -m "Bumped version to $(jq -r .version package.json) [skip ci]" + - git tag -f -a $(jq -r .version package.json) -m "Automatic release via CircleCI" + - git push origin $CIRCLE_BRANCH + - gulp release --branch="${CIRCLE_BRANCH}" + - au build: + pwd: styleguide + - au publish --commit ${CIRCLE_SHA1} --repo "${CIRCLE_PROJECT_REPONAME}/${CIRCLE_BRANCH}" --target "${TARGET}": + pwd: styleguide + styleguide: branch: /.*/ commands: - au build: diff --git a/gulpfile.js b/gulpfile.js index bb5a77d..5af93a3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,22 +1,103 @@ -var gulp = require('gulp'); -var sass = require('gulp-sass'); -var gulpStylelint = require('gulp-stylelint'); +const gulp = require('gulp'); +const sass = require('gulp-sass'); +const gulpStylelint = require('gulp-stylelint'); +const runSequence = require('run-sequence'); +const conventionalChangelog = require('gulp-conventional-changelog'); +const conventionalGitHubReleaser = require('conventional-github-releaser'); +const bump = require('gulp-bump'); +const argv = require('yargs').argv; +const validBumpTypes = 'major|minor|patch|prerelease'.split('|'); +const bumpType = (argv.bump || 'patch').toLowerCase(); + +if (validBumpTypes.indexOf(bumpType) === -1) { + throw new Error('Unrecognized bump "' + bumpType + '".'); +} + +const args = { + bump: bumpType, + depth: parseInt(argv.depth || '0', 10), + token: argv.token, + branch: argv.branch +}; + +const changelogOpts = { + preset: 'angular', + releaseCount: 1, + targetCommitish: args.branch +}; + +// utilizes the bump plugin to bump the +// semver for the repo +gulp.task('bump-version', () => + gulp.src(['./package.json']) + .pipe(bump({type: args.bump})) + .pipe(gulp.dest('./')) +); + +// generates the CHANGELOG.md file based on commit +// from git commit messages +gulp.task('changelog', () => + gulp.src(`./CHANGELOG.md`) + .pipe(conventionalChangelog(changelogOpts)) + .pipe(gulp.dest('./')) +); + +// calls the listed sequence of tasks in order +gulp.task('prepare-release', callback => + runSequence( + 'build', + 'lint', + 'bump-version', + 'changelog', + callback + ) +); + +gulp.task('release', callback => { + conventionalGitHubReleaser({ + type: 'oauth', + token: args.token || process.env.CONVENTIONAL_GITHUB_RELEASER_TOKEN + }, changelogOpts, {}, {}, {}, {}, (err, data) => { + if (err) { + console.error(err.toString()); + return callback(); + } + + if (!data.length) { + console.log('No GitHub releases created because no git tags available to work with.'); + return callback(); + } + + let allRejected = true; + for (let i = data.length - 1; i >= 0; i--) { + if (data[i].state === 'fulfilled') { + allRejected = false; + break; + } + } + + if (allRejected) { + console.error(data); + } else { + console.log(data); + } + return callback(); + }); +}); gulp.task('lint-sass', function() { - return gulp.src(['./*.scss', './custom/*.scss', './components/*.scss', './components/**/*.scss']) - .pipe(gulpStylelint({ - reporters: [ - {formatter: 'string', console: true} - ] - })); + return gulp.src(['./*.scss', './custom/*.scss', './components/*.scss', './components/**/*.scss']) + .pipe(gulpStylelint({ + reporters: [ + {formatter: 'string', console: true} + ] + })); }); // This is only used to validate the code is able to compile -gulp.task('sass', function () { - return gulp.src('./index.scss') - .pipe(sass().on('error', sass.logError)); -}); +gulp.task('sass', () => + gulp.src('./index.scss') + .pipe(sass().on('error', sass.logError)) +); -gulp.task('default', function() { - return gulp.parallel('sass', 'lint-sass') -}); +gulp.task('default', () => gulp.parallel('sass', 'lint-sass')); diff --git a/package.json b/package.json index 94b36b5..5b2f7bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fabric-scss", - "version": "0.0.1", + "version": "1.0.0", "description": "", "homepage": "https://fabric-design.github.io/styleguide/#/general/1-intro", "main": "README.md", @@ -29,9 +29,13 @@ "registry": "npm" }, "devDependencies": { + "conventional-github-releaser": "^1.1.12", "gulp": "github:gulpjs/gulp#4.0", + "gulp-bump": "^2.7.0", + "gulp-conventional-changelog": "^1.1.4", "gulp-sass": "^2.3.1", "gulp-stylelint": "^3.9.0", + "run-sequence": "^2.1.0", "stylelint": "^7.9.0", "stylelint-config-sass-guidelines": "^2.0.0", "stylelint-scss": "^1.4.3"