RustTemplate

Workflow

This section assumes you have fully followed START.md, REQ.md and the 2 required sections for the Workflow in EXTRAS.md

If don’t have a first version follow project start after that you should follow usual development.

Keep in mind extras and advice.

For an optimal coding experience I suggest you follow a test driven development model.

Git commands

This are the used git commands in my Workflow or some that you may need and an explanation to what they do.
unstaged - before doing git add .
staged/index - after doing git add .
remote - the target branch on GitHub

Project start

Planning

When beginning a new project you should start by writting your project about to reflect and get an idea of what you want it to do. Don’t go overkill just write enough to solve the problem you had originally. Also write the features your project needs to have in order to solve your original problem.

The above is the basic idea. I like to go beyond that and write personal, more detailed docs and make Excalidraw diagrams to help me see my vision better.

Beginning development

For the first basic version of the software, my workflow is basically the following

  1. Checkout the code to a branch called v0.1.0

    git checkout -b v0.1.0
    
  2. Start making changes and with every new meaningful change do the following

    • Complete your features list if you add any new.
    • Write any new usage the app has available.
    • Add a new q&a on your FAQ if needed.

    If all is good commmit the new changes.

    git add .
    git diff --staged # check changes
    git commit -m "add new feature"
    git push
    
  3. When you are done with making v0.1.0 do the following

    First make a video showcase for your project.
    Then merge the branch v0.1.0 into master by doing a PR on GitHub.
    And then in order to make a release:

    git switch master
    git pull
    git checkout -d v0.1.0
    git tag v0.1.0-stable # it's important your tag has stable in it
    git push --tags
    

    This will create a new release and CD pipelines will start compiling, making & publishing your releases. More about making releases

Usual development

After the first version this is how I would continue

  1. Checkout the code to a new branch, like feature-x
git checkout -b feature-x
  1. Add the new feature on the features list

  2. With every meaningful change

    • Write any new usage the app has available.
    • Add a new q&a on your FAQ if needed.

    Check the new changes

    git add .
    git diff --staged
    

    If everything is good follow keeping a changelog and once making a changelog push the changes.

    git add CHANGELOG.md
    git commit -m "change something"
    git push
    
  3. Once done implementing the feature do a PR on GitHub to master

  4. Once the PR was accepted create a new release

    git switch master
    git pull
    git checkout -d feature-x
    git tag v0.2.0-stable
    git push --tags
    

    More info about making a release

Making a release

Because of all the automation this template has you don’t have to fear or be tired of making new releases just because of a tiny bug since everything is really fast and simple.

First you have to keep in mind release tags have to look like the following.
v0.1.0-stable - for a stable release where homebrew pkg, AUR stable pkgs & crates.io get updated
v0.1.0-beta - where beta can be anything and the only external thing that gets updated is the AUR git pkg.

Second, while mostly optional since there are things in the CD pipelines that take care of this to an extent is updating the version of your software inside Cargo.toml to match the one you are releasing, don’t worry if you make a mistake, the CD pipeline will fix it for you.

Third once you have all the code you want for your next release on the master branch run the following

git tag v0.1.0-stable
git push --tags

This will make a new tag which will trigger the CD pipeline and start making the releases for you. Now that you have a new release on GitHub you should copy the contents of your CHANGELOG for the latest version and dump them in your release by doing an edit.

Keeping a changelog

While the release system generates a simple changelog from PRs and commits it’s not enough, we want our own, human written, changelog so our users can easily and exactly know what changed. I know there are also GitHub action that beautify this way of making changelog, but still it’s not good enough.

So what I do is everytime I have some changes staged

git add .

I run the following

git diff --staged

Look at all the changes I’ve made and start filling the CHANGELOG file

Once I’m about to release a new version I will copy the CHANGELOG and make it fresh (no changes written) and keep the tag master, while for the current version one I will delete any unfilled section and change the text from master to whatever the current version tag is.

Coding workflow

Coding in rust is all about functions so the way I do it is the following:

  1. Write a test.
  2. Write just enough code, no matter how bad, just to pass the test.
  3. Refactor the code
  4. Improve performance

Where needed I will also write integration tests and fuzz harnesses

Extras

Things to do while programming.

Road map

As you think of a new feature you want your project to have don’t hesitate to add it on the road map so you eventually get to making it. Also add that feature as unchecked on your README in the features section.

Third-party libraries

When adding a new crate to your project the first thing you should do is run cargo deny check to see if the crate complies with your requirements. Second thing is adding the crates to your README third-party libraries section.

Fuzzing

Any time you have a crucial function that you want to make sure it works properly under any circumstances you will want to create a fuzz harness and run it for some time. For this you can read the README inside the fuzz folder and look at the example. Additionally there are a few YouTube videos you can watch about cargo-fuzz.

Advice

Commits

Every commit should solve one type of issue and one only. You shouldn’t have commits fixing typos, bugs and making code changes together.

One common example would be you are making some code changes and then you suddenly find a bug or a typo, what you should do is fix that and then do something like this:

git add file_with_bug
git commit -m "fix bug x"
git push

After which you can continue with making your code changes and then commit those separately.

Multiple branches

You should use multiple branches to separate your work (hence why if you use the settings proposed you can’t even push to master directly).

One example of why you should do this is for example you are working on feature-x and then you suddenly find a bug or god forbids a vulnerability in your production code. What you can now do is create a new branch to fix that and merge it fast into master and make a new hot fix release while not having to commit any unfinished feature. Also you would merge that bugfix into your feature branch as well (or not if you prefer).