Skip to content

Commit bcbfc9c

Browse files
committed
ci: set up commit message conformance rules using ng-dev
1 parent b217494 commit bcbfc9c

File tree

10 files changed

+432
-34
lines changed

10 files changed

+432
-34
lines changed

.circleci/config.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ jobs:
168168
- custom_attach_workspace
169169
- run:
170170
name: Validate Commit Messages
171-
command: yarn -s admin validate-commits
171+
command: >
172+
if [[ -n "${CIRCLE_PR_NUMBER}" ]]; then
173+
yarn ng-dev commit-message validate-range --range <<pipeline.git.base_revision>>...<<pipeline.git.revision>>
174+
else
175+
echo "This build is not over a PR, nothing to do."
176+
fi
172177
- run:
173178
name: Validate "do not submit" Commits
174179
command: yarn -s admin validate-do-not-submit

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ tmp/
4040
npm-debug.log*
4141
yarn-error.log*
4242
.ng_pkg_build/
43+
.ng-dev.log
44+
.ng-dev.user*
4345

4446
# Mac OSX Finder files.
4547
**/.DS_Store

.ng-dev/commit-message.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// tslint:disable-next-line: no-implicit-dependencies
2+
import { COMMIT_TYPES, CommitMessageConfig, ScopeRequirement } from '@angular/dev-infra-private/commit-message/config';
3+
import { packages } from '../lib/packages';
4+
5+
/**
6+
* The details for valid commit types.
7+
* This is exported so that other tooling can access both the types and scopes from one location.
8+
* Currently used in the contributing documentation template (scripts/templates/contributing.ejs)
9+
*/
10+
export { COMMIT_TYPES, ScopeRequirement };
11+
12+
/**
13+
* The configuration for `ng-dev commit-message` commands.
14+
*/
15+
export const commitMessage: CommitMessageConfig = {
16+
maxLineLength: Infinity,
17+
minBodyLength: 0,
18+
minBodyLengthTypeExcludes: ['docs'],
19+
scopes: [
20+
...Object.keys(packages).filter(name => !packages[name].private),
21+
],
22+
};

.ng-dev/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { commitMessage } from './commit-message';
2+
export { github } from './github';

.ng-dev/github.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { GithubConfig } from '@angular/dev-infra-private/utils/config';
2+
3+
/**
4+
* Github configuration for the ng-dev command. This repository is
5+
* uses as remote for the merge script.
6+
*/
7+
export const github: GithubConfig = {
8+
owner: 'angular',
9+
name: 'angular-cli',
10+
};

CONTRIBUTING.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,15 @@ If the commit reverts a previous commit, it should begin with `revert: `, follow
192192
### Type
193193
Must be one of the following:
194194

195-
* **build**: Changes that affect the build system or external dependencies. [2]
196-
* **ci**: Changes to our CI configuration files and scripts. [2]
197-
* **docs**: Documentation only changes.
198-
* **feat**: A new feature. [1]
199-
* **fix**: A bug fix. [1]
200-
* **refactor**: A code change that neither fixes a bug nor adds a feature
201-
* **release**: A release commit. Must only include version changes. [2]
202-
* **revert**: A git commit revert. The description must include the original commit message. [2]
203-
* **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc).
204-
* **test**: Adding missing tests or correcting existing tests.
195+
* **build**: Changes to local repository build system and tooling
196+
* **ci**: Changes to CI configuration and CI specific tooling [2]
197+
* **docs**: Changes which exclusively affects documentation.
198+
* **feat**: Creates a new feature [1]
199+
* **fix**: Fixes a previously discovered failure/bug [1]
200+
* **perf**: Improves performance without any change in functionality or API [1]
201+
* **refactor**: Refactor without any change in functionality or API (includes style changes) [1]
202+
* **release**: A release point in the repository [2]
203+
* **test**: Improvements or corrections made to the project's test suite [1]
205204
206205
207206
<sup>[1] This type MUST have a scope. See the next section for more information.</sup><br/>

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"@angular/compiler": "11.0.0-next.4",
7272
"@angular/compiler-cli": "11.0.0-next.4",
7373
"@angular/core": "11.0.0-next.4",
74+
"@angular/dev-infra-private": "https://github.com/angular/dev-infra-private-builds.git#0364a68f33191747a0bb7580e44a9ad6d50add10",
7475
"@angular/forms": "11.0.0-next.4",
7576
"@angular/localize": "11.0.0-next.4",
7677
"@angular/material": "10.2.3",
@@ -238,6 +239,8 @@
238239
},
239240
"husky": {
240241
"hooks": {
242+
"commit-msg": "yarn -s ng-dev commit-message pre-commit-validate --file-env-variable HUSKY_GIT_PARAMS",
243+
"prepare-commit-msg": "yarn -s ng-dev commit-message restore-commit-message-draft --file-env-variable HUSKY_GIT_PARAMS",
241244
"pre-push": "node ./bin/devkit-admin hooks/pre-push"
242245
}
243246
}

scripts/templates/contributing.ejs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ If the commit reverts a previous commit, it should begin with `revert: `, follow
193193
Must be one of the following:
194194

195195
<%
196-
const { types, Scope } = require('../validate-commits');
197-
for (const typeName of Object.keys(types).sort()) {
198-
const type = types[typeName];
196+
const { COMMIT_TYPES, ScopeRequirement } = require('../../.ng-dev/commit-message');
197+
for (const typeName of Object.keys(COMMIT_TYPES).sort()) {
198+
const type = COMMIT_TYPES[typeName];
199199
%>* **<%= typeName %>**: <%= type.description %> <%
200-
if (type.scope == Scope.MustHave) {
200+
if (type.scope == ScopeRequirement.Required) {
201201
%>[1]<%
202-
} else if (type.scope == Scope.MustNotHave) {
202+
} else if (type.scope == ScopeRequirement.Forbidden) {
203203
%>[2]<%
204204
}
205205
%>
@@ -214,8 +214,9 @@ The scope should be the name of the npm package affected as perceived by the per
214214
The following is the list of supported scopes:
215215

216216
<%
217-
for (const packageName of Object.keys(packages).filter(x => !packages[x].private)) {
218-
%>* **<%= packageName %>**
217+
const { commitMessage } = require('../../.ng-dev/commit-message');
218+
for (const scope of commitMessage.scopes) {
219+
%>* **<%= scope %>**
219220
<% } %>
220221

221222
### Subject

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"tests/**/*",
6464
"tools/**/*",
6565
"benchmark/**/*",
66-
"integration/**/*"
66+
"integration/**/*",
67+
".ng-dev/**/*"
6768
]
6869
}

0 commit comments

Comments
 (0)