Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sunsided/dotnet-gitversion-rs
dotnet-gitversion for Rust builds
https://github.com/sunsided/dotnet-gitversion-rs
dotnet gitversion rust semver
Last synced: 2 months ago
JSON representation
dotnet-gitversion for Rust builds
- Host: GitHub
- URL: https://github.com/sunsided/dotnet-gitversion-rs
- Owner: sunsided
- License: mit
- Created: 2021-06-19T21:24:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-28T09:51:02.000Z (11 months ago)
- Last Synced: 2024-10-11T02:29:49.318Z (3 months ago)
- Topics: dotnet, gitversion, rust, semver
- Language: Rust
- Homepage: https://crates.io/crates/dotnet-gitversion-build
- Size: 32.2 KB
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# dotnet-gitversion for Rust builds
This project provides a build-time wrapper to [GitTools/GitVersion]
that embeds [Semantic Version] information obtained
from the current repository state.## Prerequisites
This library requires both the [.NET runtime] (e.g. .NET 5)
and the [GitVersion.Tool] package to be installed globally, e.g.```console
$ dotnet tool install --global GitVersion.Tool --version 5.6.10
```You can verify the installation by calling either
```console
$ dotnet gitversion
$ dotnet-gitversion
```**Note that a `GitVersion.yml` configuration file might be required in your repo.**
See the [GitVersion.yml](GitVersion.yml) of this project for an example.## Usage
Add `dotnet-gitversion` to your build dependencies:
```toml
[build-dependencies]
dotnet-gitversion-build = "0.3.0"
```Create or update your `build.rs` to call `dotnet_gitversion_build::build()`.
This method populates various `GITVERSION_` environment variables to be used with the `env!` macro,
creates the `gitversion.rs` file in the `OUT_DIR` directory
and additionally returns the intermediate representation:```rust
fn main() -> Result<(), Box> {
let _gv = dotnet_gitversion_build::build()?;
Ok(())
}
```The `GITVERSION_...` environment variables can be used immediately:
```rust
fn main() {
// Use the build-generated environment variables.
println!("Info version: {}", env!("GITVERSION_INFORMATIONAL_VERSION"));
println!("Full SemVer: {}", env!("GITVERSION_FULL_SEMVER"));
}
```Example output of the above code:
```text
Info version: 0.2.0+Branch.main.Sha.645a21e7b6358e9b72978a1b46cbd6c55a85a9af
Full SemVer: 0.2.0
```After including the generated `gitversion.rs` file you will additionally have access
to the static `GIT_VERSION` constant and the `GitVersion` struct:```rust
include!(concat!(env!("OUT_DIR"), "/gitversion.rs"));fn main() {
// Use the "global" constant.
println!("Display: {}", GIT_VERSION);
println!("Debug: {:?}", GIT_VERSION);
println!("SHA: {}", GIT_VERSION.sha);
println!("Commit: {}", GIT_VERSION.commit_date);// The GitVersion::new() function allows you to obtain
// the struct as a constant.
const GV: GitVersion = GitVersion::new();
println!("Branch name: {}", GV.branch_name);// Alternatively you can use the Default trait to obtain a new instance.
let gv = GitVersion::default();
println!("Short commit: {}", gv.short_sha);
}
```Example output of the above code:
```text
Display: 0.2.0
Debug: 0.2.0+Branch.main.Sha.2e3c96c6dbd30a0ca25e51d2fb10982042670a46
SHA: 2e3c96c6dbd30a0ca25e51d2fb10982042670a46
Commit: 2021-06-20
Branch name: main
Short commit: 2e3c96c
```The imported `GitVersion` struct itself is defined as shown below. Please
see [GitTools/GitVersion](https://github.com/GitTools/GitVersion) for
documentation on the field values or run `dotnet gitversion`.
The environment variables names are generated with a `GITVERSION_` prefix followed
by the filed names, e.g. `GITVERSION_MAJOR_MINOR_PATCH`.```rust
pub struct GitVersion {
pub major: u32,
pub minor: u32,
pub patch: u32,
pub pre_release_tag: &'static str,
pub pre_release_tag_with_dash: &'static str,
pub pre_release_label: &'static str,
pub pre_release_label_with_dash: &'static str,
pub pre_release_number: Option,
pub weighted_pre_release_number: u32,
pub build_meta_data: Option,
pub build_meta_data_padded: &'static str,
pub full_build_meta_data: &'static str,
pub major_minor_patch: &'static str,
pub semver: &'static str,
#[deprecated]
pub legacy_semver: &'static str,
#[deprecated]
pub legacy_semver_padded: &'static str,
pub assembly_semver: &'static str,
pub assembly_sem_file_version: &'static str,
pub informational_version: &'static str,
pub branch_name: &'static str,
pub escaped_branch_name: &'static str,
pub sha: &'static str,
pub short_sha: &'static str,
#[deprecated]
pub nuget_version_v2: &'static str,
#[deprecated]
pub nuget_version: &'static str,
#[deprecated]
pub nuget_prerelease_tag_v2: &'static str,
#[deprecated]
pub nuget_prerelease_tag: &'static str,
pub version_source_sha: &'static str,
pub commits_since_version_source: u32,
pub commits_since_version_source_padded: &'static str,
pub uncommitted_changes: u32,
pub commit_date: &'static str,
}
```[GitTools/GitVersion]: https://github.com/GitTools/GitVersion
[Semantic Version]: http://semver.org/
[GitVersion.Tool]: https://www.nuget.org/packages/GitVersion.Tool/
[.NET runtime]: https://dot.net/