Skip to content

Commit

Permalink
* feat(app): add skip-ci parameter (#71)
Browse files Browse the repository at this point in the history
Users can specify whether or not CI scripts should be run. Default is true - skip CI

BREAKING CHANGE:
Commit message for files `package.json` and `CHANGELOG` will contain text `[ci skip] ***NO_CI***'` so CI's can skip a build for this commit.

ISSUES CLOSED: issue #66 
PRs CLOSED: closes PR #67
  • Loading branch information
Franz Nieschalk authored and leonardoanalista committed Mar 19, 2019
1 parent 5ba2d66 commit 8293280
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules/
dist/
reports/
.idea/
.vscode/

# Logs
logs
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Of course you can change `corp-release` to any name you like.


## Options
* `--ci-skip [boolean]`: Skip Continuous Integration in CI environment. This adds `[ci skip] ***NO_CI***` to the commit message. Default is `true`.
* `-d` or `--dryrun`: it runs in non-destructive mode. No alteration should be done in your workspace.
* `--pre-commit [npm-script]`: Pre-commit hook. Pass the name of the npm script to run. It will run like this: `npm run [npm-script]`.
* `--post-success [command]`: Post-success hook (after `git push` completes successfully). Pass a command to run as the argument. Eg: `--post-success "npm publish"`.
Expand Down
17 changes: 15 additions & 2 deletions spec/system.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ describe('corp-semantic-release', function() {
expect(gitStatus).to.match(/nothing to commit, working (directory|tree) clean/);
});

it('should remove add no-ci message when ci-skip parameter is false', function() {
commitFeat();
const result = semanticRelease(`--ci-skip false`);
expect(result.code).to.be.equal(0);

const expectedVersion = '1.0.0';

// check Semantic Tag
expectedGitTag(expectedVersion, undefined, false);
});

it('should bump minor version, create CHANGELOG.md file and semantic tag correctly', function() {
commitFeat();
Expand Down Expand Up @@ -470,11 +480,14 @@ describe('corp-semantic-release', function() {
const today = new Date().toISOString().substring(0, 10);


function expectedGitTag(expectedVersion, expectedPrefix) {
function expectedGitTag(expectedVersion, expectedPrefix, ciSkip) {
expectedPrefix = expectedPrefix || '';
ciSkip = ciSkip !== false;

// check for new commit
const gitLog = shell.exec('git log | cat').stdout;
expect(gitLog).to.include(`chore(release): ${expectedPrefix}v${expectedVersion} [ci skip] ***NO_CI***`);
expect(gitLog).to.include(`chore(release): ${expectedPrefix}v${expectedVersion}`
+ (ciSkip ? ' [ci skip] ***NO_CI***' : ''));

const gitTag = shell.exec('git tag | cat').stdout;
expect(gitTag).to.include(expectedPrefix + 'v' + expectedVersion);
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ if (!pkg.name || !oldVersion) {

program
.version(oldVersion)
.option('--ci-skip [boolean]', 'Skip Continuous Integration in CI environment. This adds "[ci skip] ***NO_CI***" to the commit message. Default is true.')
.option('-d, --dryrun', 'No changes to workspace. Stops after changelog is printed.')
.option('--pre-commit [npm-script]', 'Pre-commit hook. Pass the name of the npm script to run. It will run like this: npm run [pre-commit]')
.option('--post-success [command]', 'Post-success hook (after git push completes successfully). Pass a command to run as the argument. Eg: --post-success "npm publish"')
Expand All @@ -45,6 +46,7 @@ if (program.dryrun) {
log.announce('>> YOU ARE RUNNING IN DRY RUN MODE. NO CHANGES WILL BE MADE <<');
}

program.ciSkip = program.ciSkip !== 'false';
program.branch = program.branch || 'master';
program.changelogpreset = program.changelogpreset || 'angular';
// Release count defaults to 1 (generate 1 release), but could be 0 (hence logic). See https://github.com/conventional-changelog/conventional-changelog-core#releasecount
Expand Down Expand Up @@ -133,7 +135,7 @@ function(err, results) {

// ### STEP 9 - Tag and push (DESTRUCTIVE OPERATION)
if (!program.dryrun) {
lib.addFilesAndCreateTag(version, program.mockPush);
lib.addFilesAndCreateTag(version, program.mockPush, program.ciSkip);
} else {
log.info('>>> Skipping git push');
}
Expand Down
6 changes: 4 additions & 2 deletions src/lib/addFilesAndCreateTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ const terminateProcess = require('./helpers').terminateProcess;
const shell = require('shelljs');
const log = require('./log');

module.exports = function addFilesAndCreateTag(newVersion, mockPush) {
module.exports = function addFilesAndCreateTag(newVersion, mockPush, ciSkip) {
let code;
// ###### Add edited files to git #####
log.info('>>> About to add and commit package.json and CHANGELOG...');
code = shell.exec('git add package.json CHANGELOG.md').code;
terminateProcess(code);

// ###### Commit files #####
code = shell.exec('git commit -m "chore(release): ' + newVersion + ' [ci skip] ***NO_CI***"').code;
const commitMessage = 'git commit -m "chore(release): ' + newVersion
+ (ciSkip ? ' [ci skip] ***NO_CI***' : '') + '"';
code = shell.exec(commitMessage).code;
terminateProcess(code);

// ###### TAG NEW VERSION #####
Expand Down

0 comments on commit 8293280

Please sign in to comment.