Skip to content

Commit d1e6357

Browse files
feat: mdTypes from core export (#1398)
* chore: commit existing registry * ci: new registry update scripts * fix: script self-qa * chore: rename * feat: registry updates * chore: bump deps for pdr xnuts * chore: update METADATA_SUPPORT.md * chore: removal internal links * chore: fixes from QA * fix: explain what the json output is * fix: pr feedback (case insensitivity) --------- Co-authored-by: Willie Ruemmele <[email protected]>
1 parent 83228e8 commit d1e6357

15 files changed

+6321
-2592
lines changed

CHANGELOG.md

Lines changed: 427 additions & 1626 deletions
Large diffs are not rendered by default.

METADATA_SUPPORT.md

Lines changed: 637 additions & 639 deletions
Large diffs are not rendered by default.

contributing/metadata.md

Lines changed: 51 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,54 @@
22

33
You can view the existing metadata coverage by release using [METADATA_SUPPORT.md](../METADATA_SUPPORT.md)
44

5-
- It can be updated by running
65
- The script runs daily via github actions. You only need to run it if you want to see the results of your registry changes.
6+
- It can be updated by running
77

88
```shell
99
yarn update-supported-metadata
1010
```
1111

12-
Got questions?
12+
## Project Setup
1313

14-
- If you work for Salesforce,
15-
- For general questions, post in [#platform-cli](https://salesforce-internal.slack.com/archives/C01LKDT1P6J)
16-
- For PR reviews, post in [#platform-cli-collaboration](https://salesforce.enterprise.slack.com/archives/C06V045BZD0)
17-
- If not, [open an issue](https://github.com/forcedotcom/cli/issues)
14+
1. Fork [SourceDeployRetrieve github repo](https://github.com/forcedotcom/source-deploy-retrieve)
15+
1. Clone forked repo in local and checkout a new branch
16+
1. Setup Yarn
17+
1. Go to the repo directory
18+
1. Run `yarn install && yarn build`
1819

1920
## Adding new types to the registry via a script
2021

2122
> NOTE: If you have a “Settings” metadata type, you do not need to follow these instructions. Support for your type is already built into SDR.
2223
23-
To simplify modifying the registry, there's a script.
24+
### Path 1: Using Core Metadata
25+
26+
There exists a test in Core `GenerateCLITypeRegistryInfoTest` that generates a file `cli-type-registry-info.json`.
27+
28+
The test is manually run, the file is committed to `patch`, and the output is manually copied to `../scripts/update-registry/describe.json` in SDR.
2429

25-
> Note: The script depends on being able to create an org that will have your type. If you have a working org, but your type isn't compatible with scratch org, you can [use an existing org](#use-an-existing-org)
30+
If your metadata type is simple and already in the file, run `yarn update-registry-org <MetadataEntity1> <MetadataEntity2>` (you'll see warnings if your type is missing or too complex for the script to handle)
2631

27-
> Note: The script will use your default dev hub. If you don't have one, set one up. If you want to use a different hub, update your default.
32+
### Path 2: Using Describe from an Org
33+
34+
> Note: The script asks your org for describe information about your type. Make sure that `sf org list metadata-types` returns the correct information for your type.
2835
2936
The script will:
3037

31-
1. Look for missing types (similar to the completeness test)
32-
2. For missing types, generate a project and scratch org that includes the Features/Settings
33-
3. Run `sf org list metadata-types` to get the describe
34-
4. Modify the registry to include the newly found types
38+
1. Look for missing types (similar to the completeness test) OR the types you specify
39+
1. Run `sf org list metadata-types` to get the describe
40+
1. Modify the registry to include the newly found types
3541

3642
```shell
37-
yarn update-registry YourTypeNameHere
43+
sf alias set registryBuilder=<the org's username>
44+
yarn update-registry-org <MetadataEntity1> <MetadataEntity2>
3845
```
3946
4047
You can set the environment variable `SF_ORG_API_VERSION` if you want to specify an API version.
4148
49+
### Results
50+
51+
You should see updates to `src/registry/metadataRegistry.json` (check `git status`)
52+
4253
### What the script can't do
4354

4455
inFolderTypes and types with childXml in their describe are not supported. You **want** to explore the various strategies for those (see the [SDR Handbook](../HANDBOOK.md) in this repo) and [create tests](#integration-testing) to validate that your types are being handled correctly.
@@ -51,6 +62,8 @@ If that's confusing, it's a great time to reach out to the CLI team.
5162

5263
## Manual Edits
5364

65+
> only do this if the script can't handle our type OR your type isn't in the CoverageReport yet and the script won't see it
66+
5467
You can do what the script does yourself. As you work, run `./node_modules/mocha/bin/mocha test/registry/registryValidation.test.ts` to check your entries
5568
5669
Run `sf org list metadata-types --json` to get the describe. `>` the output to a file or pipe it to [jq](https://stedolan.github.io/jq/) (`| jq`) to find your type.
@@ -135,23 +148,31 @@ The completeness is checked by comparing the registry to the metadata coverage r
135148

136149
If you find your types (or the features they require) excluded by `nonSupportedTypes.ts` but think they're ready to go, feel free to remove them from the list.
137150
138-
There are 2 main ways this happens (or ways to make this work if it currently isn't)
151+
## Manual Testing
139152
140-
1. A feature is available to scratch orgs when it previously wasn't
141-
1. The metadata coverage report's "settings" were not sufficient to enable your type to appear in the `describe` call.
153+
Want to make sure your types are working as expected?
142154
143-
Fixing those problems not only makes it easier to automate your type's support in the library, but also makes your type usable by customers (features) and fixes your documentation (coverageReport).
155+
### Path 1 (replace the registry in your CLI)
144156
145-
## Manual Testing
157+
1. find where your CLI has `metadataRegistry.json`. This varies based on how you installed the CLI and your machine. For example, using the installers on a mac, the registry is in ~/.local/share/sf/client/current/node_modules/@salesforce/source-deploy-retrieve/lib/src/registry/metadataRegistry.json
158+
1. copy your modified registry from SDR over the existing file in your CLI
146159
147-
Want to make sure your types are working as expected?
160+
### Path 2 (patch the registry via registryCustomizations)
148161
149162
1. Create a new project with `sf project generate -n registryTest`
150-
1. Create a scratch org `sf org create scratch`
163+
1. Open the generated `sfdx-project.json` and add a property `registryCustomizations`. Its shape is the same as the Metadata Registry, and it is treated as a "patch" for the default registry. If you generated registry changes above, you can add just those changes to `registryCustomizations`.
164+
1. suffixes
165+
1. strictDirectoryNames (could be empty if your new type doesn't use this)
166+
1. childTypes (could be empty if your new type doesn't use this)
167+
1. types
168+
169+
### Sample validation
170+
171+
1. Create a scratch org `sf org create scratch` (edit the scratch org definition file if your types needs features/settings)
151172
1. Open the org and create your types.
152-
1. Run `sf project deploy preview` and verify the remote add.
173+
1. Run `sf project retrieve preview` and verify the remote add.
153174
1. Run `sf project retrieve start` to pull the metadata and examine what is retrieved
154-
1. Run `sf project deploy preview` and verify the changes were retrieved and no longer appear.
175+
1. Run `sf project retrieve preview` and verify the changes were retrieved and no longer appear.
155176
1. Delete the org `sf org delete scratch --no-prompt`
156177
1. Create a new scratch org. `sf org create scratch`
157178
1. Push the source `sf project deploy start`
@@ -169,10 +190,10 @@ Target types must be MDAPI addressable on the server. If they aren’t MDAPI add
169190
170191
## Unit Testing
171192
172-
Reach out to the CLI team for help with unit tests.
173-
174193
[metadataResolver.ts](../test/resolve/metadataResolver.test.ts) is an example of unit testing one behavior (resolving from source files) of a real metadata type.
175194
195+
We don't recommend additional UT for anything the script generated. But if you had a complex type, reach out to the CLI team for help with unit tests.
196+
176197
## Integration Testing
177198

178199
If you're doing anything complex (you've used any of the following properties `strategies`, `folderType`, `inFolder=true`, `ignoreParsedFullName`, `folderContentType`, `ignoreParentName`), you'll want to add some NUTs (not-unit-tests) that verify the behavior or your types using real orgs and to prevent SDR changes from causing regressions on your types.
@@ -183,61 +204,9 @@ NUTs live in [plugin-deploy-retrieve](https://github.com/salesforcecli/plugin-de
183204
184205
See [testkit](https://github.com/salesforcecli/cli-plugins-testkit) for examples and usage.
185206
186-
# Tips and Tricks
187-
188-
### Work in stages
207+
## Got questions?
189208
190-
If you see a whole bunch of new unsupported types, you can "ignore" all the features and work through them in chunks (uncomment a feature at a time) using nonSupportedTypes.ts
191-
192-
If you want to update the registry for only a subset of the currently missing metadata types, add your types as arguments to the script.
193-
194-
```bash
195-
# normal, update all missing types
196-
yarn update-registry
197-
# only update the 2 types listed
198-
yarn update-registry AssessmentQuestion AssessmentQuestionSet
199-
```
200-
201-
### DevHub settings
202-
203-
Some metadata types require features which require modifications to the DevHub (licenses, etc) and some may have to stay ignored (ex: a pilot feature you can't enable)
204-
205-
### Use an existing org
206-
207-
You can use an existing org for the metadata describe portion of the script by
208-
209-
1. setting its alias to `registryBuilder`
210-
2. setting the env `RB_EXISTING_ORG` ex: `RB_EXISTING_ORG=true yarn update-registry`
211-
212-
### Steps to add your metadata in registry
213-
214-
## Prerequisites
215-
216-
1. A sfdx project must exist in local `sf project generate --name <projectname> --default-package-dir <directory> -x`
217-
1. An authorized devhub org must exists `sf org login web -a <alias> -r <localhost url> -d`
218-
1. A scratch org must exists with alias `registryBuilder`
219-
1. Update `project-scratch-def.json` as per your requirements
220-
1. Run `sf org create scratch -f config/project-scratch-def.json -a registryBuilder -d`
221-
222-
## Steps
223-
224-
1. Fork [SourceDeployRetrieve github repo](https://github.com/forcedotcom/source-deploy-retrieve)
225-
1. Clone forked repo in local and checkout a new branch
226-
1. Setup Yarn
227-
1. Go to the repo directory
228-
1. Run `yarn install && yarn build`
229-
1. Setup an environment variable by executing command `export RB_EXISTING_ORG=true`
230-
1. Execute yarn update command for required metadata entities `yarn update-registry <MetadataEntity1> <MetadataEntity2>`
231-
1. Check if respective file (`src/registry/metadataRegistry.json`) was updated with `git status`
232-
233-
Now changes are available in local, we have to link the registry with sfdx project
234-
235-
1. From SDR git repo directory, run `yarn build && yarn link`
236-
1. Clone the [plugin-deploy-retrieve repo](https://github.com/salesforcecli/plugin-deploy-retrieve)
237-
1. From cloned plugin repo directory execute
238-
1. `yarn link @salesforce/source-deploy-retrieve`
239-
1. `sfdx plugins:link .`
240-
1. `yarn build`
241-
242-
Registry has been set for your entities, now you can run (e.g.) `sf project deploy start` command for your entities:
243-
Proceed to `Manual Testing` section above in this document.
209+
- If you work for Salesforce,
210+
- For general questions, post in [#platform-cli](https://salesforce-internal.slack.com/archives/C01LKDT1P6J)
211+
- For PR reviews, post in [#platform-cli-collaboration](https://salesforce.enterprise.slack.com/archives/C06V045BZD0)
212+
- If not, [open an issue](https://github.com/forcedotcom/cli/issues)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"@types/mime": "2.0.3",
4949
"@types/minimatch": "^5.1.2",
5050
"deep-equal-in-any-order": "^1.1.19",
51-
"deepmerge": "^4.3.1",
5251
"eslint-plugin-sf-plugin": "^1.20.5",
5352
"mocha-junit-reporter": "^1.23.3",
5453
"mocha-snap": "^5.0.0",
@@ -79,7 +78,8 @@
7978
"test:only": "wireit",
8079
"test:registry": "mocha ./test/registry/registryCompleteness.test.ts --timeout 50000",
8180
"test:snapshot": "wireit",
82-
"update-registry": "npx ts-node scripts/update-registry/update2.ts",
81+
"update-registry-org": "npx ts-node scripts/update-registry/updateRegistryFromOrg.ts",
82+
"update-registry-core": "npx ts-node scripts/update-registry/updateRegistryFromCoreMetadata.ts",
8383
"update-supported-metadata": "npx ts-node scripts/update-registry/update-supported-metadata.ts"
8484
},
8585
"lint-staged": {

0 commit comments

Comments
 (0)