Skip to content

Commit

Permalink
chore: automate release with relase-it. fixes #275
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Oct 8, 2018
1 parent 0837f8c commit 53b5c0f
Show file tree
Hide file tree
Showing 5 changed files with 1,633 additions and 99 deletions.
14 changes: 14 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"non-interactive": true,
"increment": "conventional:angular",
"src": {
"commitMessage": "chore: release %s",
"tagName": "v%s"
},
"npm": {
"publish": true
},
"github": {
"release": true
}
}
16 changes: 14 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ Our pre-commit hooks verify that your commit message matches this format when co
We use `flow` for type checking, `eslint` with `prettier` for linting and formatting the code, and `jest` for testing. Our pre-commit hooks verify that the linter and tests pass when commiting. You can also run the following commands manually:

* `yarn flow`: run flow on all files.
* `yarn typescript`: run tests for typescript.
* `yarn lint`: run eslint and prettier.
* `yarn test`: run tests.
* `yarn test`: run unit tests.

### Sending a pull request

When you're sending a pull request:

* Prefer small pull requests focused on one change.
* Verify that `flow`, `eslint` and tests are passing.
* Verify that `flow`, `eslint` and all tests are passing.
* Preview the documentation to make sure it looks good.
* Follow the pull request template when opening a pull request.

Expand All @@ -52,6 +53,7 @@ When you're working on a component:
* Follow the guidelines described in the [official material design docs](https://material.io/guidelines/).
* Write a brief description of every prop when defining `type Props` to aid with documentation.
* Provide an example usage for the component (check other components to get a idea).
* Update the type definitions for Flow and Typescript if you changed an API or added a component.

### Running the example

Expand All @@ -63,6 +65,16 @@ After you're done, you can run `yarn start` or `expo start` in the `example/` fo

The documentation is automatically generated from the [flowtype](https://flowtype.org) annotations in the components. You can add comments above the type annotations to add descriptions. To preview the generated documentation, run `yarn start` in the `docs/` folder.

### Publishing a release

We use [release-it](https://github.com/webpro/release-it) to automate our release. If you have publish access to the NPM package, run the following from the master branch to publish a new release:

```sh
yarn release
```

NOTE: You must have a `GITHUB_TOKEN` environment variable available. You can create a GitHub access token with the "repo" access [here](https://github.com/settings/tokens).

## Reporting issues

You can report issues on our [bug tracker](https://github.com/callstack/react-native-paper/issues). Please follow the issue template when opening an issue.
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"lint": "eslint .",
"test": "jest",
"prepare": "node ./scripts/generate-mappings",
"bootstrap": "yarn && yarn --cwd example && yarn --cwd docs"
"bootstrap": "yarn && yarn --cwd example && yarn --cwd docs",
"release": "release-it"
},
"dependencies": {
"@callstack/react-theme-provider": "^1.0.5",
Expand All @@ -53,6 +54,8 @@
"babel-cli": "^6.26.0",
"babel-plugin-tester": "^5.0.0",
"babel-preset-react-native": "^4.0.0",
"chalk": "^2.4.1",
"dedent": "^0.7.0",
"eslint": "^4.19.1",
"eslint-config-callstack-io": "^1.1.1",
"eslint-plugin-prettier": "^2.6.0",
Expand All @@ -67,6 +70,7 @@
"react-native": "~0.55.4",
"react-native-vector-icons": "~4.6.0",
"react-test-renderer": "16.3.1",
"release-it": "^7.6.1",
"rimraf": "^2.6.2",
"typescript": "^3.0.3"
},
Expand Down
63 changes: 28 additions & 35 deletions scripts/validate-commit-message.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* @flow */

const fs = require('fs');
const util = require('util');
const dedent = require('dedent');
const chalk = require('chalk');

const MAX_LENGTH = 100;
const PATTERN = /^(?:fixup!\s*)?(\w*)(\(([\w$.*/-]*)\))?: (.*)$/;
const MAX_LENGTH = 72;
const MESSAGE_PATTERN = /^(?:fixup!\s*)?(\w*)(\(([\w$.*/-]*)\))?: (.*)$/;
const TYPES = [
'feat',
'fix',
Expand All @@ -18,46 +19,38 @@ const TYPES = [
'BREAKING',
];

function printError(...args) {
// eslint-disable-next-line no-console
console.error(`INVALID COMMIT MESSSAGE: ${util.format.apply(null, args)}`);
}
const commit = process.argv[2];

function validateMessage(message) {
if (message.length > MAX_LENGTH) {
printError('is longer than %d characters!', MAX_LENGTH);
return false;
}
try {
const message = fs.readFileSync(commit, 'utf8').split('\n')[0];

const match = PATTERN.exec(message);
let error;

if (!match) {
printError(`does not match "<type>: <subject>"! was: ${message}`);
return false;
}
const type = match[1];
if (message.length > MAX_LENGTH) {
error = `It should be less than ${chalk.blue(
String(MAX_LENGTH)
)} characters`;
} else {
const match = MESSAGE_PATTERN.exec(message);

if (!TYPES.includes(type)) {
printError('"%s" is not an allowed type!', type);
return false;
}
if (!match || !TYPES.includes(match[1])) {
error = dedent`
It should match the format '${chalk.blue('<type>: <subject>')}'
return true;
}
Where ${chalk.blue('<type>')} is one of:
${TYPES.map(t => `- ${t}`).join('\n')}
`;
}
}

function firstLineFromBuffer(buffer) {
return buffer
.toString()
.split('\n')
.shift();
}
if (error) {
// eslint-disable-next-line no-console
console.log(dedent`
${chalk.red('Invalid commit message:')} ${chalk.bold(message)}
const commitMsgFile = process.argv[2];
${error}
`);

try {
const buffer = fs.readFileSync(commitMsgFile);
const msg = firstLineFromBuffer(buffer);
if (!validateMessage(msg)) {
process.exit(1);
} else {
process.exit(0);
Expand Down
Loading

0 comments on commit 53b5c0f

Please sign in to comment.