Skip to content

Commit

Permalink
chore: include release cycle info in crate
Browse files Browse the repository at this point in the history
For some reason the `sn_build_info` crate started to manifest an error that it couldn't find the
`release-cycle-info` file. The solution was to embed the information in the crate. This is less than
ideal, because it now needs to be updated in two places. However, we could have the other parts of
the release process read the Rust file. We can do that later.
  • Loading branch information
jacderida committed Oct 22, 2024
1 parent 4890a3b commit 0d5e244
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 47 deletions.
1 change: 1 addition & 0 deletions sn_build_info/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ readme = "README.md"
repository = "https://github.com/maidsafe/safe_network"
version = "0.1.16"
build = "build.rs"
include = ["Cargo.toml", "src/**/*", "build.rs"]

[build-dependencies]
vergen = { version = "8.0.0", features = ["build", "git", "gitcl"] }
Expand Down
56 changes: 9 additions & 47 deletions sn_build_info/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,24 @@
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.
use std::fs;
use std::path::Path;
use vergen::EmitBuilder;

mod release_info {
include!("src/release_info.rs");
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
EmitBuilder::builder()
.build_date()
// Emit the short SHA-1 hash of the current commit
.git_sha(true)
// Emit the current branch name
.git_branch()
// Emit the annotated tag of the current commit, or fall back to abbreviated commit object.
.git_describe(true, false, None)
.emit()?;

let release_info_path = Path::new("../release-cycle-info");
let contents =
fs::read_to_string(release_info_path).expect("Failed to read release-cycle-info");

let mut year = String::new();
let mut month = String::new();
let mut cycle = String::new();
let mut counter = String::new();

for line in contents.lines() {
if line.starts_with("release-year:") {
year = line
.split(':')
.nth(1)
.map(|s| s.trim().to_string())
.unwrap_or_default();
} else if line.starts_with("release-month:") {
month = line
.split(':')
.nth(1)
.map(|s| s.trim().to_string())
.unwrap_or_default();
} else if line.starts_with("release-cycle:") {
cycle = line
.split(':')
.nth(1)
.map(|s| s.trim().to_string())
.unwrap_or_default();
} else if line.starts_with("release-cycle-counter:") {
counter = line
.split(':')
.nth(1)
.map(|s| s.trim().to_string())
.unwrap_or_default();
}
}

println!("cargo:rustc-env=RELEASE_YEAR={year}");
println!("cargo:rustc-env=RELEASE_MONTH={month}");
println!("cargo:rustc-env=RELEASE_CYCLE={cycle}");
println!("cargo:rustc-env=RELEASE_CYCLE_COUNTER={counter}");
println!("cargo:rustc-env=RELEASE_YEAR={}", release_info::RELEASE_YEAR);
println!("cargo:rustc-env=RELEASE_MONTH={}", release_info::RELEASE_MONTH);
println!("cargo:rustc-env=RELEASE_CYCLE={}", release_info::RELEASE_CYCLE);
println!("cargo:rustc-env=RELEASE_CYCLE_COUNTER={}", release_info::RELEASE_CYCLE_COUNTER);

Ok(())
}
}
4 changes: 4 additions & 0 deletions sn_build_info/src/release_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub const RELEASE_YEAR: &str = "2024";
pub const RELEASE_MONTH: &str = "10";
pub const RELEASE_CYCLE: &str = "3";
pub const RELEASE_CYCLE_COUNTER: &str = "2";

0 comments on commit 0d5e244

Please sign in to comment.