Crate cargo_auto_lib
source ·Expand description
§cargo_auto_lib
Library crate for common tasks when building rust projects. Intended for use with cargo-auto - automation tasks written in Rust language.
version: 1.3.35 date: 2024-02-28 author: Bestia.dev repository: GitHub
Hashtags: #rustlang #buildtool #developmenttool
My projects on GitHub are more like a tutorial than a finished product: bestia-dev tutorials.
§Try it
First, install the tool for task automation in Rust projects:
cargo install cargo-auto
Generate a new Rust CLI project:
cargo auto new_cli hello_world
Open the hello_world
project in VSCode:
code hello_world
Open the generated directory automation_tasks_rs
as an independent rust project in VSCode.
code hello_world/automation_tasks_rs
Now we can analyze the automation code. There is already this dependency inside Cargo.toml
for our library:
cargo_auto_lib="1.1.2"
Review the code in automation_tasks_rs/main.rs
. The cl::
namespace is the alias for cargo_auto_lib
.
Example:
/// cargo build --release
fn task_release() {
// let cargo_toml = CargoToml::read();
cl::auto_version_increment_semver_or_date();
cl::auto_cargo_toml_to_md();
cl::auto_lines_of_code("");
cl::run_shell_command("cargo fmt");
cl::run_shell_command("cargo build --release");
println!(
r#"{YELLOW}
After `cargo auto release`, run examples and tests
if ok, then,{RESET}{GREEN}
cargo auto doc{RESET}{YELLOW}
{RESET}"#
);
print_examples_cmd();
}
You can see this function will increment the version in Cargo.toml
.
Then it will copy some data from Cargo.toml
to README.md (title, description, version, author,…).
It will count the lines of code and create badges in README.md.
Then comes the traditional Rust part: cargo fmt and cargo build –release.
Finally, it will show on the screen the instructions on how to continue developing.
Run (in your main rust project):
cargo auto release
Now open the README.md and you will see the data that this automation task copied from other places. Therefore you change this data only in one place, the automation task copies them wherever needed.
§Caveats
This crate will attempt to edit Cargo.toml
. Unfortunately, there’s no great robust way right now to edit TOML file preserving formatting and comments and such, so right now I use just regex to do this.
If you find that the heuristics don’t work for you though please let me know and I’ll try to check in a fix!
§Development details
Read the development details in a separate md file:
DEVELOPMENT.md
§Releases changelog
Read the release changelog in a separate md file:
RELEASES.md
§TODO
Nothing big for now.
§Open-source and free as a beer
My open-source projects are free as a beer (MIT license).
I just love programming.
But I need also to drink. If you find my projects and tutorials helpful, please buy me a beer by donating to my PayPal.
You know the price of a beer in your local bar ;-)
So I can drink a free beer for your health :-)
Na zdravje! Alla salute! Prost! Nazdravlje! 🍻
//bestia.dev
//github.com/bestia-dev
//bestiadev.substack.com
//youtube.com/@bestia-dev-tutorials
Structs§
- similar to std::process::Output, but with i32 and Strings for easier work
Constants§
Traits§
Functions§
- add commit message to Unreleased in RELEASES.md
- auto_cargo_toml_to_md
- I want html pages to be correct microXML when I use them for single page application. Before build or release this function will check for correctness.
- deletes old js snippets when working with wasm-pack
The old folders forjs snippets
are not automatically deleted on building withwasm-pack
.
This utils do that.
The function must be executed in the root project folder where is the Cargo.toml. - The HTML generated by
cargo doc
is ugly and difficult togit diff
tidy HTML is a HTML checker and formatter installed on most Linuxes. If it is not installed run:sudo apt install -y tidy
From the bash you can install it inside the podman container like this:podman exec --user root rust_dev_vscode_cnt apt install -y tidy
- auto_lines_of_code
- auto_md_to_doc_comments
- process plantuml in current directory finds markers (auto_plantuml start) and (auto_plantuml end) in md files if needed calls the web service and saves the svg file Between markers adds the link to the svg file repo_url like https://github.com/bestia-dev/sey_currency_converter_pwa so the image file link is from the repository and accessible everywhere
- process plantuml for all md files for test and examples I need to provide the path
- process code for playground for Rust code segments in all md files
- Increments the minor version in Cargo.toml file only if files are changed
- Increments the minor version in Cargo.toml file even if files are not changed
- Increments the patch version in Cargo.toml file only if files are changed
- Increments the patch version in Cargo.toml file even if files are not changed
- auto_version_from_date
- Works for single projects and workspaces.
Just like auto_version_from_date(), but force the new version even if no files are changed. For workspacesrelease
I want to have the same version in all members.
It is slower, but easier to understand when deployed. - increments the version in Cargo.toml. if the major version is greater than 2000, it is a date version else it is semver and increments the patch part
- increments the version in Cargo.toml. if the major version is greater than 2000, it is a date version forced is used in workspaces to force all members to have the same date version else it is semver and increments the patch part
- First, the user must write the content into file RELEASES.md in the section ## Unreleased. Then the automation task will copy the content to GitHub release and create a new Version title in RELEASES.md.
- println one, more or all sub_commands
- the original
concat()
function does not have a delimiter - copy all files from the folder into a module as strings (static &str) the module has the markers: region: files copied into strings by automation tasks and endregion: the string will be in a vector with the file name first we create the complete text, then we check if the old text needs to be replaced ext_for_binary_files=vec![“.ico”,“.jpg”,“.png”,“.woff2”]; exclude_big_folders = vec![“/.git”,“/target”,“/docs”];
- Check and modify the description and topics on Github The words topics, keywords and tags all mean the same concept. In cargo.toml we have keywords. In README.md I want to have badges for tags In GitHub they are topics. Topic must be only one word: lowercase letters, hyphens(-) or numbers, less then 35 characters.
- check if run in rust project root directory error there must be Cargo.toml and the directory automation_tasks_rs exit with error message if not
- find from_pos
- return the position of end of the delimited data before the delimiter
- return the position of start of the delimited data after the delimiter
- has git remote
- check if this folder is a local Git repository
- sync, check, create, push git tag
- create new release on Github
return release_id
https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token - upload asset to github release
release_upload_url example: https://uploads.github.com/repos/owner/repo/releases/48127727/assets
https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token
async function can be called from sync code: - home_dir() using the home crate. panics if HOME not found
- init repository if needed. A new local git repository and remote GitHub repository.
- the UTC date in iso standard 2024-12-31
- run one shell command Stops task execution if the command has Exit Status != 0
- run one shell command and return ShellOutput {exit_status,stdout,stderr}
- run one shell command and return true if success
- run shell commands from a vector of strings. Stops task execution if oe of the commands has Exit Status != 0
- traverse_dir_with_exclude_dir
Type Aliases§
- for easier writing the returning type, that is mostly Result<> type for result with fixed LibError using thiserror