|
| 1 | +# Contribution workflow and the review process |
| 2 | + |
| 3 | +This document outlines the best practice, using git and CI, which **must** be followed |
| 4 | +for all contributions to `mlip-testing`. Also contained are instructions and tips for |
| 5 | +managing your fork of the project, which will help keep merges clean and avoid many |
| 6 | +headaches. |
| 7 | + |
| 8 | +Please read our |
| 9 | +[developer documentation](https://ddmms.github.io/mlip-testing/developer_guide/index.html) |
| 10 | +for more technical details relating to contributions. |
| 11 | + |
| 12 | +## Golden rules |
| 13 | + |
| 14 | +In brief the rules for contribution are as follows: |
| 15 | + |
| 16 | +- Follow the branch, fix, merge model, from your own fork or fork/branch model |
| 17 | +- An issue must be created for every piece of work (new benchmark, bug, feature, *etc.*) |
| 18 | +- Pull/merge requests will not be accepted without a review |
| 19 | +- New features must have a test |
| 20 | +- All tests must pass, no regressions may be merged |
| 21 | + |
| 22 | +## Contributing benchmarks/models |
| 23 | + |
| 24 | +Please consult our online documentation on |
| 25 | +[adding benchmarks](https://ddmms.github.io/mlip-testing/developer_guide/add_benchmarks.html) |
| 26 | +and |
| 27 | +[adding models](https://ddmms.github.io/mlip-testing/developer_guide/add_models.html) |
| 28 | +for a detailed description of the process involved. |
| 29 | + |
| 30 | +## Issues |
| 31 | + |
| 32 | +### Using issues |
| 33 | + |
| 34 | +- Open an issue for each piece of work done, using the appropriate issue template |
| 35 | +- Open issues for design discussions. The answers may be important for newer members |
| 36 | +- When adding features, use comments to provide succinct reports on progress |
| 37 | + |
| 38 | +### Labels |
| 39 | + |
| 40 | +Labels may be assigned to issues to help classify them. Examples include: |
| 41 | + |
| 42 | +- `new benchmark`: Proposing or discussing a new benchmark |
| 43 | +- `bug`: something is not working as expected. We typically aim to fix these ASAP |
| 44 | +- `Eehancement`: adding or improving on features |
| 45 | +- `testing`: adding or enhancing unit testing or CI |
| 46 | +- `documentation`: adding or enhancing documentation |
| 47 | +- `question`: Something is unclear |
| 48 | + |
| 49 | +## Review |
| 50 | + |
| 51 | +All merge requests will be reviewed to ensure the integrity of the code. |
| 52 | + |
| 53 | +The reviewer(s) have the following responsibilities: |
| 54 | + |
| 55 | +- Ensuring all contribution rules have been followed |
| 56 | +- Ensuring the [coding style](./coding_style.md) is adhered to |
| 57 | +- Only accepting a merge if all tests have passed |
| 58 | +- Using the comments system to request changes for the submitter to make |
| 59 | + |
| 60 | +### Enforcing style |
| 61 | + |
| 62 | +GitHub Actions will automatically run a pre-commit and enforce the coding style. To |
| 63 | +reduce the number of CI failures, please run the pre-commit locally before you push to |
| 64 | +your repository. |
| 65 | + |
| 66 | +```sh |
| 67 | + pre-commit run --all-files |
| 68 | +``` |
| 69 | + |
| 70 | +## Using git for development |
| 71 | + |
| 72 | +The GitHub instance hosts an *upstream* repository, which we will refer to as |
| 73 | +*upstream*. Contributors will work on their own personal copies of the repository by |
| 74 | +creating *forks*. This allows us to keep *upstream* clean, while users may work on |
| 75 | +their own *fork*, creating commits and changing the code as they see fit. Only in |
| 76 | +exceptional circumstances are branches allowed in *upstream*. |
| 77 | + |
| 78 | +The *upstream* repository may be cloned as follows, |
| 79 | + |
| 80 | +``` sh |
| 81 | +git clone [email protected]:ddmms/mlip-testing.git |
| 82 | +``` |
| 83 | + |
| 84 | +A *fork* is created using the web UI. It may then be cloned for a user called |
| 85 | +'username' as follows: |
| 86 | + |
| 87 | +``` sh |
| 88 | +git clone [email protected]:username/mlip-testing.git mlip-testing-username |
| 89 | +``` |
| 90 | + |
| 91 | +or added as an alternative origin in the *upstream* cloned repository: |
| 92 | + |
| 93 | +``` sh |
| 94 | +git remote add username [email protected]:username/mlip-testing.git |
| 95 | +``` |
| 96 | + |
| 97 | +### Branch, fix, merge model: |
| 98 | + |
| 99 | +All work should follow the workflow of branch, fix, merge. Let us assume you have an |
| 100 | +issue with your code which needs to be fixed. |
| 101 | + |
| 102 | +#### Step 1: Branch from your fork |
| 103 | + |
| 104 | +Create a new branch for the issue on the dashboard of your fork, we will assume the |
| 105 | +branch is called 'fix-xyz'. Clone the branch, |
| 106 | + |
| 107 | +``` sh |
| 108 | +$ git clone -b fix-xyz --single-branch [email protected]:username/mlip-testing.git mlip-testing-fix-xyz |
| 109 | +``` |
| 110 | + |
| 111 | +Alternatively you can create the branch in the CLI using |
| 112 | + |
| 113 | +``` sh |
| 114 | +# clone the repository, if you already have a local repository this is not nessecary |
| 115 | +$ git clone [email protected]:username/mlip-testing.git mlip-testing-fix-xyz |
| 116 | +$ pushd mlip-testing-fix-xyz |
| 117 | +# create and checkout a new branch (this is equivilent to git branch followed by git checkout) |
| 118 | +$ git checkout -b fix-xyz |
| 119 | +# create a remote tracking branch for you to push your changes to |
| 120 | +$ git push -u origin fix-xyz |
| 121 | +``` |
| 122 | + |
| 123 | +#### Step 2: Fix the issue and commit your changes |
| 124 | + |
| 125 | +Fix whatever is wrong. Use `git status` to see which files you have |
| 126 | +changed and prepare a commit. |
| 127 | + |
| 128 | +``` sh |
| 129 | +# stage changes |
| 130 | +$ git add <filename|folder> # to add the new things |
| 131 | +# commit the changes with a clear and brief message |
| 132 | +$ git commit -m "<commit message>" |
| 133 | +# push the commit to origin |
| 134 | +$ git push |
| 135 | +``` |
| 136 | + |
| 137 | +#### Step 3a: Merge your branch into upstream |
| 138 | + |
| 139 | +Follow the provided link after the push and continue to the web interface. Add any |
| 140 | +relevant labels or milestones and assign a reviewer. Compare the code and if you are |
| 141 | +happy click to submit your pull request. |
| 142 | + |
| 143 | +After the pull request has been submitted, tests will be run and your reviewer will be |
| 144 | +notified. |
| 145 | + |
| 146 | +#### Step 3b: Finalising the merge |
| 147 | + |
| 148 | +If all is OK with the commit your reviewer may set the request to be merged once all |
| 149 | +tests pass. Otherwise the reviewer may open discussions using the GitHub comment system |
| 150 | +to point out issues that may need to be addressed before the commit can be merged. |
| 151 | + |
| 152 | +If changes need to be made you may make more commits onto your branch. When you push |
| 153 | +your branch to your *fork* the pull request will be automatically updated to use the |
| 154 | +latest commit. Reply to the discussions to indicate when and how they have been |
| 155 | +addressed. |
| 156 | + |
| 157 | +If your branch has become out of sync with *upstream* then conflicts may arise. |
| 158 | +Sometimes these cannot be automatically resolved and you will need to resolve them by |
| 159 | +hand. GitHub provides instructions for this, or you can follow this routine, |
| 160 | + |
| 161 | +``` sh |
| 162 | +# add upstream as a remote if you have not already |
| 163 | +$ git remote add upstream [email protected]:ddmms/mlip-testing.git |
| 164 | +# get the changes to upstream since you started working on your issue |
| 165 | +$ git fetch upstream |
| 166 | +# merge these changes into your branch (assuming you want to merge into the main branch on upstream) |
| 167 | +$ git merge upstream/main |
| 168 | +# resolve any conflicts |
| 169 | +# push to your fork |
| 170 | +$ git push |
| 171 | +``` |
| 172 | + |
| 173 | +Alternatively you may use rebase which will replay the changes you made in your branch |
| 174 | +on top of *upstream/main*. However, be sure you understand the differences between |
| 175 | +merge and rebase. |
| 176 | + |
| 177 | +``` sh |
| 178 | +# add upstream as a remote if you have not already |
| 179 | +$ git remote add upstream [email protected]:ddmms/mlip-testing.git |
| 180 | +# get the changes to upstream since you started working on your issue |
| 181 | +$ git fetch upstream |
| 182 | +# merge these changes into your branch (assuming you want to merge into the main branch on upstream) |
| 183 | +$ git rebase -i upstream/main |
| 184 | +# resolve any conflicts |
| 185 | +# push to your fork |
| 186 | +$ git push |
| 187 | +``` |
| 188 | + |
| 189 | + |
| 190 | +### Advanced git |
| 191 | + |
| 192 | +#### Keeping your fork in sync with project |
| 193 | + |
| 194 | +By adding two remotes, one for *upstream* and one for your *fork* it is possible to |
| 195 | +keep your *fork* in sync with *upstream*. This will greatly simplify merge requests. |
| 196 | +GitHub also offers a sync functionality in their web UI that achieves the same. |
| 197 | + |
| 198 | +``` sh |
| 199 | +# clone your fork |
| 200 | +$ git clone [email protected]:username/mlip-testing.git mlip-testing-username |
| 201 | +pushd mlip-testing-username |
| 202 | +# add a remote for upstream |
| 203 | +$ git remote add upstream [email protected]:ddmms/mlip-testing.git |
| 204 | +``` |
| 205 | + |
| 206 | +These commands need to be done only once. `git remote -v` shall show you |
| 207 | +the origin and project fetch and push links |
| 208 | + |
| 209 | +``` sh |
| 210 | +$ git remote -v |
| 211 | +origin [email protected]:username/mlip-testing.git (fetch) |
| 212 | +origin [email protected]:username/mlip-testing.git (push) |
| 213 | +upstream [email protected]:ddmms/mlip-testing.git (fetch) |
| 214 | +upstream [email protected]:ddmms/mlip-testing.git (push) |
| 215 | +``` |
| 216 | + |
| 217 | +When you need to sync your *fork* with *upstream*, do the following, |
| 218 | + |
| 219 | +``` sh |
| 220 | +# get the latest commits from upstream |
| 221 | +$ git fetch upstream |
| 222 | +# ensure you are in the main branch of your fork |
| 223 | +$ git checkout main |
| 224 | +# merge your main branch into the main branch of upstream |
| 225 | +$ git merge upstream/main |
| 226 | +# push these changes back to the remote of your fork (origin) |
| 227 | +$ git push |
| 228 | +``` |
| 229 | + |
| 230 | +Of course, one can use a similar process to merge any other branch or available |
| 231 | +projects. |
| 232 | + |
| 233 | +#### Rebasing commits |
| 234 | + |
| 235 | +When working on an issue you may use multiple commits. When you are ready to create a |
| 236 | +merge request, you should squash your changes into one commit in order to keep |
| 237 | +*upstream* clean. This is most easily achieved with an interactive rebase. |
| 238 | + |
| 239 | +Assuming you have made five commits, |
| 240 | + |
| 241 | +``` sh |
| 242 | +# rebase your branch five commits before HEAD i.e. where your branch originally diverged |
| 243 | +$ git rebase -i HEAD~5 |
| 244 | +# follow the instructions. 'pick' the first commit then 'sqaush' or 'fixup' the rest. |
| 245 | +# You should now be left with a single commit containing all your changes |
| 246 | +# Push your commmit to the remote, use --force-with-lease if you have already pushed this branch to |
| 247 | +# 'rewrite history' |
| 248 | +$ git push origin branchname --force-with-lease |
| 249 | +``` |
| 250 | + |
| 251 | +Using force is a powerful and dangerous option, use it only if you know 150% nobody |
| 252 | +else touched that branch. |
| 253 | + |
| 254 | +#### Cleaning stale branches |
| 255 | + |
| 256 | +Deleting branches from the web interface will get rid of the remotes and not of your |
| 257 | +local copies. The local branches left behind are called stale branches. To get rid of |
| 258 | +them: |
| 259 | + |
| 260 | +``` sh |
| 261 | +$ git remote prune origin |
| 262 | +``` |
| 263 | + |
| 264 | +To delete a local branch: |
| 265 | + |
| 266 | +``` sh |
| 267 | +$ git branch -d localBranch |
| 268 | +``` |
| 269 | + |
| 270 | +If unmerged commits exists, but you still want to delete the branch, use: |
| 271 | + |
| 272 | +``` sh |
| 273 | +$ git branch -D localBranch |
| 274 | +``` |
| 275 | + |
| 276 | +To delete a remote branch on the remote *origin* use: |
| 277 | + |
| 278 | +``` sh |
| 279 | +$ git push -d origin remoteBranch |
| 280 | +``` |
| 281 | + |
| 282 | +## Code Coverage |
| 283 | + |
| 284 | +Ensure that any code you add does not reduce the code coverage in a meaningful way. |
| 285 | +Reviewers may insist on new test to be added. Please cooperate. |
0 commit comments