Skip to content

Commit a00f827

Browse files
jbogarthydealxhub
authored andcommitted
docs: document golden file requirement (angular#33900)
PR Close angular#33900
1 parent 4d7a9db commit a00f827

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ changes to be accepted, the CLA must be signed. It's a quick process, we promise
279279
280280
<hr>
281281
282-
283282
[angular-group]: https://groups.google.com/forum/#!forum/angular
284283
[coc]: https://github.com/angular/code-of-conduct/blob/master/CODE_OF_CONDUCT.md
285284
[commit-message-format]: https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#

docs/PR_REVIEW.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ cef93a51b (pr/24623_top) ci: scripts to review PRs locally
4141
637805a0c (pr/24623_base) docs: update `lowercase` pipe example in "AngularJS to Angular" guide (#24588)
4242
```
4343

44-
Knowing `pr/24623_top` and `pr/24623_base` makes it convenient to refer to different SHAs in PR when rebasing or reseting.
44+
Knowing `pr/24623_top` and `pr/24623_base` makes it convenient to refer to different SHAs in PR when rebasing or reseting.
4545

4646
### 2. Review PR
4747

@@ -131,7 +131,7 @@ cef93a51b (pr/24623_top) ci: scripts to review PRs locally
131131

132132
### 5. Pushing local edits back to the PR
133133

134-
The last step is to push your local changes back into the PR.
134+
The last step is to push your local changes back into the PR.
135135
Use `./scripts/github/push-pr` script for that.
136136

137137
```
@@ -151,5 +151,4 @@ To github.com:mhevery/angular.git
151151
NOTE: Notice that we did not have to specify the PR number since the script can guess it from the branch name.
152152

153153
If you visit https://github.com/angular/angular/pull/24623/commits you will see that your `fixup!` commit has been added to the PR.
154-
This greatly simplifies the work for many minor changes to the PR.
155-
154+
This greatly simplifies the work for many minor changes to the PR.

docs/PUBLIC_API.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,51 @@ We explicitly don't consider the following to be our public API surface:
4242
- the contents and API surface of the code generated by Angular's compiler (with one notable exception: the existence and name of `NgModuleFactory` instances exported from generated code is guaranteed)
4343

4444

45-
Our peer dependencies (e.g. TypeScript, Zone.js, or RxJS) are not considered part of our API surface, but they are included in our SemVer policies. We might update the required version of any of these dependencies in minor releases if the update doesn't cause breaking changes for Angular applications. Peer dependency updates that result in non-trivial breaking changes must be deferred to major Angular releases.
45+
Our peer dependencies (such as TypeScript, Zone.js, or RxJS) are not considered part of our API surface, but they are included in our SemVer policies. We might update the required version of any of these dependencies in minor releases if the update doesn't cause breaking changes for Angular applications. Peer dependency updates that result in non-trivial breaking changes must be deferred to major Angular releases.
46+
47+
<a name="golden-files"></a>
48+
49+
## Golden files
50+
51+
Angular tracks the status of the public API in a *golden file*, maintained with a tool called the *public API guard*. If you modify any part of a public API in one of the supported public packages, the PR can fail a Circle CI test with failures in `testlogs/tools/public_api_guard`, and an error message that instructs you to accept the golden file.
52+
53+
The public API guard provides a Bazel target that updates the current status of a given package. If you add to or modify the public API in any way, you must use [yarn](https://yarnpkg.com/) to execute the Bazel target in your terminal shell of choice (a recent version of `bash` is recommended).
54+
55+
```shell
56+
yarn bazel run //tools/public_api_guard:<modified_package>_api.accept
57+
```
58+
59+
Using yarn ensures that you are running the correct version of Bazel.
60+
(Read more about building Angular with Bazel [here](./BAZEL.md).)
61+
62+
Here is an example of a Circle CI test failure that resulted from adding a new allowed type to a public property in `forms.d.ts`. Error messages from the API guard use [`git-diff` formatting](https://git-scm.com/docs/git-diff#_combined_diff_format).
63+
64+
```
65+
FAIL: //tools/public_api_guard:forms_api (see /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular/bazel-out/k8-fastbuild/testlogs/tools/public_api_guard/forms_api/test_attempts/attempt_1.log)
66+
FAIL: //tools/public_api_guard:forms_api (see /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular/bazel-out/k8-fastbuild/testlogs/tools/public_api_guard/forms_api/test.log)
67+
68+
FAILED: //tools/public_api_guard:forms_api (Summary)
69+
/home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular/bazel-out/k8-fastbuild/testlogs/tools/public_api_guard/forms_api/test.log
70+
/home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular/bazel-out/k8-fastbuild/testlogs/tools/public_api_guard/forms_api/test_attempts/attempt_1.log
71+
INFO: From Testing //tools/public_api_guard:forms_api:
72+
==================== Test output for //tools/public_api_guard:forms_api:
73+
--- tools/public_api_guard/forms/forms.d.ts Golden file
74+
+++ tools/public_api_guard/forms/forms.d.ts Generated API
75+
@@ -4,9 +4,9 @@
76+
readonly disabled: boolean;
77+
readonly enabled: boolean;
78+
readonly errors: ValidationErrors | null;
79+
readonly invalid: boolean;
80+
- readonly parent: FormGroup | FormArray;
81+
+ readonly parent: FormGroup | FormArray | undefined;
82+
readonly pending: boolean;
83+
readonly pristine: boolean;
84+
readonly root: AbstractControl;
85+
readonly status: string;
86+
87+
If you modify a public API, you must accept the new golden file.
88+
89+
90+
To do so, execute the following Bazel target:
91+
yarn bazel run //tools/public_api_guard:forms_api.accept
92+
```

tools/ts-api-guardian/lib/cli.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,13 @@ export function startCli() {
8282
if (hasDiff) {
8383
// Under bazel, give instructions how to use bazel run to accept the golden file.
8484
if (!!process.env['BAZEL_TARGET']) {
85-
console.error('\n\nAccept the new golden file:');
86-
console.error(` bazel run ${process.env['BAZEL_TARGET'].replace(/_bin$/, "")}.accept`);
85+
console.error('\n\nIf you modify a public API, you must accept the new golden file.');
86+
console.error('\n\nTo do so, execute the following Bazel target:');
87+
console.error(
88+
` yarn bazel run ${process.env['BAZEL_TARGET'].replace(/_bin$/, "")}.accept`);
89+
console.error('\n\nFor more information, see');
90+
console.error(
91+
'\n https://github.com/angular/angular/blob/master/docs/PUBLIC_API.md#golden-files');
8792
}
8893
process.exit(1);
8994
}

0 commit comments

Comments
 (0)