|
|
… |
133 unchanged lines |
| 134 |
134 |
|
let _ = std::fs::remove_dir_all(&scratch); |
| 135 |
135 |
|
std::fs::create_dir_all(scratch.join("tree"))?; |
| 136 |
136 |
|
let result = (|| -> Result<Finish> { |
| 137 |
|
- |
let files = workspace::export_state(&repo, &heads, &scratch.join("tree"))?; |
|
137 |
+ |
let mut files = workspace::export_state(&repo, &heads, &scratch.join("tree"))?; |
|
138 |
+ |
// Pinned subrepos (Oxygen spec §7.8), at their paths, as part of the |
|
139 |
+ |
// workspace and of the scope hash. |
|
140 |
+ |
for sub in &claim.subrepos { |
|
141 |
+ |
if sub.path.split('/').any(|p| p.is_empty() || p == "." || p == ".." || p == ".oxy") { |
|
142 |
+ |
bail!("subrepo path {:?} is not a clean relative path", sub.path); |
|
143 |
+ |
} |
|
144 |
+ |
note( |
|
145 |
+ |
&mut sink, |
|
146 |
+ |
format!( |
|
147 |
+ |
"fetching subrepo {} at {} for {}", |
|
148 |
+ |
sub.repo, |
|
149 |
+ |
sub.heads.iter().map(|h| &h[..12]).collect::<Vec<_>>().join("+"), |
|
150 |
+ |
sub.path |
|
151 |
+ |
), |
|
152 |
+ |
); |
|
153 |
+ |
let sub_repo = cached_repo_at(home, cfg, &sub.repo, &sub.clone_url, &claim.token)?; |
|
154 |
+ |
let sub_heads: Vec<ChangeHash> = |
|
155 |
+ |
sub.heads.iter().map(|h| ChangeHash::from_hex(h).context("bad subrepo head")).collect::<Result<_>>()?; |
|
156 |
+ |
let dir = scratch.join("tree").join(&sub.path); |
|
157 |
+ |
std::fs::create_dir_all(&dir)?; |
|
158 |
+ |
let sub_files = workspace::export_state(&sub_repo, &sub_heads, &dir)?; |
|
159 |
+ |
files.extend(sub_files.into_iter().map(|(p, h)| (format!("{}/{p}", sub.path), h))); |
|
160 |
+ |
} |
| 138 |
161 |
|
let scope_hash = scope_tree_hash(&claim.job.scope, files.iter().map(|(p, h)| (p.as_str(), *h))); |
| 139 |
162 |
|
workspace::image(&scratch.join("tree"), &scratch.join("workspace.ext4"))?; |
| 140 |
163 |
|
std::fs::remove_dir_all(scratch.join("tree"))?; |
|
|
… |
49 unchanged lines |
| 190 |
213 |
|
|
| 191 |
214 |
|
/// The runner's copy of a repository, fetched up to date with the job's token. |
| 192 |
215 |
|
fn cached_repo(home: &Home, cfg: &RunnerConfig, claim: &Claim) -> Result<Repo> { |
| 193 |
|
- |
let dir: PathBuf = home.root.join("repos").join(claim.repo.replace('/', "__")); |
|
216 |
+ |
cached_repo_at(home, cfg, &claim.repo, &claim.clone_url, &claim.token) |
|
217 |
+ |
} |
|
218 |
+ |
|
|
219 |
+ |
/// The runner's copy of `repo`, cloned or fetched with `token`. |
|
220 |
+ |
fn cached_repo_at(home: &Home, cfg: &RunnerConfig, repo_name: &str, clone_url: &str, token: &str) -> Result<Repo> { |
|
221 |
+ |
let dir: PathBuf = home.root.join("repos").join(repo_name.replace('/', "__")); |
| 194 |
222 |
|
let set_remote = |repo: &mut Repo| -> Result<()> { |
| 195 |
|
- |
repo.config.set("remote.origin.url", &claim.clone_url).map_err(|e| anyhow::anyhow!("{e}"))?; |
| 196 |
|
- |
repo.config.set("remote.origin.token", &claim.token).map_err(|e| anyhow::anyhow!("{e}"))?; |
|
223 |
+ |
repo.config.set("remote.origin.url", clone_url).map_err(|e| anyhow::anyhow!("{e}"))?; |
|
224 |
+ |
repo.config.set("remote.origin.token", token).map_err(|e| anyhow::anyhow!("{e}"))?; |
| 197 |
225 |
|
if let Some(ca) = &cfg.ca { |
| 198 |
226 |
|
repo.config.set("remote.origin.ca", &ca.to_string_lossy()).map_err(|e| anyhow::anyhow!("{e}"))?; |
| 199 |
227 |
|
} |
|
|
… |
2 unchanged lines |
| 202 |
230 |
|
if dir.join(".oxy").is_dir() { |
| 203 |
231 |
|
let mut repo = Repo::open(&dir).map_err(|e| anyhow::anyhow!("{e}"))?; |
| 204 |
232 |
|
set_remote(&mut repo)?; |
| 205 |
|
- |
repo.fetch("origin").map_err(|e| anyhow::anyhow!("fetch {}: {e}", claim.clone_url))?; |
|
233 |
+ |
repo.fetch("origin").map_err(|e| anyhow::anyhow!("fetch {clone_url}: {e}"))?; |
| 206 |
234 |
|
return Ok(repo); |
| 207 |
235 |
|
} |
| 208 |
236 |
|
// First job for this repository: clone with the job's token. |
| 209 |
|
- |
std::env::set_var("OXY_TOKEN", &claim.token); |
|
237 |
+ |
std::env::set_var("OXY_TOKEN", token); |
| 210 |
238 |
|
if let Some(ca) = &cfg.ca { |
| 211 |
239 |
|
std::env::set_var("OXY_CA", ca); |
| 212 |
240 |
|
} |
| 213 |
|
- |
let cloned = Repo::clone(&claim.clone_url, &dir); |
|
241 |
+ |
let cloned = Repo::clone(clone_url, &dir); |
| 214 |
242 |
|
std::env::remove_var("OXY_TOKEN"); |
| 215 |
243 |
|
std::env::remove_var("OXY_CA"); |
| 216 |
244 |
|
let mut repo = cloned.map_err(|e| { |
| 217 |
245 |
|
let _ = std::fs::remove_dir_all(&dir); |
| 218 |
|
- |
anyhow::anyhow!("clone {}: {e}", claim.clone_url) |
|
246 |
+ |
anyhow::anyhow!("clone {}: {e}", clone_url) |
| 219 |
247 |
|
})?; |
| 220 |
248 |
|
set_remote(&mut repo)?; |
| 221 |
249 |
|
Ok(repo) |
|
|
… |
1 unchanged lines |