Skip to content

Commit

Permalink
Add is-pr command (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
job13er authored Jul 1, 2019
1 parent 09d97db commit 1f77c74
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ You can perform the automated bump in the merge build by using:
bumpr bump
```

If you have some other CI script you want to run only in a PR build, you can check by using

```
bumpr is-pr
```

This command will exit with a 0 exit code if the current build is a PR build, and a 1 if it is not. So you can have
a CI script like this:

```
bumpr is-pr && echo "Do PR stuff"
```

or

```
bumpr is-pr || echo "Do merge stuff"
```

If you have the `logging` feature enabled, you can output a specific key from the log file using:

```
Expand Down
11 changes: 11 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ program
withBumpr(bumpr => bumpr.bump())
})

program
.command('is-pr')
.description('check if current build is a PR build')
.action(() => {
// Use exit code 0 if the current build is a PR build, 1 if it is not
// this will allow CI scripts to do things like:
// $ bumpr is-pr && echo "A PR build"
// $ bumpr is-pr || echo "A merge build"
withBumpr(bumpr => process.exit(bumpr.isPr() ? 0 : 1))
})

program
.command('log <key>')
.description(`Output the given key from the ${name} log file`)
Expand Down
7 changes: 7 additions & 0 deletions src/bumpr.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ class Bumpr {
})
}

/**
* Check if a build is happening in a PR
*/
isPr() {
return this.config.computed.ci.isPr
}

/**
* Read the bumpr log and output the given key from it
* @returns {Promise} a promise resolved with the value or rejected on error
Expand Down
25 changes: 25 additions & 0 deletions src/tests/bumpr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,31 @@ describe('Bumpr', () => {
})
})

describe('.isPr()', () => {
let ret
describe('when not a PR build', () => {
beforeEach(() => {
set(bumpr.config, 'computed.ci.isPr', false)
ret = bumpr.isPr()
})

it('should return false', () => {
expect(ret).toEqual(false)
})
})

describe('when it is a PR build', () => {
beforeEach(() => {
set(bumpr.config, 'computed.ci.isPr', true)
ret = bumpr.isPr()
})

it('should return true', () => {
expect(ret).toEqual(true)
})
})
})

describe('.log()', () => {
beforeEach(() => {
set(bumpr.config, 'features.logging.file', 'the-log-file')
Expand Down

0 comments on commit 1f77c74

Please sign in to comment.