Skip to content

Commit e2273aa

Browse files
alejnpCopilot
andauthored
CON-370: Initial migration to Github (#1)
* Add fallback mechanism for `build.rs`. Also, add support for latest Github version * Update Coverage plugin in CI * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 431c55b commit e2273aa

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

CONNECTOR_VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
latest

build.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,27 @@ impl LibraryProvisioner {
100100
const VERSION_ENV: &str = "RTI_CONNECTOR_VERSION";
101101
const DIR_ENV: &str = "RTI_CONNECTOR_DIR";
102102
const CARGO_ENV: &str = "CARGO_MANIFEST_DIR";
103+
const VERSION_FILE: &str =
104+
concat!(env!("CARGO_MANIFEST_DIR"), "/CONNECTOR_VERSION");
103105

104106
println!("cargo:rerun-if-env-changed={}", VERSION_ENV);
105107
println!("cargo:rerun-if-env-changed={}", DIR_ENV);
106108

107109
if let Ok(version) = env::var(VERSION_ENV) {
110+
/*
111+
* First choice:
112+
* Use version specified in RTI_CONNECTOR_VERSION to fetch from GitHub releases.
113+
*/
108114
Ok(LibraryProvisioner::GitHub(GitHubSource::new(version)))
109115
} else if let Some(connector_lib_dir) = env::var(DIR_ENV)
110116
.ok()
111117
.map(PathBuf::from)
112118
.filter(|path| path.exists() && path.is_dir())
113119
{
120+
/*
121+
* Second choice:
122+
* Use local directory specified in RTI_CONNECTOR_DIR.
123+
*/
114124
println!("cargo:rerun-if-changed={}", connector_lib_dir.display());
115125
Ok(LibraryProvisioner::Directory(DirectorySource::new(
116126
connector_lib_dir,
@@ -120,14 +130,32 @@ impl LibraryProvisioner {
120130
.map(|path_str| PathBuf::from(path_str).join(LIB_DIR_NAME))
121131
.filter(|path| path.exists() && path.is_dir())
122132
{
133+
/*
134+
* Third choice:
135+
* Use 'rticonnextdds-connector' directory in the Cargo manifest directory.
136+
*/
123137
println!("cargo:rerun-if-changed={}", manifest_lib_dir.display());
124138
Ok(LibraryProvisioner::Directory(DirectorySource::new(
125139
manifest_lib_dir,
126140
)))
141+
} else if let Some(version) = std::fs::read_to_string(VERSION_FILE)
142+
.ok()
143+
.map(|s| s.trim().to_string())
144+
.filter(|s| !s.is_empty())
145+
{
146+
/*
147+
* Fallback:
148+
* Use version specified in VERSION file to fetch from GitHub releases.
149+
*/
150+
println!("cargo:rerun-if-changed={}", VERSION_FILE);
151+
Ok(LibraryProvisioner::GitHub(GitHubSource::new(version)))
127152
} else {
153+
/*
154+
* Error scenario: VERSION file does not exist, cannot be read, or is empty after trimming.
155+
*/
128156
Err(format!(
129-
"Environment variables {} and {} unset. {} doesn't contain native libraries.",
130-
VERSION_ENV, DIR_ENV, CARGO_ENV
157+
"Environment variables {} and {} unset. {} doesn't contain native libraries. The file '{}' does not exist or is invalid.",
158+
VERSION_ENV, DIR_ENV, CARGO_ENV, VERSION_FILE
131159
))
132160
}
133161
}
@@ -162,18 +190,21 @@ impl GitHubSource {
162190
}
163191

164192
fn fetch_release_asset_url(&self) -> Result<String> {
165-
let release_tag = format!("v{}", self.version);
166-
let release_url = format!("{}/releases/tags/{}", self.api_root_uri, &release_tag);
193+
let release_url = if self.version == "latest" {
194+
format!("{}/releases/latest", self.api_root_uri)
195+
} else {
196+
format!("{}/releases/tags/v{}", self.api_root_uri, self.version)
197+
};
167198
let release_json = ureq::get(&release_url)
168199
.header("Accept", "application/vnd.github+json")
169200
.call()
170201
.map_err(|e| {
171-
format!("Failed to fetch '{}' release info: {}", release_tag, e)
202+
format!("Failed to fetch '{}' release info: {}", self.version, e)
172203
})?
173204
.into_body()
174205
.read_to_string()
175206
.map_err(|e| {
176-
format!("Failed to read '{}' release info: {}", release_tag, e)
207+
format!("Failed to read '{}' release info: {}", self.version, e)
177208
})?;
178209

179210
#[derive(Debug, serde::Deserialize)]

resources/jenkins/build_and_test.groovy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ def getBuildAndTestStages(String rustVersion) {
119119
}
120120
}
121121

122-
publishCoverage adapters: [
123-
coberturaAdapter('tarpaulin-report/cobertura.xml')
122+
recordCoverage tools: [
123+
[
124+
parser: 'COBERTURA',
125+
pattern: 'tarpaulin-report/cobertura.xml'
126+
],
124127
]
125128

126129
publishHTML(target: [

0 commit comments

Comments
 (0)