Skip to content

Commit 36f7921

Browse files
committed
wip
1 parent 0ac3c50 commit 36f7921

File tree

17 files changed

+310
-45
lines changed

17 files changed

+310
-45
lines changed

packages/cli/src/publish.rs

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,19 @@ impl Cli {
136136
items.push(Either::Right(item.referent.item.clone()));
137137
tags.push((item.tag.clone(), item.referent.item.clone()));
138138
}
139-
handle.put_tag(&item.tag, tg::tag::put::Arg {
140-
force: true,
141-
item: Either::Right(item.referent.item.clone()),
142-
remote: None,
143-
})
144-
.await
145-
.map_err(|source| tg::error!(!source, %tag = item.tag, %package = item.referent, "failed to put the tag"))?;
139+
handle
140+
.put_tag(
141+
&item.tag,
142+
tg::tag::put::Arg {
143+
force: true,
144+
item: Either::Right(item.referent.item().clone()),
145+
remote: None,
146+
},
147+
)
148+
.await
149+
.map_err(
150+
|source| tg::error!(!source, %tag = item.tag, "failed to put local tag"),
151+
)?;
146152
}
147153

148154
// Get the remote.
@@ -167,22 +173,25 @@ impl Cli {
167173
eprintln!("pushed {} objects to remote {remote:?}", output.objects);
168174

169175
// Put tags on the remote.
170-
let count = tags.len();
171-
for (tag, item) in tags {
172-
eprintln!("published {tag} {item}");
173-
handle
174-
.put_tag(
175-
&tag,
176-
tg::tag::put::Arg {
177-
item: Either::Right(item),
178-
force: false,
179-
remote: Some(remote.clone()),
180-
},
181-
)
182-
.await
183-
.map_err(|source| tg::error!(!source, %tag, "failed to put tag on remote"))?;
176+
let tags = tags
177+
.into_iter()
178+
.map(|(tag, item)| tg::tag::post::Item {
179+
tag,
180+
item: Either::Right(item),
181+
force: false,
182+
})
183+
.collect::<Vec<_>>();
184+
handle
185+
.post_tags_batch(tg::tag::post::Arg {
186+
remote: Some(remote.clone()),
187+
tags: tags.clone(),
188+
})
189+
.await
190+
.map_err(|source| tg::error!(!source, "failed to publish tags to remote"))?;
191+
for item in &tags {
192+
eprintln!("published {} {}", item.tag, item.item);
184193
}
185-
eprintln!("published {count} packages to remote {remote:?}");
194+
eprintln!("published {} packages to remote {remote:?}", tags.len());
186195
Ok(())
187196
}
188197
}
@@ -247,7 +256,9 @@ async fn try_get_package_tag(
247256
executable: Some(executable),
248257
..Default::default()
249258
};
250-
let output = tg::run::run(handle, arg).await?;
259+
let Ok(output) = tg::run::run(handle, arg).await else {
260+
return Ok(None);
261+
};
251262
let map = output
252263
.try_unwrap_map()
253264
.map_err(|_| tg::error!("expected metadata to be a map"))?;

packages/cli/tests/publish.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,6 @@ async fn package_with_local_path_import() {
633633
// Verify publish order by checking stderr output.
634634
let stderr = String::from_utf8_lossy(&publish_output.stderr);
635635

636-
// Extract the positions where each package appears in the output.
637-
let dep_pos = stderr.find("published test-dep/1.0.0");
638-
let main_pos = stderr.find("published test-main/1.0.0");
639-
640-
// Both packages should be published.
641-
assert!(dep_pos.is_some(), "test-dep should be published");
642-
assert!(main_pos.is_some(), "test-main should be published");
643-
644636
// Extract the published artifact IDs from the stderr output.
645637
// Since packages with local path dependencies are re-checked-in, the published IDs
646638
// may differ from the original checkin IDs.

packages/client/src/handle.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ pub trait Tag: Clone + Unpin + Send + Sync + 'static {
398398
arg: tg::tag::put::Arg,
399399
) -> impl Future<Output = tg::Result<()>> + Send;
400400

401+
fn post_tags_batch(
402+
&self,
403+
arg: tg::tag::post::Arg,
404+
) -> impl Future<Output = tg::Result<()>> + Send;
405+
401406
fn delete_tag(
402407
&self,
403408
arg: tg::tag::delete::Arg,
@@ -900,6 +905,13 @@ impl tg::handle::Tag for tg::Client {
900905
self.put_tag(tag, arg)
901906
}
902907

908+
fn post_tags_batch(
909+
&self,
910+
arg: crate::tag::post::Arg,
911+
) -> impl Future<Output = tg::Result<()>> + Send {
912+
self.post_tags_batch(arg)
913+
}
914+
903915
fn delete_tag(
904916
&self,
905917
arg: tg::tag::delete::Arg,

packages/client/src/handle/dynamic.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ impl tg::handle::Tag for Handle {
546546
unsafe { std::mem::transmute::<_, BoxFuture<'_, _>>(self.0.put_tag(tag, arg)) }
547547
}
548548

549+
fn post_tags_batch(&self, arg: tg::tag::post::Arg) -> impl Future<Output = tg::Result<()>> {
550+
unsafe { std::mem::transmute::<_, BoxFuture<'_, _>>(self.0.post_tags_batch(arg)) }
551+
}
552+
549553
fn delete_tag(
550554
&self,
551555
arg: tg::tag::delete::Arg,

packages/client/src/handle/either.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,13 @@ where
795795
}
796796
}
797797

798+
fn post_tags_batch(&self, arg: tg::tag::post::Arg) -> impl Future<Output = tg::Result<()>> {
799+
match self {
800+
Either::Left(s) => s.post_tags_batch(arg).left_future(),
801+
Either::Right(s) => s.post_tags_batch(arg).right_future(),
802+
}
803+
}
804+
798805
fn delete_tag(
799806
&self,
800807
arg: tg::tag::delete::Arg,

packages/client/src/handle/erased.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ pub trait Tag: Send + Sync + 'static {
345345
arg: tg::tag::put::Arg,
346346
) -> BoxFuture<'a, tg::Result<()>>;
347347

348+
fn post_tags_batch<'a>(&'a self, arg: tg::tag::post::Arg) -> BoxFuture<'a, tg::Result<()>>;
349+
348350
fn delete_tag(
349351
&self,
350352
arg: tg::tag::delete::Arg,
@@ -848,6 +850,10 @@ where
848850
self.put_tag(tag, arg).boxed()
849851
}
850852

853+
fn post_tags_batch<'a>(&'a self, arg: tg::tag::post::Arg) -> BoxFuture<'a, tg::Result<()>> {
854+
self.post_tags_batch(arg).boxed()
855+
}
856+
851857
fn delete_tag(
852858
&self,
853859
arg: tg::tag::delete::Arg,

packages/client/src/tag.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod delete;
44
pub mod get;
55
pub mod list;
66
pub mod pattern;
7+
pub mod post;
78
pub mod put;
89

910
pub use self::pattern::Pattern;

packages/client/src/tag/post.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use {
2+
crate as tg,
3+
tangram_either::Either,
4+
tangram_http::{request::builder::Ext as _, response::Ext as _},
5+
tangram_util::serde::is_false,
6+
};
7+
8+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
9+
pub struct Arg {
10+
pub tags: Vec<Item>,
11+
12+
#[serde(default, skip_serializing_if = "Option::is_none")]
13+
pub remote: Option<String>,
14+
}
15+
16+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
17+
pub struct Item {
18+
#[serde(default, skip_serializing_if = "is_false")]
19+
pub force: bool,
20+
pub tag: tg::Tag,
21+
pub item: Either<tg::process::Id, tg::object::Id>,
22+
}
23+
24+
impl tg::Client {
25+
pub async fn post_tags_batch(&self, arg: Arg) -> tg::Result<()> {
26+
let method = http::Method::POST;
27+
let uri = format!("/tags/batch");
28+
let request = http::request::Builder::default()
29+
.method(method)
30+
.uri(uri)
31+
.json(&arg)
32+
.map_err(|source| tg::error!(!source, "failed to serialize the arg"))?
33+
.unwrap();
34+
let response = self.send(request).await
35+
.map_err(|source| tg::error!(!source, "failed to send the request"))?;
36+
if !response.status().is_success() {
37+
let error = response.json().await?;
38+
return Err(error);
39+
}
40+
Ok(())
41+
}
42+
}

packages/module/src/resolve.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ where
283283
tg::Object::Directory(directory),
284284
) => {
285285
let path =
286-
tg::package::try_get_root_module_file_name(handle, Either::Left(directory))
287-
.await?;
286+
tg::package::try_get_root_module_file_name(handle, Either::Left(directory)).await?;
288287
let (item, path) = if let Some(path) = path {
289288
let file = directory
290289
.get(handle, path)

packages/server/src/handle.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,13 @@ impl tg::handle::Tag for Handle {
497497
self.0.put_tag(tag, arg)
498498
}
499499

500+
fn post_tags_batch(
501+
&self,
502+
arg: tg::tag::post::Arg,
503+
) -> impl Future<Output = tg::Result<()>> + Send {
504+
self.0.post_tags_batch(arg)
505+
}
506+
500507
fn delete_tag(
501508
&self,
502509
arg: tg::tag::delete::Arg,
@@ -1003,6 +1010,10 @@ impl tg::handle::Tag for Server {
10031010
self.put_tag(tag, arg)
10041011
}
10051012

1013+
fn post_tags_batch(&self, arg: tg::tag::post::Arg) -> impl Future<Output = tg::Result<()>> {
1014+
self.post_tags_batch(arg)
1015+
}
1016+
10061017
fn delete_tag(
10071018
&self,
10081019
arg: tg::tag::delete::Arg,

0 commit comments

Comments
 (0)