2022-11-03 13:54:49 +00:00
|
|
|
# Contributing
|
|
|
|
|
|
|
|
|
|
<!-- toc -->
|
2023-02-20 03:38:49 +00:00
|
|
|
- <a href="#welcome" id="toc-welcome">Welcome</a>
|
2022-12-18 20:26:58 +00:00
|
|
|
- <a href="#ci" id="toc-ci">CI</a>
|
|
|
|
|
- <a href="#logistics" id="toc-logistics">Logistics</a>
|
|
|
|
|
- <a href="#dev" id="toc-dev">Dev</a>
|
|
|
|
|
- <a href="#content" id="toc-content">Content</a>
|
|
|
|
|
- <a href="#tests" id="toc-tests">Tests</a>
|
|
|
|
|
- <a href="#documentation" id="toc-documentation">Documentation</a>
|
|
|
|
|
- <a href="#questions" id="toc-questions">Questions</a>
|
2022-11-03 13:54:49 +00:00
|
|
|
|
2023-02-20 03:38:49 +00:00
|
|
|
## Welcome
|
|
|
|
|
|
|
|
|
|
D2's [long-term mission](https://d2lang.com/tour/future/) is to significantly reduce the
|
|
|
|
|
amount of time and effort it takes to create and maintain high-quality diagrams for every
|
|
|
|
|
software team. We started this because we love the idea of creating diagrams with text --
|
|
|
|
|
but it was clear the existing solutions were inadequete in their state and speed of
|
2023-02-20 03:45:21 +00:00
|
|
|
execution for this idea to be widely usable.
|
2023-02-20 03:38:49 +00:00
|
|
|
|
|
|
|
|
We've tried our best to avoid the mistakes of the past and take inspiration from the most
|
2023-02-20 03:45:21 +00:00
|
|
|
successful modern programming and configuration languages. D2 has built up each step of
|
|
|
|
|
the text-to-diagram pipeline from scratch, rethinking each one from first principles, from
|
|
|
|
|
the dead simple syntax, to the readable compiler, our own SVG renderer, etc.
|
2023-02-20 03:38:49 +00:00
|
|
|
|
|
|
|
|
D2 is committed to making something people want to use. That means contributions don't
|
|
|
|
|
only have to be in the form of pull requests. Your bug reports, plugins, examples,
|
|
|
|
|
discussions of new ideas, help a great deal.
|
|
|
|
|
|
2023-02-20 03:45:21 +00:00
|
|
|
If you'd like to get involved, we're also committed to helping you merge that first pull
|
|
|
|
|
request. You should be able to freely pick up Issues tagged as "good first issue". If you
|
|
|
|
|
need help getting started, please don't hesitate to pop into Discord -- as long as you
|
|
|
|
|
want to help, we'll find the perfect task (complexity matches your appetite and
|
2023-02-20 03:38:49 +00:00
|
|
|
programming experience, in an area you're interested in, etc).
|
|
|
|
|
|
2022-11-03 13:54:49 +00:00
|
|
|
## CI
|
|
|
|
|
|
2022-11-22 00:32:58 +00:00
|
|
|
Most of D2's CI is open sourced in its own
|
2023-02-20 03:45:21 +00:00
|
|
|
[repository](https://github.com/terrastruct/ci), included as a submodule. After you clone
|
|
|
|
|
D2, make sure you initialize the submodules:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
git submodule update --init --recursive
|
|
|
|
|
```
|
2023-02-20 03:38:49 +00:00
|
|
|
|
|
|
|
|
`./make.sh` runs everything. Subcommands to run individual parts of the CI:
|
|
|
|
|
|
|
|
|
|
- `./make.sh fmt`
|
|
|
|
|
- `./make.sh lint`
|
|
|
|
|
- `./make.sh test`
|
|
|
|
|
- `./make.sh race`
|
|
|
|
|
- `./make.sh build`
|
|
|
|
|
|
2023-02-20 03:48:16 +00:00
|
|
|
Here's what a successful run should look like:
|
|
|
|
|
|
|
|
|
|
<img width="1582" alt="Screen Shot 2023-02-19 at 7 46 34 PM" src="https://user-images.githubusercontent.com/3120367/220004975-7a218b82-c5c1-4a71-b2bb-8695bbfd600c.png">
|
|
|
|
|
|
2023-02-20 03:38:49 +00:00
|
|
|
|
|
|
|
|
Please make sure CI is passing for any PRs submitted for review.
|
2022-11-03 13:54:49 +00:00
|
|
|
|
2023-02-20 03:45:21 +00:00
|
|
|
Be sure to update the submodule whenever there are changes:
|
2022-12-30 18:04:43 +00:00
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
git submodule update --recursive
|
|
|
|
|
```
|
|
|
|
|
|
2022-11-03 13:54:49 +00:00
|
|
|
## Logistics
|
|
|
|
|
|
2022-12-31 14:56:45 +00:00
|
|
|
- Use Go 1.18. Go 1.19's autofmt inexplicably strips spacing from ASCII art in comments.
|
2023-02-20 03:38:49 +00:00
|
|
|
We're working on it.
|
2022-12-31 16:10:48 +00:00
|
|
|
- Please sign your commits
|
|
|
|
|
([https://github.com/terrastruct/d2/pull/557#issuecomment-1367468730](https://github.com/terrastruct/d2/pull/557#issuecomment-1367468730)).
|
2022-11-22 02:32:25 +00:00
|
|
|
- D2 uses Issues as TODOs. No auto-closing on staleness.
|
2022-11-03 13:54:49 +00:00
|
|
|
- Branch off `master`.
|
|
|
|
|
- If there's an Issue related, include it by adding "[one-word] #[issue]", e.g. "Fixes
|
|
|
|
|
#123" somewhere in the description.
|
|
|
|
|
- Whenever possible and relevant, include a screenshot or screen-recording.
|
|
|
|
|
|
|
|
|
|
## Dev
|
|
|
|
|
|
|
|
|
|
### Content
|
|
|
|
|
|
2023-02-20 03:38:49 +00:00
|
|
|
Unless you've contributed before, it's safest to choose an Issue with a "good first issue"
|
|
|
|
|
label. If you'd like to propose new functionality or change to current functionality,
|
|
|
|
|
please create an Issue first with a proposal. When you start work on an Issue, please
|
|
|
|
|
leave a comment so others know that it's being worked on.
|
2022-11-03 13:54:49 +00:00
|
|
|
|
|
|
|
|
### Tests
|
|
|
|
|
|
2023-02-20 03:38:49 +00:00
|
|
|
D2 has extensive tests, and all code changes must include tests.
|
2022-11-03 13:54:49 +00:00
|
|
|
|
|
|
|
|
With the exception of changes to the renderer, all code should include a package-specific
|
2023-02-20 03:38:49 +00:00
|
|
|
test. If it's a visual change, an end-to-end (e2e) test should accompany.
|
|
|
|
|
|
|
|
|
|
Let's say I make some code changes. I can easily see how this affects the end result by
|
|
|
|
|
running:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
./ci/e2ereport.sh -delta
|
|
|
|
|
```
|
|
|
|
|
|
2023-02-20 03:45:21 +00:00
|
|
|
This gives me a nice HMTL output of what the test expected vs what it got (this was a PR
|
|
|
|
|
fixing multi-byte character labels):
|
2023-02-20 03:38:49 +00:00
|
|
|
|
|
|
|
|

|
2022-11-03 13:54:49 +00:00
|
|
|
|
2023-02-20 06:24:10 +00:00
|
|
|
Run `./ci/e2ereport.sh -help` for flags, including how to get deltas for a single test.
|
|
|
|
|
|
2022-11-03 13:54:49 +00:00
|
|
|
If you're testing labels and strings, it's encouraged to use 1-letter strings (`x`) in small
|
|
|
|
|
functional tests to minimally pinpoint issues. If you are testing something that exercises
|
|
|
|
|
variations in strings, or want to mimic more realistic diagram text, it's encouraged you
|
|
|
|
|
generate random strings and words from `fortune`. It gives a good range of the English
|
2023-02-20 03:38:49 +00:00
|
|
|
language. (Sometimes it gives controversial sentences -- don't use those.)
|
2022-11-03 13:54:49 +00:00
|
|
|
|
|
|
|
|
Script to generate one line of random text:
|
|
|
|
|
```
|
|
|
|
|
ipsum1() {
|
2022-11-21 04:16:29 +00:00
|
|
|
fortune | head -n1 | sed 's/^ *//;s/ *$//' | tr -d '\n' | tee /dev/stderr | pbcopy
|
2022-11-03 13:54:49 +00:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Running tests
|
|
|
|
|
|
|
|
|
|
Run: `./ci/test.sh`
|
|
|
|
|
|
|
|
|
|
CI runs tests with `-race` to catch potential race conditions. It's much slower, but if
|
|
|
|
|
your machine can run it locally, you can do so with `./make.sh race`.
|
|
|
|
|
|
2023-01-10 04:34:54 +00:00
|
|
|
If you add a new test and run, it will show failure. That's because the vast majority of
|
|
|
|
|
D2's tests are comparing outputs. You don't define the expected output manually. The
|
|
|
|
|
testing library generates it and it's checked into version control if it looks right. So
|
|
|
|
|
for the first run of a new test, it has no expected output, and will fail. To accept the
|
|
|
|
|
result as the expected, run the test with environment variable `TESTDATA_ACCEPT=1`.
|
|
|
|
|
|
2022-11-03 13:54:49 +00:00
|
|
|
#### Chaos tests
|
|
|
|
|
|
|
|
|
|
D2 has [chaos tests](https://en.wikipedia.org/wiki/Chaos_engineering) which produce random
|
|
|
|
|
configurations of diagrams. It can be helpful to run a few iterations (N~=100) to spot
|
|
|
|
|
cover your manual tests.
|
|
|
|
|
|
|
|
|
|
`D2_CHAOS_MAXI=100 D2_CHAOS_N=100 ./ci/test.sh ./d2chaos`
|
|
|
|
|
|
|
|
|
|
### Documentation
|
|
|
|
|
|
|
|
|
|
The code itself should be documented as appropriate with Go-style comments. No rules here,
|
|
|
|
|
`GetX()` doesn't need a `// GetX gets X`.
|
|
|
|
|
|
|
|
|
|
If it's some new functionality, please submit a pull request to document it in the
|
|
|
|
|
language docs:
|
|
|
|
|
[https://github.com/terrastruct/d2-docs](https://github.com/terrastruct/d2-docs).
|
|
|
|
|
|
|
|
|
|
### Questions
|
|
|
|
|
|
|
|
|
|
If you have any questions or would like to get more involved, feel free to open an issue
|
2022-11-10 00:07:47 +00:00
|
|
|
to discuss publicly, or chat in [Discord](https://discord.gg/NF6X8K4eDq)! If you have a
|
2022-11-09 21:55:33 +00:00
|
|
|
private inquiry, feel free to email us at hi@d2lang.com.
|