This document outlines some conventions about development workflow, commit message formatting, contact points and other resources to make it easier to get your contribution accepted.
Before you start, you need Set up your GO development environment.
-
Install
Go
version 1.14 or above. Refer to How to Write Go Code for more information. -
Define
GOPATH
environment variable and modifyPATH
to access your Go binaries. A common setup is as follows. You could always specify it based on your own flavor.export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin
Note: TiDB uses
Go Modules
to manage dependencies.
Now you should be able to use the make build
command to build TiDB.
To contribute to the goInception code base, please follow the workflow as defined in this section.
- Create a topic branch from where you want to base your work. This is usually master.
- Make commits of logical units and add test case if the change fixes a bug or adds new functionality.
- Run tests and make sure all the tests are passed.
- Make sure your commit messages are in the proper format (see below).
- Push your changes to a topic branch in your fork of the repository.
- Submit a pull request.
Thanks for your contributions!
- Visit https://github.com/hanchuanchuan/goInception
- On the top right of the page, click the
Fork
button (top right) to create a cloud-based fork of the repository.
Per Go's workspace instructions,
place TiDB's code on your GOPATH
using the following cloning procedure.
Define a local working directory:
# Set `user` to match your github profile name:
export user={your github profile name}
export working_dir=$GOPATH/src/github.com/${user}
Both $working_dir
and $user
are mentioned in the figure above.
Create your clone:
mkdir -p $working_dir
cd $working_dir
git clone https://github.com/${user}/goInception.git
# or: git clone [email protected]/${user}/goInception.git
cd $working_dir/goInception
git remote add upstream https://github.com/hanchuanchuan/goInception.git
# or: git remote add upstream [email protected]/hanchuanchuan/goInception.git
# Never push to the upstream master.
git remote set-url --push upstream no_push
# Confirm that your remotes make sense:
# It should look like:
# origin [email protected]:$(user)/goInception.git (fetch)
# origin [email protected]:$(user)/goInception.git (push)
# upstream https://github.com/hanchuanchuan/goInception (fetch)
# upstream no_push (push)
git remote -v
Set the pre-commit
hook. This hook checks your commits for formatting,
building, doc generation, etc:
cd $working_dir/goInception/
ln -s `pwd`/hooks/pre-commit .git/hooks/
chmod +x $working_dir/goInception/.git/hooks/pre-commit
Get your local master up to date:
cd $working_dir/goInception
git fetch upstream
git checkout master
git rebase upstream/master
Branch from master:
git checkout -b feature-test
You can now edit the code on the feature-test
branch.
A mysql instance is required to run local tests to test audit, execution, and backup functions.
- mysql recommended version:
5.7
- mysql startup parameters(or set my.cnf)
mysqld --log-bin=on --server_id=111 --character-set-server=utf8mb4
- Create a test database
mysql -e "create database if not exists test DEFAULT CHARACTER SET utf8;create database if not exists test_inc DEFAULT CHARACTER SET utf8;"
- Create a test user
mysql -e "grant all on *.* to test@'127.0.0.1' identified by 'test';FLUSH PRIVILEGES;"
Build and run all tests:
# build and run the unit test to make sure all tests are passed.
make dev
# Check the checklist before you move on.
make checklist
You can also run a single unit test in a file. For example, to run test
TestToInt64
in file types/datum.go
:
GO111MODULE=on go test session/session_inception_*.go
# or:
GO111MODULE=on go test session/session_inception_test.go
The branch needs to be merged with the latest version of goInception before submitting, so as not to be unable to merge PR
# While on your feature-test branch.
git fetch upstream
git rebase upstream/master
Please don't use git pull
instead of the above fetch
/rebase
. git pull
does a merge, which leaves merge commits. These make the commit history messy
and violate the principle that commits ought to be individually understandable
and useful (see below). You can also consider changing your .git/config
file
via git config branch.autoSetupRebase
always to change the behavior of git pull
.
Commit your changes.
git commit
Likely you'll go back and edit/build/test further, and then commit --amend
in a
few cycles.
When the changes are ready to review (or you just to create an offsite backup
or your work), push your branch to your fork on github.com
:
git push --set-upstream ${your_remote_name} feature-test
- Visit your fork at
https://github.com/$user/goInception
. - Click the
Compare & Pull Request
button next to yourfeature-test
branch. - Fill in the required information in the PR template.
After PR submission, travisci test and circleci test will be automatically performed, During the review, any changes can be directly modified and submitted on the branch, the PR will use the latest commit, and there is no need to submit the PR again. If a PR involves multiple functions or fixes, it is recommended to split into multiple branches to facilitate review and merging.
You can refer to the coding style suggested by the Golang community style doc