|
1 | 1 | ---
|
2 |
| -title: Code Contribution Guide |
| 2 | +title: 代码贡献指南 |
3 | 3 | ---
|
4 |
| -In this code contribution guide, you will learn about the following: |
| 4 | +在本代码贡献指南,你将会了解下列内容: |
5 | 5 |
|
6 |
| -- [How to run Karpor locally](#running-karpor-locally) |
7 |
| -- [How to create a pull request](#creating-a-pull-request) |
8 |
| -- [Code review guidelines](#code-review) |
9 |
| -- [Formatting guidelines for pull requests](#formatting-guidelines) |
10 |
| -- [Updating Documentation and Website](#updating-documentation-and-website) |
| 6 | +- [如何在本地运行 Karpor](#%E5%A6%82%E4%BD%95%E5%9C%A8%E6%9C%AC%E5%9C%B0%E8%BF%90%E8%A1%8C-karpor) |
| 7 | +- [如何创建拉取请求(pull request)](#%E5%88%9B%E5%BB%BA%E6%8B%89%E5%8F%96%E8%AF%B7%E6%B1%82pull-request) |
| 8 | +- [代码审查指导规则](#%E4%BB%A3%E7%A0%81%E5%AE%A1%E6%9F%A5) |
| 9 | +- [Pull request 格式指南](#pull-request-%E6%A0%BC%E5%BC%8F%E6%8C%87%E5%8D%97) |
| 10 | +- [更新文档和网站](#%E6%9B%B4%E6%96%B0%E6%96%87%E6%A1%A3%E5%92%8C%E7%BD%91%E7%AB%99) |
11 | 11 |
|
12 |
| -## Running Karpor Locally |
| 12 | +## 如何在本地运行 Karpor |
13 | 13 |
|
14 |
| -This guide will help you get started with Karpor development. |
| 14 | +本指南将会帮助你开始 Karpor 开发。 |
15 | 15 |
|
16 |
| -### Prerequisites |
| 16 | +### 前提条件 |
17 | 17 |
|
18 |
| -* Golang version 1.19+ |
| 18 | +* Golang 版本 1.19+ |
19 | 19 |
|
20 | 20 | <details>
|
21 |
| - <summary>Installing Golang</summary> |
| 21 | + <summary>安装 Golang</summary> |
22 | 22 |
|
23 |
| -1. Install go1.19 from the [official website](https://go.dev/dl/). Extract the binary files and place them at a location, assuming it is located under the home directory `~/go/`, here is an example command, you should choose the correct binary file for your system. |
| 23 | +1. 从 [官方网站](https://go.dev/dl/) 安装 golang 1.19+。解压二进制文件并放置到某个位置,假设该位置是 home 目录下的 `~/go/`,下面是一个示例命令,你应当选择适合你系统的正确二进制文件。 |
24 | 24 |
|
25 | 25 | ```
|
26 | 26 | wget https://go.dev/dl/go1.20.2.linux-amd64.tar.gz
|
27 | 27 | tar xzf go1.20.2.linux-amd64.tar.gz
|
28 | 28 | ```
|
29 | 29 |
|
30 |
| -If you would like to maintain multiple versions of golang in your local development environment, you can download the package and extract it to a location, like `~/go/go1.19.1`, and then alter the path in the command below accordingly. |
| 30 | +如果你想在本地开发环境维护多个 golang 版本,你可以下载包并解压到某个位置,比如 `~/go/go1.19.1`,然后根据下面的命令相应地改变路径。 |
31 | 31 |
|
32 |
| -1. Set environment variables for Golang |
| 32 | +1. 为 Golang 设置环境变量 |
33 | 33 |
|
34 | 34 | ```
|
35 | 35 | export PATH=~/go/bin/:$PATH
|
36 | 36 | export GOROOT=~/go/
|
37 | 37 | export GOPATH=~/gopath/
|
38 | 38 | ```
|
39 | 39 |
|
40 |
| -If the `gopath` folder does not exist, create it with `mkdir ~/gopath`. These commands will add the go binary folder to the `PATH` environment variable (making it the primary choice for go) and set the `GOROOT` environment to this go folder. Please add these lines to your `~/.bashrc` or `~/.zshrc` file, so you won't need to set these environment variables every time you open a new terminal. |
| 40 | +如果 `gopath` 目录不存在,可以使用 `mkdir ~/gopath` 创建。这些命令将会把 go 二进制文件所在的目录添加到 `PATH` 环境变量 (让其成为 go 命令的优先选择)并且设置 `GOROOT` 环境到该 go 目录。如果将这些行添加到你的 `~/.bashrc` or `~/.zshrc` 文件,你就不用每次打开新的终端时设置这些环境变量。 |
41 | 41 |
|
42 |
| -1. (Optional) Some regions, such as China, may have slow connection to the default go registry; you can configure GOPROXY to speed up the download process. |
| 42 | +1. (可选) 在一些地区,例如中国大陆,连接到默认的 go 仓库可能会很慢;你可以配置 GOPROXY 来加速下载过程。 |
43 | 43 |
|
44 | 44 | ```
|
45 | 45 | go env -w GOPROXY=https://goproxy.cn,direct
|
46 | 46 | ```
|
47 | 47 |
|
48 | 48 | </details>
|
49 | 49 |
|
50 |
| -* Kubernetes version v1.20+ configured with `~/.kube/config`. |
51 |
| -* golangci-lint version v1.52.2+, it will be installed automatically if you run `make lint`, if the installation fails, you can install it manually. |
| 50 | +* Kubernetes 版本 v1.20+ ,且配置文件保存在 `~/.kube/config`。 |
| 51 | +* golangci-lint 版本 v1.52.2+, 通过运行 `make lint` 可以自动安装,如果自动安装失败,你可以手动安装。 |
52 | 52 |
|
53 | 53 | <details>
|
54 |
| - <summary>Manually installing golangci-lint</summary> |
| 54 | + <summary>手动安装 golangci-lint</summary> |
55 | 55 |
|
56 |
| -You can install it manually following the [guide](https://golangci-lint.run/welcome/install), or use the command: |
| 56 | +你可以根据 [安装指南](https://golangci-lint.run/welcome/install)手动安装,或者使用以下命令: |
57 | 57 |
|
58 | 58 | ```
|
59 | 59 | cd ~/go/ && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.52.2
|
60 | 60 | ```
|
61 | 61 |
|
62 | 62 | </details>
|
63 | 63 |
|
64 |
| -### Building |
| 64 | +### 构建 |
65 | 65 |
|
66 |
| -- Clone this project |
| 66 | +- 克隆项目 |
67 | 67 |
|
68 | 68 | ```shell
|
69 | 69 | git clone [email protected]:KusionStack/karpor.git
|
70 | 70 | ```
|
71 | 71 |
|
72 |
| -- Build locally |
| 72 | +- 本地构建 |
73 | 73 |
|
74 |
| -Executing `make build-all` will build the executables for all platforms; if you only want to build for a specific platform, execute `make build-${PlatformName}`, e.g., `make build-darwin`. To see all available commands, execute `make help`. |
| 74 | +执行 `make build-all` 将会为所有平台创建可执行文件;如果你只想为特定平台构建,执行 `make build-${PlatformName}`,例如 `make build-darwin`。查看所有可用命令,执行 `make help`。 |
75 | 75 |
|
76 |
| -### Testing |
| 76 | +### 测试 |
77 | 77 |
|
78 |
| -It's essential to write tests to maintain code quality, you can run all unit tests by executing the following command in the project root directory: |
| 78 | +为了保证代码质量,编写测试代码是必不可少的,你可以在项目根目录运行以下命令执行单元测试: |
79 | 79 |
|
80 | 80 | ```shell
|
81 | 81 | make test
|
82 | 82 | ```
|
83 | 83 |
|
84 |
| -If you need to generate extra coverage report files, execute: |
| 84 | +如果你需要生成额外的覆盖率报告,执行: |
85 | 85 |
|
86 | 86 | ```shell
|
87 | 87 | make cover
|
88 | 88 | ```
|
89 | 89 |
|
90 |
| -Then you can view the content of the coverage report in a browser by running: |
| 90 | +接下来你可以执行下列命令,来从浏览器中阅读测试覆盖率报告: |
91 | 91 |
|
92 | 92 | ```shell
|
93 | 93 | make cover-html
|
94 | 94 | ```
|
95 | 95 |
|
96 |
| -## Creating a Pull Request |
| 96 | +## 创建拉取请求(Pull Request) |
97 | 97 |
|
98 |
| -We are thrilled that you are considering contributing to the Karpor project! |
| 98 | +我们很高兴你考虑为 Karpor 项目作出贡献! |
99 | 99 |
|
100 |
| -This document will guide you through the process of [creating a pull request](./index.md#contribute-a-pull-request). |
| 100 | +本文档将会指导你完成 [创建拉取请求](./index.md#contribute-a-pull-request) 的过程。 |
101 | 101 |
|
102 |
| -### Before you begin |
| 102 | +### 在你开始之前 |
103 | 103 |
|
104 |
| -We know you are excited to create your first pull request. Before we get started, make sure your code follows the relevant [code conventions](../2-conventions/2-code-conventions.md). |
| 104 | +我们知道你对于创建第一个 pull request 非常兴奋。在我们开始之前,请确保你的代码符合相关的 [代码规约](../2-conventions/2-code-conventions.md)。 |
105 | 105 |
|
106 |
| -### Your First Pull Request |
| 106 | +### 你的第一个 Pull Request |
107 | 107 |
|
108 |
| -Before submitting your PR, run the following commands to ensure they all succeed: |
| 108 | +在提交你的 PR 之前,运行下面的命令并确保它们都成功了: |
109 | 109 |
|
110 | 110 | ```
|
111 | 111 | make test
|
112 | 112 | make lint
|
113 | 113 | ```
|
114 | 114 |
|
115 |
| -If this is your first time contributing to an open-source project on GitHub, please make sure to read the instructions on [creating a pull request](https://help.github.com/en/articles/creating-a-pull-request). |
| 115 | +如果这是你第一次向 Github 上的开源项目贡献,请确保你已经阅读了 [创建拉取请求](https://docs.github.com/zh/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)。 |
116 | 116 |
|
117 |
| -To increase the chances of your pull request being accepted, please ensure your pull request follows these guidelines: |
| 117 | +为了提高你的 pull request 被接受的机会,请确保你的 pull rquest 符合以下指导规则: |
118 | 118 |
|
119 |
| -- The title and description match the implementation. |
120 |
| -- The commits in the pull request follow the [formatting guidelines](#Formatting-guidelines). |
121 |
| -- The pull request closes a related issue. |
122 |
| -- The pull request includes necessary tests to verify the expected behavior. |
123 |
| -- If your pull request has conflicts, please rebase your branch onto the main branch. |
| 119 | +- 标题和描述与实现相符。 |
| 120 | +- pull request 中的所有 commit 都符合 [格式指南](#Formatting-guidelines)。 |
| 121 | +- pull request 会关闭一个相关 issue。 |
| 122 | +- pull request 包含了必要的测试,以验证预期行为。 |
| 123 | +- 如果你的 pull request 有冲突,请将你的分支 rebase 到 main 分支。 |
124 | 124 |
|
125 |
| -If the pull request fixes a bug: |
| 125 | +如果 pull request 修复了一个漏洞: |
126 | 126 |
|
127 |
| -- The pull request description must contain `Closes #<issue number>` or `Fixes #<issue number>`. |
128 |
| -- To prevent regressions, the pull request should include tests that replicate the bug being fixed. |
| 127 | +- pull request 的描述中必须包含 `Closes #<issue number>` 或 `Fixes #<issue number>`。 |
| 128 | +- 为了避免回归问题,pull request 必须包含验证该漏洞被修复的测试。 |
129 | 129 |
|
130 |
| -## Code Review |
| 130 | +## 代码审查 |
131 | 131 |
|
132 |
| -Once you have created a pull request, the next step is to have others review your changes. Review is a learning opportunity for both reviewers and the author of the pull request. |
| 132 | +一旦你创建了一个 pull requset,下一步就是让其他人审查你的改动。代码审查对审查者和 pull request 作者都是很好的学习机会。 |
133 | 133 |
|
134 |
| -If you believe a specific person should review your pull request, you can tag them in the description or a comment. |
135 |
| -Tag a user by typing an `@` symbol followed by their username. |
| 134 | +如果你觉得某个特定的人应当审查你的 pull request,你可以在描述或评论中标记他们。 |
| 135 | +通过输入 `@` 符号和其用户名来标记用户。 |
136 | 136 |
|
137 |
| -We recommend that you read [How to do a code review](https://google.github.io/eng-practices/review/reviewer/) to learn more about code reviews. |
| 137 | +我们建议你阅读 [如何进行代码审查](https://google.github.io/eng-practices/review/reviewer/) 来了解更多关于代码审查的知识。 |
138 | 138 |
|
139 |
| -## Formatting Guidelines |
| 139 | +## Pull request 格式指南 |
140 | 140 |
|
141 |
| -A well-crafted pull request can minimize the time to get your changes accepted. These guidelines will help you write well-formulated commit messages and descriptions for your pull requests. |
| 141 | +精心编写的 pull request 可以最大程度地缩短你的更改被接受的时间。这些指南将帮助你为 pull requset 编写条理清晰的提交消息和说明。 |
142 | 142 |
|
143 |
| -### Commit Message Format |
| 143 | +### Commit 信息格式 |
144 | 144 |
|
145 |
| -More see: [Commit Conventions](../2-conventions/4-commit-conventions.md) |
| 145 | +了解更多:[Commit 规约](../2-conventions/4-commit-conventions.md) |
146 | 146 |
|
147 |
| -### Pull Request Title |
| 147 | +### Pull Request 标题 |
148 | 148 |
|
149 |
| -When accepting pull requests, the Karpor team merges all commits into one. |
| 149 | +在接受 pull request 时,Karpor 团队会将所有的 commit 合并为一个。 |
150 | 150 |
|
151 |
| -The pull request title becomes the subject line of the merged commit message. |
| 151 | +Pull request 的标题将会成为合并后的 commit 信息的描述。 |
152 | 152 |
|
153 |
| -We still encourage contributors to write informative commit messages, as they will be part of the Git commit body. |
| 153 | +我们仍然鼓励贡献者撰写详细的 commit 信息,因为它们将会作为 git commit 正文的一部分。 |
154 | 154 |
|
155 |
| -We use the pull request titles when generating change logs for releases. Hence, we strive to make the titles as informative as possible. |
| 155 | +我们在生成发布更新日志时将会使用 pull request 的标题。因此,我们会努力使标题尽可能具有信息量。 |
156 | 156 |
|
157 |
| -Make sure your pull request title uses the same format as the commit message subject line. If the format is not followed, we will add a `title-needs-formatting` label on the pull request. |
| 157 | +确保你的 pull request 标题使用与 commit 信息相同的格式。如果不遵循该格式,我们将会在该 pull request 添加 `title-needs-formatting` 标签。 |
158 | 158 |
|
159 |
| -### Passing All CI Checks |
| 159 | +### 通过所有 CI 检查 |
160 | 160 |
|
161 |
| -Before merging, all testing CIs should pass: |
| 161 | +在合并之前,所有的测试 CI 都应该通过: |
162 | 162 |
|
163 |
| -- Coverage should not drop. Currently, the pull request coverage should be at least 70%. |
164 |
| -- Karpor uses a **CLA** for the contributor agreement. It requires you to sign for every commit before merging the pull request. |
| 163 | +- 覆盖率不应该下降。当前,pull request 的覆盖率应当至少为 70%。 |
| 164 | +- Karpor 使用 **CLA** 作为贡献者协议。它要求你在第一次合并 pull request 之前签署。 |
165 | 165 |
|
166 |
| -## Updating Documentation and Website |
| 166 | +## 更新文档和网站 |
167 | 167 |
|
168 |
| -If your pull request has been merged, and it is a new feature or enhancement, you need to update the documentation and send a pull request to the [kusionstack.io](https://github.com/KusionStack/kusionstack.io) repository. |
| 168 | +如果你的 pull request 被合并了,而且它引入了新的特性或增强,你需要更新文档并且提交 pull requset 到 [kusionstack.io](https://github.com/KusionStack/kusionstack.io) 仓库。 |
169 | 169 |
|
170 |
| -Learn how to write documentation through the following guide: |
| 170 | +根据下面的文档了解如何编写文档: |
171 | 171 |
|
172 |
| -- [kusionstack.io Developer Guide](https://github.com/KusionStack/kusionstack.io/blob/main/README.md) |
| 172 | +- [kusionstack.io 开发者指南](https://github.com/KusionStack/kusionstack.io/blob/main/README.md) |
173 | 173 |
|
174 |
| -Awesome, you've completed the lifecycle of code contribution! |
| 174 | +太棒了,你已经完成了代码贡献的整个生命周期! |
0 commit comments