🔥 remove: local release builds (release.rs, podman/xwin orchestration, build card, job rows, status chip, release.source setting); ✨ feat: Builder › Releases imports a forge release by tag: the server downloads the assets in the background from its configured forge (server_config forge = <repo url>, optional forge_token), checks each against forge's sha256 and stages them, then Event::Imported fills the drafts; publish picks Server, Client or Both. ALPN yumush/7. CI: shader bytes move to ci/, no .sha256 assets (forge reports sha256)
Browse files at this commit40db0e6882b5c648e768608102ce77c15f2cede5Parent: 3ac1c5626 changed files +389 -1325
- .forge/ci.toml +2 -2
- Cargo.lock +34 -0
- ci/build.sh +3 -4
- crates/client/src/release/shaders.sha256 → ci/shaders.sha256 +0 -0
- crates/client/src/release/shaders_bytes.rs → ci/shaders_bytes.rs +0 -0
- configs/server_config.example.toml +2 -0
- crates/client/lang/en/builder_release.txt +4 -20
- crates/client/lang/tr/builder_release.txt +4 -20
- crates/client/src/gui.rs +5 -6
- crates/client/src/gui/builder/releases.rs +141 -740
- crates/client/src/gui/chat.rs +4 -1
- crates/client/src/gui/sidebar.rs +0 -1
- crates/client/src/lib.rs +0 -1
- crates/client/src/release.rs +0 -511
- crates/client/src/settings.rs +1 -12
- crates/client/src/update.rs +0 -4
- crates/common/src/call.rs +6 -0
- crates/common/src/error.rs +6 -0
- crates/common/src/event.rs +4 -0
- crates/common/src/transport.rs +1 -1
- crates/server/Cargo.toml +2 -0
- crates/server/src/call/mod.rs +1 -0
- crates/server/src/call/release.rs +27 -1
- crates/server/src/forge.rs +89 -0
- crates/server/src/lib.rs +9 -0
- crates/server/src/update.rs +44 -1
.forge/ci.tomlmodified+2 -2
| @@ -8,10 +8,10 @@ manual = true | |||
| 8 | image = "docker.io/library/ubuntu:24.04" | 8 | image = "docker.io/library/ubuntu:24.04" |
| 9 | run = "bash ci/build.sh \"$MATRIX_TARGET\"" | 9 | run = "bash ci/build.sh \"$MATRIX_TARGET\"" |
| 10 | matrix = { target = ["server-x86_64-linux", "x86_64_v1-linux", "x86_64_v3-linux", "x86_64_v1-windows", "x86_64_v3-windows"] } | 10 | matrix = { target = ["server-x86_64-linux", "x86_64_v1-linux", "x86_64_v3-linux", "x86_64_v1-windows", "x86_64_v3-windows"] } |
| 11 | -artifacts = ["server-x86_64-linux*", "x86_64_*"] | 11 | +artifacts = ["server-x86_64-linux", "x86_64_*"] |
| 12 | cache = [".cargo-home", ".rustup", "target"] | 12 | cache = [".cargo-home", ".rustup", "target"] |
| 13 | timeout_minutes = 180 | 13 | timeout_minutes = 180 |
| 14 | 14 | ||
| 15 | [release] | 15 | [release] |
| 16 | -assets = ["build:server-x86_64-linux*", "build:x86_64_*"] | 16 | +assets = ["build:server-x86_64-linux", "build:x86_64_*"] |
| 17 | notes = "commits" | 17 | notes = "commits" |
Cargo.lockmodified+34 -0
| @@ -1488,12 +1488,41 @@ dependencies = [ | |||
| 1488 | "unicode-segmentation", | 1488 | "unicode-segmentation", |
| 1489 | ] | 1489 | ] |
| 1490 | 1490 | ||
| 1491 | +[[package]] | ||
| 1492 | +name = "cookie" | ||
| 1493 | +version = "0.18.3" | ||
| 1494 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1495 | +checksum = "d55f2d6c30eeec7d5c6f98bd4395d4abb1895629eab97ee6522d340623615f8a" | ||
| 1496 | +dependencies = [ | ||
| 1497 | + "percent-encoding", | ||
| 1498 | + "time", | ||
| 1499 | + "version_check", | ||
| 1500 | +] | ||
| 1501 | + | ||
| 1491 | [[package]] | 1502 | [[package]] |
| 1492 | name = "cookie-factory" | 1503 | name = "cookie-factory" |
| 1493 | version = "0.3.3" | 1504 | version = "0.3.3" |
| 1494 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1505 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1495 | checksum = "9885fa71e26b8ab7855e2ec7cae6e9b380edff76cd052e07c683a0319d51b3a2" | 1506 | checksum = "9885fa71e26b8ab7855e2ec7cae6e9b380edff76cd052e07c683a0319d51b3a2" |
| 1496 | 1507 | ||
| 1508 | +[[package]] | ||
| 1509 | +name = "cookie_store" | ||
| 1510 | +version = "0.22.1" | ||
| 1511 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1512 | +checksum = "15b2c103cf610ec6cae3da84a766285b42fd16aad564758459e6ecf128c75206" | ||
| 1513 | +dependencies = [ | ||
| 1514 | + "cookie", | ||
| 1515 | + "document-features", | ||
| 1516 | + "idna", | ||
| 1517 | + "indexmap", | ||
| 1518 | + "log", | ||
| 1519 | + "serde", | ||
| 1520 | + "serde_derive", | ||
| 1521 | + "serde_json", | ||
| 1522 | + "time", | ||
| 1523 | + "url", | ||
| 1524 | +] | ||
| 1525 | + | ||
| 1497 | [[package]] | 1526 | [[package]] |
| 1498 | name = "core-foundation" | 1527 | name = "core-foundation" |
| 1499 | version = "0.7.0" | 1528 | version = "0.7.0" |
| @@ -8350,12 +8379,14 @@ dependencies = [ | |||
| 8350 | "quinn", | 8379 | "quinn", |
| 8351 | "rcgen", | 8380 | "rcgen", |
| 8352 | "rustls", | 8381 | "rustls", |
| 8382 | + "serde", | ||
| 8353 | "sha2 0.11.2", | 8383 | "sha2 0.11.2", |
| 8354 | "thiserror 2.0.21", | 8384 | "thiserror 2.0.21", |
| 8355 | "tokio", | 8385 | "tokio", |
| 8356 | "tracing", | 8386 | "tracing", |
| 8357 | "tracing-subscriber", | 8387 | "tracing-subscriber", |
| 8358 | "turso", | 8388 | "turso", |
| 8389 | + "ureq", | ||
| 8359 | "usage", | 8390 | "usage", |
| 8360 | "zstd", | 8391 | "zstd", |
| 8361 | ] | 8392 | ] |
| @@ -9810,11 +9841,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 9810 | checksum = "3ac5cecf619ca81f66a96482db09687c9f7465af65f4300a8c30cca05bd5a59d" | 9841 | checksum = "3ac5cecf619ca81f66a96482db09687c9f7465af65f4300a8c30cca05bd5a59d" |
| 9811 | dependencies = [ | 9842 | dependencies = [ |
| 9812 | "base64 0.23.1", | 9843 | "base64 0.23.1", |
| 9844 | + "cookie_store", | ||
| 9813 | "flate2", | 9845 | "flate2", |
| 9814 | "log", | 9846 | "log", |
| 9815 | "percent-encoding", | 9847 | "percent-encoding", |
| 9816 | "rustls", | 9848 | "rustls", |
| 9817 | "rustls-pki-types", | 9849 | "rustls-pki-types", |
| 9850 | + "serde", | ||
| 9851 | + "serde_json", | ||
| 9818 | "ureq-proto", | 9852 | "ureq-proto", |
| 9819 | "utf8-zero", | 9853 | "utf8-zero", |
| 9820 | "webpki-roots", | 9854 | "webpki-roots", |
ci/build.shmodified+3 -4
| @@ -42,8 +42,8 @@ echo "::endgroup::" | |||
| 42 | 42 | ||
| 43 | echo "::group::Build" | 43 | echo "::group::Build" |
| 44 | if [ "$os" = windows ]; then | 44 | if [ "$os" = windows ]; then |
| 45 | - sha256sum -c --quiet crates/client/src/release/shaders.sha256 | 45 | + sha256sum -c --quiet ci/shaders.sha256 |
| 46 | - export XWIN_ACCEPT_LICENSE=1 XWIN_CACHE_DIR="$CARGO_HOME/xwin" GPUI_SHADERS_BYTES="$PWD/crates/client/src/release/shaders_bytes.rs" | 46 | + export XWIN_ACCEPT_LICENSE=1 XWIN_CACHE_DIR="$CARGO_HOME/xwin" GPUI_SHADERS_BYTES="$PWD/ci/shaders_bytes.rs" |
| 47 | export CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS="-C target-cpu=$cpu" | 47 | export CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS="-C target-cpu=$cpu" |
| 48 | cargo xwin build --release -p client --target "$windows" --target-dir "target/$level" | 48 | cargo xwin build --release -p client --target "$windows" --target-dir "target/$level" |
| 49 | built="target/$level/$windows/release/client.exe" | 49 | built="target/$level/$windows/release/client.exe" |
| @@ -56,6 +56,5 @@ echo "::endgroup::" | |||
| 56 | 56 | ||
| 57 | echo "::group::Package" | 57 | echo "::group::Package" |
| 58 | cp "$built" "$target" | 58 | cp "$built" "$target" |
| 59 | -sha256sum "$target" > "$target.sha256" | 59 | +sha256sum "$target" |
| 60 | -cat "$target.sha256" | ||
| 61 | echo "::endgroup::" | 60 | echo "::endgroup::" |
crates/client/src/release/shaders.sha256 → ci/shaders.sha256renamed+0 -0
crates/client/src/release/shaders_bytes.rs → ci/shaders_bytes.rsrenamed+0 -0
configs/server_config.example.tomlmodified+2 -0
| @@ -3,3 +3,5 @@ database_path = "yumush.db" | |||
| 3 | server_address = "127.0.0.1:2026" | 3 | server_address = "127.0.0.1:2026" |
| 4 | certificate_path = "fullchain.pem" | 4 | certificate_path = "fullchain.pem" |
| 5 | key_path = "privkey.pem" | 5 | key_path = "privkey.pem" |
| 6 | +# forge = "https://git.tahinli.com/Tahinli/yumush" | ||
| 7 | +# forge_token = "" | ||
crates/client/lang/en/builder_release.txtmodified+4 -20
| @@ -6,28 +6,12 @@ required = Required | |||
| 6 | publish = Publish | 6 | publish = Publish |
| 7 | confirm = Confirm | 7 | confirm = Confirm |
| 8 | no_releases = No releases | 8 | no_releases = No releases |
| 9 | -choose_source = Choose source | ||
| 10 | -no_source = No source folder | ||
| 11 | -not_source = Not a release source | ||
| 12 | -cancel = Cancel | ||
| 13 | -waiting = Waiting | ||
| 14 | -done = Done | ||
| 15 | -skipped = Skipped | ||
| 16 | -failed = Failed | ||
| 17 | -linux_v1 = Linux v1 | ||
| 18 | -linux_v3 = Linux v3 | ||
| 19 | -prepare = Prepare | ||
| 20 | -windows_v1 = Windows v1 | ||
| 21 | -windows_v3 = Windows v3 | ||
| 22 | -building = Building | ||
| 23 | -build_failed = Build failed | ||
| 24 | -cancelled = Cancelled | ||
| 25 | -open_releases = Open Releases | ||
| 26 | -dismiss = Dismiss | ||
| 27 | ready = Ready to publish | 9 | ready = Ready to publish |
| 28 | discard = Discard | 10 | discard = Discard |
| 29 | server = Server | 11 | server = Server |
| 30 | -retry = Retry | ||
| 31 | -stopping = Stopping | ||
| 32 | client = Client | 12 | client = Client |
| 33 | both = Both | 13 | both = Both |
| 14 | +import = Import | ||
| 15 | +importing = Importing | ||
| 16 | +tag = Tag (v1.2.3) | ||
| 17 | +nothing_new = Nothing new in that release | ||
crates/client/lang/tr/builder_release.txtmodified+4 -20
| @@ -6,28 +6,12 @@ required = Zorunlu | |||
| 6 | publish = Yayınla | 6 | publish = Yayınla |
| 7 | confirm = Onayla | 7 | confirm = Onayla |
| 8 | no_releases = Sürüm yok | 8 | no_releases = Sürüm yok |
| 9 | -choose_source = Kaynak seç | ||
| 10 | -no_source = Kaynak klasörü yok | ||
| 11 | -not_source = Geçerli bir sürüm kaynağı değil | ||
| 12 | -cancel = İptal | ||
| 13 | -waiting = Bekliyor | ||
| 14 | -done = Tamam | ||
| 15 | -skipped = Atlandı | ||
| 16 | -failed = Başarısız | ||
| 17 | -linux_v1 = Linux v1 | ||
| 18 | -linux_v3 = Linux v3 | ||
| 19 | -prepare = Hazırlık | ||
| 20 | -windows_v1 = Windows v1 | ||
| 21 | -windows_v3 = Windows v3 | ||
| 22 | -building = Derleniyor | ||
| 23 | -build_failed = Derleme başarısız | ||
| 24 | -cancelled = İptal edildi | ||
| 25 | -open_releases = Sürümleri aç | ||
| 26 | -dismiss = Kapat | ||
| 27 | ready = Yayına hazır | 9 | ready = Yayına hazır |
| 28 | discard = Vazgeç | 10 | discard = Vazgeç |
| 29 | server = Sunucu | 11 | server = Sunucu |
| 30 | -retry = Tekrar dene | ||
| 31 | -stopping = Durduruluyor | ||
| 32 | client = İstemci | 12 | client = İstemci |
| 33 | both = İkisi | 13 | both = İkisi |
| 14 | +import = İçe aktar | ||
| 15 | +importing = İçe aktarılıyor | ||
| 16 | +tag = Etiket (v1.2.3) | ||
| 17 | +nothing_new = O sürümde yeni bir şey yok | ||
crates/client/src/gui.rsmodified+5 -6
| @@ -614,8 +614,7 @@ pub struct Yumush { | |||
| 614 | pending_backup_delete: Option<String>, | 614 | pending_backup_delete: Option<String>, |
| 615 | update: crate::update::Phase, | 615 | update: crate::update::Phase, |
| 616 | desk: builder::releases::Desk, | 616 | desk: builder::releases::Desk, |
| 617 | - log_search: Entity<InputState>, | 617 | + release_tag: Entity<InputState>, |
| 618 | - log_scroll: gpui_kit::UniformListScrollHandle, | ||
| 619 | share_apps: Vec<crate::share::audio::AudioApp>, | 618 | share_apps: Vec<crate::share::audio::AudioApp>, |
| 620 | share_apps_seen: std::cell::Cell<Instant>, | 619 | share_apps_seen: std::cell::Cell<Instant>, |
| 621 | share_apps_task: Option<gpui_kit::Task<()>>, | 620 | share_apps_task: Option<gpui_kit::Task<()>>, |
| @@ -692,7 +691,7 @@ impl Yumush { | |||
| 692 | 691 | ||
| 693 | let server = network.server(); | 692 | let server = network.server(); |
| 694 | let account_filter = new_input(w().auth.find_account, window, cx); | 693 | let account_filter = new_input(w().auth.find_account, window, cx); |
| 695 | - let log_search = new_input(w().chat.find, window, cx); | 694 | + let release_tag = new_input(w().builder_release.tag, window, cx); |
| 696 | cx.subscribe(&account_filter, |_, _, event: &InputEvent, cx| { | 695 | cx.subscribe(&account_filter, |_, _, event: &InputEvent, cx| { |
| 697 | if matches!(event, InputEvent::Change) { | 696 | if matches!(event, InputEvent::Change) { |
| 698 | cx.notify(); | 697 | cx.notify(); |
| @@ -719,8 +718,7 @@ impl Yumush { | |||
| 719 | pending_backup_delete: None, | 718 | pending_backup_delete: None, |
| 720 | update: crate::update::Phase::Idle, | 719 | update: crate::update::Phase::Idle, |
| 721 | desk: builder::releases::Desk::default(), | 720 | desk: builder::releases::Desk::default(), |
| 722 | - log_search, | 721 | + release_tag, |
| 723 | - log_scroll: gpui_kit::UniformListScrollHandle::new(), | ||
| 724 | share_apps: Vec::new(), | 722 | share_apps: Vec::new(), |
| 725 | share_apps_seen: std::cell::Cell::new(Instant::now()), | 723 | share_apps_seen: std::cell::Cell::new(Instant::now()), |
| 726 | share_apps_task: None, | 724 | share_apps_task: None, |
| @@ -1310,6 +1308,7 @@ impl Yumush { | |||
| 1310 | } | 1308 | } |
| 1311 | Event::ReportCreated => self.report_created(window, cx), | 1309 | Event::ReportCreated => self.report_created(window, cx), |
| 1312 | Event::Release => self.releases_changed(window, cx), | 1310 | Event::Release => self.releases_changed(window, cx), |
| 1311 | + Event::Imported { result, .. } => self.release_imported(result, window, cx), | ||
| 1313 | Event::SettingsUpdated(settings) => self.server = Some(settings), | 1312 | Event::SettingsUpdated(settings) => self.server = Some(settings), |
| 1314 | event => { | 1313 | event => { |
| 1315 | let voice = matches!( | 1314 | let voice = matches!( |
| @@ -1500,7 +1499,7 @@ impl Render for Yumush { | |||
| 1500 | self.schedule_pump(window, cx); | 1499 | self.schedule_pump(window, cx); |
| 1501 | let palette = palette(cx); | 1500 | let palette = palette(cx); |
| 1502 | let route = self.current_route; | 1501 | let route = self.current_route; |
| 1503 | - let required = self.update.required() && !crate::release::running(); | 1502 | + let required = self.update.required(); |
| 1504 | let page = match route { | 1503 | let page = match route { |
| 1505 | _ if required => self.update_required(palette).into_any_element(), | 1504 | _ if required => self.update_required(palette).into_any_element(), |
| 1506 | Route::Login | Route::Register => self.auth_page(route, cx).into_any_element(), | 1505 | Route::Login | Route::Register => self.auth_page(route, cx).into_any_element(), |
crates/client/src/gui/builder/releases.rsmodified+141 -740
| @@ -1,34 +1,29 @@ | |||
| 1 | use common::{ | 1 | use common::{ |
| 2 | - call::{ListReleases, PublishRelease, SetReleaseRequired}, | 2 | + call::{ImportRelease, ListReleases, PublishRelease, SetReleaseRequired}, |
| 3 | + error::ReleaseProblem, | ||
| 3 | model::{ReleaseInfo, Staged}, | 4 | model::{ReleaseInfo, Staged}, |
| 5 | + update::{SERVER_TARGET, Sha}, | ||
| 4 | }; | 6 | }; |
| 5 | use gpui_kit::{ | 7 | use gpui_kit::{ |
| 6 | - Anchor, AnyElement, App, Context, Div, Entity, Focusable, Hsla, InteractiveElement, | 8 | + AnyElement, Context, Div, Entity, Hsla, IntoElement, ParentElement, PathPromptOptions, Styled, |
| 7 | - IntoElement, ListHorizontalSizingBehavior, ParentElement, PathPromptOptions, ScrollStrategy, | 9 | + Window, |
| 8 | - Styled, Window, component::popover::Popover, div, px, uniform_list, | 10 | + component::{WindowExt as _, notification::Notification}, |
| 11 | + div, px, uniform_list, | ||
| 9 | }; | 12 | }; |
| 10 | use std::path::PathBuf; | 13 | use std::path::PathBuf; |
| 11 | -use std::rc::Rc; | ||
| 12 | -use std::time::{Duration, Instant}; | ||
| 13 | 14 | ||
| 14 | use super::ui::{card, card_header, confirmed, delete_icon_button, list_row, rows_body}; | 15 | use super::ui::{card, card_header, confirmed, delete_icon_button, list_row, rows_body}; |
| 15 | -use crate::gui::builder::BuilderTab; | ||
| 16 | -use crate::gui::chat::View; | ||
| 17 | use crate::gui::{ | 16 | use crate::gui::{ |
| 18 | - Palette, Trigger, Yumush, entity_action, hoverable, millis_time, notify_error, | 17 | + Palette, Yumush, entity_action, millis_time, notify_error, |
| 19 | parts::{self, Fill, Press}, | 18 | parts::{self, Fill, Press}, |
| 20 | - profile::yumush_action, | ||
| 21 | storage, | 19 | storage, |
| 22 | - style::{radius, size, space, text}, | 20 | + style::{size, space, text}, |
| 23 | text, | 21 | text, |
| 22 | + widget::field, | ||
| 24 | }; | 23 | }; |
| 25 | use crate::lang::w; | 24 | use crate::lang::w; |
| 26 | -use crate::release::{Build, Event, Job, Level, Side, is_source}; | ||
| 27 | 25 | ||
| 28 | const METER: f32 = 140.; | 26 | const METER: f32 = 140.; |
| 29 | -const LOG_LINE: f32 = 18.; | ||
| 30 | -const LOG_MAX: usize = 50_000; | ||
| 31 | -const TICK: Duration = Duration::from_secs(1); | ||
| 32 | 27 | ||
| 33 | #[derive(Default)] | 28 | #[derive(Default)] |
| 34 | pub(crate) struct Desk { | 29 | pub(crate) struct Desk { |
| @@ -38,68 +33,24 @@ pub(crate) struct Desk { | |||
| 38 | publishing: bool, | 33 | publishing: bool, |
| 39 | releases: Vec<ReleaseInfo>, | 34 | releases: Vec<ReleaseInfo>, |
| 40 | pending_required: Option<u64>, | 35 | pending_required: Option<u64>, |
| 41 | - build: Option<Build>, | 36 | + importing: Option<String>, |
| 42 | - jobs: Vec<Row>, | ||
| 43 | - cancelled: bool, | ||
| 44 | - began: Option<Instant>, | ||
| 45 | - ended: Option<Instant>, | ||
| 46 | - dismissed: bool, | ||
| 47 | - log_open: Option<Job>, | ||
| 48 | } | 37 | } |
| 49 | 38 | ||
| 50 | -struct Row { | 39 | +#[derive(Clone, Copy)] |
| 51 | - job: Job, | 40 | +enum Side { |
| 52 | - phase: Phase, | 41 | + Server, |
| 53 | - line: String, | 42 | + Client, |
| 54 | - log: Vec<String>, | 43 | + Both, |
| 55 | - started: Option<Instant>, | ||
| 56 | - ended: Option<Instant>, | ||
| 57 | } | 44 | } |
| 58 | 45 | ||
| 59 | -#[derive(Clone, Copy, PartialEq, Eq)] | 46 | +impl Side { |
| 60 | -enum Status { | 47 | + fn takes(self, target: &str) -> bool { |
| 61 | - Running, | 48 | + match self { |
| 62 | - Stopping, | 49 | + Self::Server => target == SERVER_TARGET, |
| 63 | - Done, | 50 | + Self::Client => target != SERVER_TARGET, |
| 64 | - Failed, | 51 | + Self::Both => true, |
| 65 | - Cancelled, | ||
| 66 | -} | ||
| 67 | - | ||
| 68 | -impl Row { | ||
| 69 | - fn share(&self) -> f32 { | ||
| 70 | - match self.phase { | ||
| 71 | - Phase::Waiting => 0., | ||
| 72 | - Phase::Running { done, total } if total > 0 => done as f32 / total as f32, | ||
| 73 | - Phase::Running { .. } => 0., | ||
| 74 | - Phase::Done | Phase::Skipped(_) | Phase::Failed(_) => 1., | ||
| 75 | } | 52 | } |
| 76 | } | 53 | } |
| 77 | - | ||
| 78 | - fn finished(&self) -> bool { | ||
| 79 | - matches!(self.phase, Phase::Done | Phase::Skipped(_)) | ||
| 80 | - } | ||
| 81 | -} | ||
| 82 | - | ||
| 83 | -fn span(from: Option<Instant>, to: Option<Instant>, seconds: bool) -> Option<String> { | ||
| 84 | - let total = to | ||
| 85 | - .unwrap_or_else(Instant::now) | ||
| 86 | - .duration_since(from?) | ||
| 87 | - .as_secs(); | ||
| 88 | - let (hours, minutes, rest) = (total / 3600, total / 60 % 60, total % 60); | ||
| 89 | - Some(match (seconds, hours) { | ||
| 90 | - (true, 0) => format!("{minutes}:{rest:02}"), | ||
| 91 | - (true, _) => format!("{hours}:{minutes:02}:{rest:02}"), | ||
| 92 | - (false, 0) => format!("{minutes}m"), | ||
| 93 | - (false, _) => format!("{hours}h {minutes:02}m"), | ||
| 94 | - }) | ||
| 95 | -} | ||
| 96 | - | ||
| 97 | -enum Phase { | ||
| 98 | - Waiting, | ||
| 99 | - Running { done: u32, total: u32 }, | ||
| 100 | - Done, | ||
| 101 | - Skipped(String), | ||
| 102 | - Failed(String), | ||
| 103 | } | 54 | } |
| 104 | 55 | ||
| 105 | struct Draft { | 56 | struct Draft { |
| @@ -125,12 +76,20 @@ fn is_duplicate(drafts: &[Draft], index: usize) -> bool { | |||
| 125 | } | 76 | } |
| 126 | 77 | ||
| 127 | impl Desk { | 78 | impl Desk { |
| 128 | - fn can_publish(&self) -> bool { | 79 | + fn picked(&self, side: Side) -> Option<Vec<Sha>> { |
| 129 | - !self.publishing | 80 | + let ready = !self.publishing |
| 130 | - && !self.drafts.is_empty() | ||
| 131 | && self.drafts.iter().enumerate().all(|(index, draft)| { | 81 | && self.drafts.iter().enumerate().all(|(index, draft)| { |
| 132 | matches!(draft.stage, Stage::Ready(_)) && !is_duplicate(&self.drafts, index) | 82 | matches!(draft.stage, Stage::Ready(_)) && !is_duplicate(&self.drafts, index) |
| 83 | + }); | ||
| 84 | + let files: Vec<Sha> = self | ||
| 85 | + .drafts | ||
| 86 | + .iter() | ||
| 87 | + .filter_map(|draft| match &draft.stage { | ||
| 88 | + Stage::Ready(staged) if side.takes(&staged.target) => Some(staged.file), | ||
| 89 | + _ => None, | ||
| 133 | }) | 90 | }) |
| 91 | + .collect(); | ||
| 92 | + (ready && !files.is_empty()).then_some(files) | ||
| 134 | } | 93 | } |
| 135 | 94 | ||
| 136 | fn next_seq(&self) -> u64 { | 95 | fn next_seq(&self) -> u64 { |
| @@ -142,60 +101,9 @@ impl Desk { | |||
| 142 | + 1 | 101 | + 1 |
| 143 | } | 102 | } |
| 144 | 103 | ||
| 145 | - fn building(&self) -> bool { | ||
| 146 | - !self.dismissed && (self.build.is_some() || self.failed() || self.cancelled) | ||
| 147 | - } | ||
| 148 | - | ||
| 149 | - fn active(&self) -> bool { | ||
| 150 | - self.build.is_some() && !self.cancelled | ||
| 151 | - } | ||
| 152 | - | ||
| 153 | - fn failed(&self) -> bool { | ||
| 154 | - self.jobs | ||
| 155 | - .iter() | ||
| 156 | - .any(|row| matches!(row.phase, Phase::Failed(_))) | ||
| 157 | - } | ||
| 158 | - | ||
| 159 | fn draft(&mut self, id: u64) -> Option<&mut Draft> { | 104 | fn draft(&mut self, id: u64) -> Option<&mut Draft> { |
| 160 | self.drafts.iter_mut().find(|draft| draft.id == id) | 105 | self.drafts.iter_mut().find(|draft| draft.id == id) |
| 161 | } | 106 | } |
| 162 | - | ||
| 163 | - fn row(&mut self, job: Job) -> Option<&mut Row> { | ||
| 164 | - self.jobs.iter_mut().find(|row| row.job == job) | ||
| 165 | - } | ||
| 166 | - | ||
| 167 | - fn status(&self) -> Option<Status> { | ||
| 168 | - if self.jobs.is_empty() || self.dismissed { | ||
| 169 | - return None; | ||
| 170 | - } | ||
| 171 | - Some(if self.active() { | ||
| 172 | - Status::Running | ||
| 173 | - } else if self.build.is_some() { | ||
| 174 | - Status::Stopping | ||
| 175 | - } else if self.cancelled { | ||
| 176 | - Status::Cancelled | ||
| 177 | - } else if self.failed() { | ||
| 178 | - Status::Failed | ||
| 179 | - } else { | ||
| 180 | - Status::Done | ||
| 181 | - }) | ||
| 182 | - } | ||
| 183 | - | ||
| 184 | - fn share(&self) -> f32 { | ||
| 185 | - self.jobs.iter().map(Row::share).sum::<f32>() / self.jobs.len().max(1) as f32 | ||
| 186 | - } | ||
| 187 | -} | ||
| 188 | - | ||
| 189 | -fn job_label(job: Job) -> &'static str { | ||
| 190 | - let w = &w().builder_release; | ||
| 191 | - match job { | ||
| 192 | - Job::Prepare => w.prepare, | ||
| 193 | - Job::Linux(Level::V1) => w.linux_v1, | ||
| 194 | - Job::Linux(Level::V3) => w.linux_v3, | ||
| 195 | - Job::Server => w.server, | ||
| 196 | - Job::Windows(Level::V1) => w.windows_v1, | ||
| 197 | - Job::Windows(Level::V3) => w.windows_v3, | ||
| 198 | - } | ||
| 199 | } | 107 | } |
| 200 | 108 | ||
| 201 | pub(super) fn caption_text(value: impl Into<String>, color: Hsla) -> Div { | 109 | pub(super) fn caption_text(value: impl Into<String>, color: Hsla) -> Div { |
| @@ -215,142 +123,6 @@ pub(super) fn meter(share: f32, label: String, palette: Palette) -> Div { | |||
| 215 | .child(caption_text(label, palette.muted)) | 123 | .child(caption_text(label, palette.muted)) |
| 216 | } | 124 | } |
| 217 | 125 | ||
| 218 | -fn job_row( | ||
| 219 | - row: &Row, | ||
| 220 | - seconds: bool, | ||
| 221 | - retry: Option<AnyElement>, | ||
| 222 | - entity: &Entity<Yumush>, | ||
| 223 | - palette: Palette, | ||
| 224 | -) -> Div { | ||
| 225 | - let (status, detail): (Div, Option<Div>) = match &row.phase { | ||
| 226 | - Phase::Waiting => ( | ||
| 227 | - caption_text(w().builder_release.waiting, palette.muted), | ||
| 228 | - None, | ||
| 229 | - ), | ||
| 230 | - Phase::Running { done, total } => { | ||
| 231 | - let status = if *total == 0 { | ||
| 232 | - caption_text("…", palette.muted) | ||
| 233 | - } else { | ||
| 234 | - meter( | ||
| 235 | - *done as f32 / *total as f32, | ||
| 236 | - format!("{done}/{total}"), | ||
| 237 | - palette, | ||
| 238 | - ) | ||
| 239 | - }; | ||
| 240 | - (status, Some(caption_text(row.line.clone(), palette.muted))) | ||
| 241 | - } | ||
| 242 | - Phase::Done => (caption_text(w().builder_release.done, palette.ok), None), | ||
| 243 | - Phase::Skipped(reason) => ( | ||
| 244 | - caption_text(w().builder_release.skipped, palette.muted), | ||
| 245 | - Some(caption_text(reason.clone(), palette.muted)), | ||
| 246 | - ), | ||
| 247 | - Phase::Failed(reason) => ( | ||
| 248 | - caption_text(w().builder_release.failed, palette.danger), | ||
| 249 | - Some(caption_text(reason.clone(), palette.danger)), | ||
| 250 | - ), | ||
| 251 | - }; | ||
| 252 | - | ||
| 253 | - let info = div() | ||
| 254 | - .id(format!("job_log_{:?}", row.job)) | ||
| 255 | - .w_full() | ||
| 256 | - .flex() | ||
| 257 | - .flex_col() | ||
| 258 | - .cursor_pointer() | ||
| 259 | - .child( | ||
| 260 | - div() | ||
| 261 | - .text_size(text(text::LABEL)) | ||
| 262 | - .text_color(palette.text) | ||
| 263 | - .child(job_label(row.job)), | ||
| 264 | - ) | ||
| 265 | - .children(detail.map(|detail| detail.truncate())); | ||
| 266 | - let job = row.job; | ||
| 267 | - let entity = entity.clone(); | ||
| 268 | - list_row() | ||
| 269 | - .child( | ||
| 270 | - div().flex_1().min_w_0().child( | ||
| 271 | - Popover::new(format!("job_log_popover_{job:?}")) | ||
| 272 | - .anchor(Anchor::TopLeft) | ||
| 273 | - .appearance(false) | ||
| 274 | - .trigger(Trigger::new(info)) | ||
| 275 | - .content(move |_, window, cx| log_sheet(job, &entity, window, cx)), | ||
| 276 | - ), | ||
| 277 | - ) | ||
| 278 | - .children(retry) | ||
| 279 | - .child(status) | ||
| 280 | - .children( | ||
| 281 | - span(row.started, row.ended, seconds).map(|time| caption_text(time, palette.muted)), | ||
| 282 | - ) | ||
| 283 | -} | ||
| 284 | - | ||
| 285 | -fn log_sheet(job: Job, entity: &Entity<Yumush>, window: &mut Window, cx: &mut App) -> Div { | ||
| 286 | - let palette = crate::gui::palette(cx); | ||
| 287 | - let input = entity.read(cx).log_search.clone(); | ||
| 288 | - if !input.read(cx).focus_handle(cx).contains_focused(window, cx) { | ||
| 289 | - input.update(cx, |state, cx| state.focus(window, cx)); | ||
| 290 | - } | ||
| 291 | - let query = crate::gui::widget::search_text(&input, cx); | ||
| 292 | - let yumush = entity.read(cx); | ||
| 293 | - let lines: Rc<Vec<usize>> = Rc::new( | ||
| 294 | - yumush | ||
| 295 | - .desk | ||
| 296 | - .jobs | ||
| 297 | - .iter() | ||
| 298 | - .find(|row| row.job == job) | ||
| 299 | - .map(|row| { | ||
| 300 | - row.log | ||
| 301 | - .iter() | ||
| 302 | - .enumerate() | ||
| 303 | - .filter(|(_, line)| query.is_empty() || line.to_lowercase().contains(&query)) | ||
| 304 | - .map(|(index, _)| index) | ||
| 305 | - .collect() | ||
| 306 | - }) | ||
| 307 | - .unwrap_or_default(), | ||
| 308 | - ); | ||
| 309 | - let scroll = yumush.log_scroll.clone(); | ||
| 310 | - let count = lines.len(); | ||
| 311 | - if yumush.desk.log_open != Some(job) { | ||
| 312 | - scroll.scroll_to_item(count.saturating_sub(1), ScrollStrategy::Bottom); | ||
| 313 | - entity.update(cx, |yumush, _| yumush.desk.log_open = Some(job)); | ||
| 314 | - } | ||
| 315 | - let entity = entity.clone(); | ||
| 316 | - crate::gui::widget::panel(palette) | ||
| 317 | - .w(px(size::PAGE - space::XL)) | ||
| 318 | - .p(px(space::XS)) | ||
| 319 | - .flex() | ||
| 320 | - .flex_col() | ||
| 321 | - .gap(px(space::XS)) | ||
| 322 | - .child(crate::gui::sidebar::input_box(&input, palette)) | ||
| 323 | - .child( | ||
| 324 | - uniform_list( | ||
| 325 | - format!("job_log_lines_{job:?}"), | ||
| 326 | - count, | ||
| 327 | - move |range, _, cx| { | ||
| 328 | - let yumush = entity.read(cx); | ||
| 329 | - let palette = crate::gui::palette(cx); | ||
| 330 | - let Some(row) = yumush.desk.jobs.iter().find(|row| row.job == job) else { | ||
| 331 | - return Vec::new(); | ||
| 332 | - }; | ||
| 333 | - lines[range] | ||
| 334 | - .iter() | ||
| 335 | - .filter_map(|&index| row.log.get(index)) | ||
| 336 | - .map(|line| { | ||
| 337 | - div() | ||
| 338 | - .h(px(LOG_LINE)) | ||
| 339 | - .px(px(space::XS)) | ||
| 340 | - .whitespace_nowrap() | ||
| 341 | - .text_size(text(text::CAPTION)) | ||
| 342 | - .text_color(palette.muted) | ||
| 343 | - .child(line.clone()) | ||
| 344 | - }) | ||
| 345 | - .collect() | ||
| 346 | - }, | ||
| 347 | - ) | ||
| 348 | - .with_horizontal_sizing_behavior(ListHorizontalSizingBehavior::Unconstrained) | ||
| 349 | - .track_scroll(&scroll) | ||
| 350 | - .h(px((count as f32 * LOG_LINE).clamp(LOG_LINE, size::SHEET))), | ||
| 351 | - ) | ||
| 352 | -} | ||
| 353 | - | ||
| 354 | fn draft_row(draft: &Draft, duplicate: bool, entity: &Entity<Yumush>, palette: Palette) -> Div { | 126 | fn draft_row(draft: &Draft, duplicate: bool, entity: &Entity<Yumush>, palette: Palette) -> Div { |
| 355 | let id = draft.id; | 127 | let id = draft.id; |
| 356 | let status = match &draft.stage { | 128 | let status = match &draft.stage { |
| @@ -465,7 +237,7 @@ fn release_row( | |||
| 465 | 237 | ||
| 466 | impl Yumush { | 238 | impl Yumush { |
| 467 | pub(super) fn releases_body(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> { | 239 | pub(super) fn releases_body(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> { |
| 468 | - let mut body = vec![self.build_card(entity, palette).into_any_element()]; | 240 | + let mut body = vec![self.import_card(entity, palette).into_any_element()]; |
| 469 | if !self.desk.drafts.is_empty() { | 241 | if !self.desk.drafts.is_empty() { |
| 470 | body.push(self.draft_card(entity, palette).into_any_element()); | 242 | body.push(self.draft_card(entity, palette).into_any_element()); |
| 471 | } | 243 | } |
| @@ -473,324 +245,35 @@ impl Yumush { | |||
| 473 | body | 245 | body |
| 474 | } | 246 | } |
| 475 | 247 | ||
| 476 | - fn build_card(&self, entity: &Entity<Self>, palette: Palette) -> Div { | 248 | + fn import_card(&self, entity: &Entity<Self>, palette: Palette) -> Div { |
| 477 | - let running = self.desk.build.is_some(); | 249 | + let w = &w().builder_release; |
| 478 | - let source = self.settings.release_source.as_ref().map_or_else( | 250 | + let import = parts::button( |
| 479 | - || w().builder_release.no_source.to_string(), | 251 | + "import_release", |
| 480 | - |path| path.display().to_string(), | 252 | + w.import, |
| 481 | - ); | 253 | + Press::Primary, |
| 482 | - let choose = parts::button( | ||
| 483 | - "choose_release_source", | ||
| 484 | - w().builder_release.choose_source, | ||
| 485 | - Press::Plain, | ||
| 486 | palette.tokens, | 254 | palette.tokens, |
| 487 | entity_action(entity, |yumush, window, cx| { | 255 | entity_action(entity, |yumush, window, cx| { |
| 488 | - yumush.pick_release_source(window, cx) | 256 | + yumush.import_release(window, cx) |
| 489 | }), | 257 | }), |
| 490 | ); | 258 | ); |
| 491 | - let ready = self.settings.release_source.is_some() && !running; | 259 | + let status = self |
| 492 | - let w = &w().builder_release; | 260 | + .desk |
| 493 | - let builds = [ | 261 | + .importing |
| 494 | - ("build_server", w.server, Side::Server), | 262 | + .as_ref() |
| 495 | - ("build_client", w.client, Side::Client), | 263 | + .map(|tag| caption_text(format!("{} {tag}", w.importing), palette.muted)); |
| 496 | - ("build_both", w.both, Side::Both), | 264 | + card(palette).child( |
| 497 | - ] | 265 | + list_row() |
| 498 | - .map(|(id, label, side)| { | 266 | + .child(field(palette, &self.release_tag).w(px(METER))) |
| 499 | - let button = parts::button( | 267 | + .children(status) |
| 500 | - id, | 268 | + .child(div().flex_1()) |
| 501 | - label, | 269 | + .child(if self.desk.importing.is_none() { |
| 502 | - Press::Primary, | 270 | + import |
| 503 | - palette.tokens, | 271 | + } else { |
| 504 | - entity_action(entity, move |yumush, window, cx| { | 272 | + import.opacity(0.4) |
| 505 | - yumush.start_build(side, window, cx) | ||
| 506 | - }), | ||
| 507 | - ); | ||
| 508 | - if ready { button } else { button.opacity(0.4) } | ||
| 509 | - }); | ||
| 510 | - | ||
| 511 | - card(palette) | ||
| 512 | - .child( | ||
| 513 | - list_row() | ||
| 514 | - .child( | ||
| 515 | - div() | ||
| 516 | - .flex_1() | ||
| 517 | - .min_w_0() | ||
| 518 | - .truncate() | ||
| 519 | - .text_size(text(text::LABEL)) | ||
| 520 | - .text_color(palette.muted) | ||
| 521 | - .child(source), | ||
| 522 | - ) | ||
| 523 | - .child(choose) | ||
| 524 | - .children(builds), | ||
| 525 | - ) | ||
| 526 | - .children( | ||
| 527 | - self.desk | ||
| 528 | - .building() | ||
| 529 | - .then(|| self.progress_card(entity, palette)), | ||
| 530 | - ) | ||
| 531 | - } | ||
| 532 | - | ||
| 533 | - fn progress_card(&self, entity: &Entity<Self>, palette: Palette) -> Div { | ||
| 534 | - let w = &w().builder_release; | ||
| 535 | - let running = self.desk.active(); | ||
| 536 | - let close = if running { | ||
| 537 | - parts::button( | ||
| 538 | - "cancel_release_build", | ||
| 539 | - w.cancel, | ||
| 540 | - Press::Danger, | ||
| 541 | - palette.tokens, | ||
| 542 | - entity_action(entity, |yumush, _, cx| yumush.cancel_build(cx)), | ||
| 543 | - ) | ||
| 544 | - } else { | ||
| 545 | - parts::button( | ||
| 546 | - "dismiss_release_build", | ||
| 547 | - w.dismiss, | ||
| 548 | - Press::Plain, | ||
| 549 | - palette.tokens, | ||
| 550 | - entity_action(entity, |yumush, _, cx| { | ||
| 551 | - yumush.desk.dismissed = true; | ||
| 552 | - cx.notify(); | ||
| 553 | }), | 273 | }), |
| 554 | - ) | ||
| 555 | - }; | ||
| 556 | - div() | ||
| 557 | - .flex() | ||
| 558 | - .flex_col() | ||
| 559 | - .pt(px(space::MD)) | ||
| 560 | - .child(self.build_head(palette)) | ||
| 561 | - .child(parts::track( | ||
| 562 | - Fill::Part(self.desk.share()), | ||
| 563 | - self.desk.failed(), | ||
| 564 | - palette.tokens, | ||
| 565 | - )) | ||
| 566 | - .children(self.lanes(entity, |row| row, palette)) | ||
| 567 | - .child(list_row().justify_end().child(close)) | ||
| 568 | - } | ||
| 569 | - | ||
| 570 | - fn retry_button( | ||
| 571 | - &self, | ||
| 572 | - row: &Row, | ||
| 573 | - entity: &Entity<Self>, | ||
| 574 | - palette: Palette, | ||
| 575 | - ) -> Option<AnyElement> { | ||
| 576 | - if !self.desk.active() || !matches!(row.phase, Phase::Failed(_)) { | ||
| 577 | - return None; | ||
| 578 | - } | ||
| 579 | - let job = row.job; | ||
| 580 | - Some( | ||
| 581 | - parts::button( | ||
| 582 | - format!("retry_build_{job:?}"), | ||
| 583 | - w().builder_release.retry, | ||
| 584 | - Press::Plain, | ||
| 585 | - palette.tokens, | ||
| 586 | - entity_action(entity, move |yumush, _, cx| yumush.retry_job(job, cx)), | ||
| 587 | - ) | ||
| 588 | - .into_any_element(), | ||
| 589 | - ) | ||
| 590 | - } | ||
| 591 | - | ||
| 592 | - fn retry_job(&mut self, job: Job, cx: &mut Context<Self>) { | ||
| 593 | - let Some(build) = &self.desk.build else { | ||
| 594 | - return; | ||
| 595 | - }; | ||
| 596 | - build.retry(); | ||
| 597 | - if let Some(row) = self.desk.row(job) { | ||
| 598 | - row.phase = Phase::Waiting; | ||
| 599 | - row.line.clear(); | ||
| 600 | - row.started = None; | ||
| 601 | - row.ended = None; | ||
| 602 | - } | ||
| 603 | - cx.notify(); | ||
| 604 | - } | ||
| 605 | - | ||
| 606 | - fn build_head(&self, palette: Palette) -> Div { | ||
| 607 | - let w = &w().builder_release; | ||
| 608 | - let label = match self.desk.status() { | ||
| 609 | - Some(Status::Running) => w.building, | ||
| 610 | - Some(Status::Stopping) => w.stopping, | ||
| 611 | - Some(Status::Failed) => w.build_failed, | ||
| 612 | - Some(Status::Cancelled) => w.cancelled, | ||
| 613 | - Some(Status::Done) if self.desk.can_publish() => w.ready, | ||
| 614 | - _ => w.done, | ||
| 615 | - }; | ||
| 616 | - let finished = self.desk.jobs.iter().filter(|row| row.finished()).count(); | ||
| 617 | - let time = span( | ||
| 618 | - self.desk.began, | ||
| 619 | - self.desk.ended, | ||
| 620 | - self.settings.clock_seconds, | ||
| 621 | - ) | ||
| 622 | - .unwrap_or_default(); | ||
| 623 | - let aside = if self.desk.active() { | ||
| 624 | - format!("{finished} / {} · {time}", self.desk.jobs.len()) | ||
| 625 | - } else { | ||
| 626 | - time | ||
| 627 | - }; | ||
| 628 | - div() | ||
| 629 | - .flex() | ||
| 630 | - .justify_between() | ||
| 631 | - .pb(px(space::XS)) | ||
| 632 | - .text_size(text(text::LABEL)) | ||
| 633 | - .child( | ||
| 634 | - div() | ||
| 635 | - .text_color(if self.desk.status() == Some(Status::Failed) { | ||
| 636 | - palette.danger | ||
| 637 | - } else { | ||
| 638 | - palette.text | ||
| 639 | - }) | ||
| 640 | - .child(label), | ||
| 641 | - ) | ||
| 642 | - .child(div().text_color(palette.muted).child(aside)) | ||
| 643 | - } | ||
| 644 | - | ||
| 645 | - fn lanes(&self, entity: &Entity<Self>, fit: impl Fn(Div) -> Div, palette: Palette) -> Vec<Div> { | ||
| 646 | - let seconds = self.settings.clock_seconds; | ||
| 647 | - self.desk | ||
| 648 | - .jobs | ||
| 649 | - .iter() | ||
| 650 | - .map(|row| { | ||
| 651 | - let retry = self.retry_button(row, entity, palette); | ||
| 652 | - fit(job_row(row, seconds, retry, entity, palette)) | ||
| 653 | - }) | ||
| 654 | - .collect() | ||
| 655 | - } | ||
| 656 | - | ||
| 657 | - pub(in crate::gui) fn build_control( | ||
| 658 | - &self, | ||
| 659 | - entity: &Entity<Self>, | ||
| 660 | - palette: Palette, | ||
| 661 | - ) -> Option<AnyElement> { | ||
| 662 | - let status = self.desk.status()?; | ||
| 663 | - let w = &w().builder_release; | ||
| 664 | - let t = palette.tokens; | ||
| 665 | - let seconds = self.settings.clock_seconds; | ||
| 666 | - let label = match status { | ||
| 667 | - Status::Running => w.building, | ||
| 668 | - Status::Stopping => w.stopping, | ||
| 669 | - Status::Done if self.desk.can_publish() => w.ready, | ||
| 670 | - Status::Done => w.done, | ||
| 671 | - Status::Failed => w.build_failed, | ||
| 672 | - Status::Cancelled => w.cancelled, | ||
| 673 | - }; | ||
| 674 | - let aside = match status { | ||
| 675 | - Status::Running => format!( | ||
| 676 | - "{} / {}", | ||
| 677 | - self.desk.jobs.iter().filter(|row| row.finished()).count(), | ||
| 678 | - self.desk.jobs.len() | ||
| 679 | - ), | ||
| 680 | - _ => span(self.desk.began, self.desk.ended, seconds).unwrap_or_default(), | ||
| 681 | - }; | ||
| 682 | - let failed = status == Status::Failed; | ||
| 683 | - let trigger = hoverable( | ||
| 684 | - "build_trigger", | ||
| 685 | - div() | ||
| 686 | - .flex() | ||
| 687 | - .flex_col() | ||
| 688 | - .gap(px(space::XS)) | ||
| 689 | - .py(px(space::XS)) | ||
| 690 | - .px(px(space::SM)) | ||
| 691 | - .rounded(px(radius::MD)) | ||
| 692 | - .child( | ||
| 693 | - div() | ||
| 694 | - .flex() | ||
| 695 | - .justify_between() | ||
| 696 | - .text_size(text(text::LABEL)) | ||
| 697 | - .child( | ||
| 698 | - div() | ||
| 699 | - .text_color(if failed { palette.danger } else { palette.text }) | ||
| 700 | - .child(label), | ||
| 701 | - ) | ||
| 702 | - .child(div().text_color(palette.muted).child(aside)), | ||
| 703 | - ) | ||
| 704 | - .child(parts::track(Fill::Part(self.desk.share()), failed, t)), | ||
| 705 | - palette, | ||
| 706 | - ); | ||
| 707 | - let entity = entity.clone(); | ||
| 708 | - Some( | ||
| 709 | - Popover::new("build_status") | ||
| 710 | - .anchor(Anchor::BottomLeft) | ||
| 711 | - .appearance(false) | ||
| 712 | - .trigger(Trigger::new(trigger)) | ||
| 713 | - .content(move |_, _, cx| { | ||
| 714 | - let popover = cx.entity(); | ||
| 715 | - let palette = crate::gui::palette(cx); | ||
| 716 | - entity.read(cx).build_sheet(&entity, &popover, palette) | ||
| 717 | - }) | ||
| 718 | - .into_any_element(), | ||
| 719 | ) | 274 | ) |
| 720 | } | 275 | } |
| 721 | 276 | ||
| 722 | - fn build_sheet( | ||
| 723 | - &self, | ||
| 724 | - entity: &Entity<Self>, | ||
| 725 | - popover: &Entity<gpui_kit::component::popover::PopoverState>, | ||
| 726 | - palette: Palette, | ||
| 727 | - ) -> Div { | ||
| 728 | - let w = &w().builder_release; | ||
| 729 | - let running = self.desk.active(); | ||
| 730 | - let open = parts::button( | ||
| 731 | - "build_open_releases", | ||
| 732 | - w.open_releases, | ||
| 733 | - Press::Plain, | ||
| 734 | - palette.tokens, | ||
| 735 | - yumush_action(entity, popover, |yumush, window, cx| { | ||
| 736 | - yumush.show_view(View::Builder, window, cx); | ||
| 737 | - yumush.select_builder_tab(BuilderTab::Releases, window, cx); | ||
| 738 | - }), | ||
| 739 | - ); | ||
| 740 | - let close = if running { | ||
| 741 | - parts::button( | ||
| 742 | - "build_sheet_cancel", | ||
| 743 | - w.cancel, | ||
| 744 | - Press::Danger, | ||
| 745 | - palette.tokens, | ||
| 746 | - yumush_action(entity, popover, |yumush, _, cx| yumush.cancel_build(cx)), | ||
| 747 | - ) | ||
| 748 | - } else if self.desk.can_publish() { | ||
| 749 | - parts::button( | ||
| 750 | - "build_sheet_publish", | ||
| 751 | - w.publish, | ||
| 752 | - Press::Primary, | ||
| 753 | - palette.tokens, | ||
| 754 | - yumush_action(entity, popover, |yumush, window, cx| { | ||
| 755 | - yumush.publish_release(window, cx) | ||
| 756 | - }), | ||
| 757 | - ) | ||
| 758 | - } else { | ||
| 759 | - parts::button( | ||
| 760 | - "build_sheet_dismiss", | ||
| 761 | - w.dismiss, | ||
| 762 | - Press::Plain, | ||
| 763 | - palette.tokens, | ||
| 764 | - yumush_action(entity, popover, |yumush, _, cx| { | ||
| 765 | - yumush.desk.dismissed = true; | ||
| 766 | - cx.notify(); | ||
| 767 | - }), | ||
| 768 | - ) | ||
| 769 | - }; | ||
| 770 | - parts::popover(palette.tokens) | ||
| 771 | - .w(px(size::SHEET)) | ||
| 772 | - .p(px(space::MD)) | ||
| 773 | - .child(self.build_head(palette)) | ||
| 774 | - .children(self.lanes( | ||
| 775 | - entity, | ||
| 776 | - |row| row.min_h(px(size::CONTROL)).py(px(space::XXS)), | ||
| 777 | - palette, | ||
| 778 | - )) | ||
| 779 | - .children((!running && self.desk.can_publish()).then(|| { | ||
| 780 | - div() | ||
| 781 | - .pt(px(space::SM)) | ||
| 782 | - .child(self.required_toggle(entity, palette)) | ||
| 783 | - })) | ||
| 784 | - .child( | ||
| 785 | - div() | ||
| 786 | - .pt(px(space::SM)) | ||
| 787 | - .flex() | ||
| 788 | - .justify_between() | ||
| 789 | - .child(open) | ||
| 790 | - .child(close), | ||
| 791 | - ) | ||
| 792 | - } | ||
| 793 | - | ||
| 794 | fn required_toggle(&self, entity: &Entity<Self>, palette: Palette) -> impl IntoElement { | 277 | fn required_toggle(&self, entity: &Entity<Self>, palette: Palette) -> impl IntoElement { |
| 795 | parts::labeled_toggle( | 278 | parts::labeled_toggle( |
| 796 | "release_required", | 279 | "release_required", |
| @@ -813,20 +296,27 @@ impl Yumush { | |||
| 813 | .enumerate() | 296 | .enumerate() |
| 814 | .map(|(index, draft)| draft_row(draft, is_duplicate(drafts, index), entity, palette)) | 297 | .map(|(index, draft)| draft_row(draft, is_duplicate(drafts, index), entity, palette)) |
| 815 | .collect(); | 298 | .collect(); |
| 816 | - let publish = parts::button( | 299 | + let publish = [ |
| 817 | - "publish_release", | 300 | + ("publish_server", w.server, Side::Server), |
| 818 | - w.publish, | 301 | + ("publish_client", w.client, Side::Client), |
| 819 | - Press::Primary, | 302 | + ("publish_both", w.both, Side::Both), |
| 820 | - palette.tokens, | 303 | + ] |
| 821 | - entity_action(entity, |yumush, window, cx| { | 304 | + .map(|(id, label, side)| { |
| 822 | - yumush.publish_release(window, cx) | 305 | + let button = parts::button( |
| 823 | - }), | 306 | + id, |
| 824 | - ); | 307 | + label, |
| 825 | - let publish = if self.desk.can_publish() { | 308 | + Press::Primary, |
| 826 | - publish | 309 | + palette.tokens, |
| 827 | - } else { | 310 | + entity_action(entity, move |yumush, window, cx| { |
| 828 | - publish.opacity(0.4) | 311 | + yumush.publish_release(side, window, cx) |
| 829 | - }; | 312 | + }), |
| 313 | + ); | ||
| 314 | + if self.desk.picked(side).is_some() { | ||
| 315 | + button | ||
| 316 | + } else { | ||
| 317 | + button.opacity(0.4) | ||
| 318 | + } | ||
| 319 | + }); | ||
| 830 | let discard = parts::button( | 320 | let discard = parts::button( |
| 831 | "discard_release", | 321 | "discard_release", |
| 832 | w.discard, | 322 | w.discard, |
| @@ -850,7 +340,7 @@ impl Yumush { | |||
| 850 | .child(self.required_toggle(entity, palette)) | 340 | .child(self.required_toggle(entity, palette)) |
| 851 | .child(div().flex_1()) | 341 | .child(div().flex_1()) |
| 852 | .child(discard) | 342 | .child(discard) |
| 853 | - .child(publish), | 343 | + .children(publish), |
| 854 | ) | 344 | ) |
| 855 | } | 345 | } |
| 856 | 346 | ||
| @@ -894,145 +384,6 @@ impl Yumush { | |||
| 894 | ); | 384 | ); |
| 895 | } | 385 | } |
| 896 | 386 | ||
| 897 | - pub(super) fn pick_release_source(&self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 898 | - let picked = cx.prompt_for_paths(PathPromptOptions { | ||
| 899 | - files: false, | ||
| 900 | - directories: true, | ||
| 901 | - multiple: false, | ||
| 902 | - prompt: None, | ||
| 903 | - }); | ||
| 904 | - | ||
| 905 | - cx.spawn_in(window, async move |this, cx| { | ||
| 906 | - let Ok(Ok(Some(paths))) = picked.await else { | ||
| 907 | - return; | ||
| 908 | - }; | ||
| 909 | - let Some(path) = paths.into_iter().next() else { | ||
| 910 | - return; | ||
| 911 | - }; | ||
| 912 | - if is_source(&path) { | ||
| 913 | - let _ = this.update_in(cx, |yumush, _, cx| { | ||
| 914 | - yumush.settings.release_source = Some(path); | ||
| 915 | - crate::settings::save(&yumush.settings); | ||
| 916 | - cx.notify(); | ||
| 917 | - }); | ||
| 918 | - } else { | ||
| 919 | - notify_error(&this, cx, w().builder_release.not_source); | ||
| 920 | - } | ||
| 921 | - }) | ||
| 922 | - .detach(); | ||
| 923 | - } | ||
| 924 | - | ||
| 925 | - fn start_build(&mut self, side: Side, window: &mut Window, cx: &mut Context<Self>) { | ||
| 926 | - let Some(source) = self.settings.release_source.clone() else { | ||
| 927 | - return; | ||
| 928 | - }; | ||
| 929 | - if self.desk.build.is_some() { | ||
| 930 | - return; | ||
| 931 | - } | ||
| 932 | - let (build, mut events) = Build::start(source, side); | ||
| 933 | - self.desk.build = Some(build); | ||
| 934 | - self.desk.jobs = side | ||
| 935 | - .jobs() | ||
| 936 | - .into_iter() | ||
| 937 | - .map(|job| Row { | ||
| 938 | - job, | ||
| 939 | - phase: Phase::Waiting, | ||
| 940 | - line: String::new(), | ||
| 941 | - log: Vec::new(), | ||
| 942 | - started: None, | ||
| 943 | - ended: None, | ||
| 944 | - }) | ||
| 945 | - .collect(); | ||
| 946 | - self.desk.began = Some(Instant::now()); | ||
| 947 | - self.desk.ended = None; | ||
| 948 | - self.desk.dismissed = false; | ||
| 949 | - self.desk.cancelled = false; | ||
| 950 | - | ||
| 951 | - cx.spawn_in(window, async move |this, cx| { | ||
| 952 | - while let Some(event) = events.recv().await { | ||
| 953 | - if this | ||
| 954 | - .update_in(cx, |yumush, window, cx| { | ||
| 955 | - yumush.build_event(event, window, cx) | ||
| 956 | - }) | ||
| 957 | - .is_err() | ||
| 958 | - { | ||
| 959 | - break; | ||
| 960 | - } | ||
| 961 | - } | ||
| 962 | - }) | ||
| 963 | - .detach(); | ||
| 964 | - cx.spawn_in(window, async move |this, cx| { | ||
| 965 | - loop { | ||
| 966 | - cx.background_executor().timer(TICK).await; | ||
| 967 | - let running = this.update_in(cx, |yumush, window, cx| { | ||
| 968 | - cx.notify(); | ||
| 969 | - window.refresh(); | ||
| 970 | - yumush.desk.build.is_some() | ||
| 971 | - }); | ||
| 972 | - if !matches!(running, Ok(true)) { | ||
| 973 | - break; | ||
| 974 | - } | ||
| 975 | - } | ||
| 976 | - }) | ||
| 977 | - .detach(); | ||
| 978 | - cx.notify(); | ||
| 979 | - } | ||
| 980 | - | ||
| 981 | - fn cancel_build(&mut self, cx: &mut Context<Self>) { | ||
| 982 | - if let Some(build) = &self.desk.build { | ||
| 983 | - build.cancel(); | ||
| 984 | - } | ||
| 985 | - self.desk.cancelled = true; | ||
| 986 | - self.desk.ended = Some(Instant::now()); | ||
| 987 | - cx.notify(); | ||
| 988 | - } | ||
| 989 | - | ||
| 990 | - fn build_event(&mut self, event: Event, window: &mut Window, cx: &mut Context<Self>) { | ||
| 991 | - match event { | ||
| 992 | - Event::Started(job) => self.set_phase(job, Phase::Running { done: 0, total: 0 }), | ||
| 993 | - Event::Progress { job, done, total } => { | ||
| 994 | - self.set_phase(job, Phase::Running { done, total }) | ||
| 995 | - } | ||
| 996 | - Event::Line(job, line) => { | ||
| 997 | - if let Some(row) = self.desk.row(job) { | ||
| 998 | - if row.log.len() >= LOG_MAX { | ||
| 999 | - row.log.drain(..LOG_MAX / 10); | ||
| 1000 | - } | ||
| 1001 | - row.log.push(line.clone()); | ||
| 1002 | - row.line = line; | ||
| 1003 | - } | ||
| 1004 | - } | ||
| 1005 | - Event::Built(_, path) => self.stage_release_file(path, window, cx), | ||
| 1006 | - Event::Finished(job) => self.set_phase(job, Phase::Done), | ||
| 1007 | - Event::Skipped(job, reason) => self.set_phase(job, Phase::Skipped(reason)), | ||
| 1008 | - Event::Failed(job, reason) => { | ||
| 1009 | - if let Some(row) = self.desk.row(job) { | ||
| 1010 | - row.log.push(reason.clone()); | ||
| 1011 | - } | ||
| 1012 | - self.set_phase(job, Phase::Failed(reason)) | ||
| 1013 | - } | ||
| 1014 | - Event::Done => { | ||
| 1015 | - self.desk.build = None; | ||
| 1016 | - self.desk.ended.get_or_insert_with(Instant::now); | ||
| 1017 | - } | ||
| 1018 | - } | ||
| 1019 | - window.refresh(); | ||
| 1020 | - cx.notify(); | ||
| 1021 | - } | ||
| 1022 | - | ||
| 1023 | - fn set_phase(&mut self, job: Job, phase: Phase) { | ||
| 1024 | - let Some(row) = self.desk.row(job) else { | ||
| 1025 | - return; | ||
| 1026 | - }; | ||
| 1027 | - let now = Some(Instant::now()); | ||
| 1028 | - match phase { | ||
| 1029 | - Phase::Running { .. } => row.started = row.started.or(now), | ||
| 1030 | - Phase::Waiting => {} | ||
| 1031 | - Phase::Done | Phase::Skipped(_) | Phase::Failed(_) => row.ended = now, | ||
| 1032 | - } | ||
| 1033 | - row.phase = phase; | ||
| 1034 | - } | ||
| 1035 | - | ||
| 1036 | pub(super) fn pick_release_files(&self, window: &mut Window, cx: &mut Context<Self>) { | 387 | pub(super) fn pick_release_files(&self, window: &mut Window, cx: &mut Context<Self>) { |
| 1037 | let picked = cx.prompt_for_paths(PathPromptOptions { | 388 | let picked = cx.prompt_for_paths(PathPromptOptions { |
| 1038 | files: true, | 389 | files: true, |
| @@ -1110,32 +461,82 @@ impl Yumush { | |||
| 1110 | cx.notify(); | 461 | cx.notify(); |
| 1111 | } | 462 | } |
| 1112 | 463 | ||
| 1113 | - fn publish_release(&mut self, window: &mut Window, cx: &mut Context<Self>) { | 464 | + fn import_release(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 1114 | - if !self.desk.can_publish() { | 465 | + let tag = self |
| 466 | + .release_tag | ||
| 467 | + .read(cx) | ||
| 468 | + .text() | ||
| 469 | + .to_string() | ||
| 470 | + .trim() | ||
| 471 | + .to_string(); | ||
| 472 | + if tag.is_empty() || self.desk.importing.is_some() { | ||
| 1115 | return; | 473 | return; |
| 1116 | } | 474 | } |
| 1117 | - let files = self | 475 | + self.desk.importing = Some(tag.clone()); |
| 1118 | - .desk | 476 | + cx.notify(); |
| 1119 | - .drafts | 477 | + let network = self.network.clone(); |
| 1120 | - .iter() | 478 | + cx.spawn_in(window, async move |this, cx| { |
| 1121 | - .filter_map(|draft| match &draft.stage { | 479 | + if let Err(error) = network.call(ImportRelease { tag }).await { |
| 1122 | - Stage::Ready(staged) => Some(staged.file), | 480 | + let _ = this.update(cx, |yumush, cx| { |
| 1123 | - _ => None, | 481 | + yumush.desk.importing = None; |
| 1124 | - }) | 482 | + cx.notify(); |
| 1125 | - .collect(); | 483 | + }); |
| 484 | + notify_error(&this, cx, error); | ||
| 485 | + } | ||
| 486 | + }) | ||
| 487 | + .detach(); | ||
| 488 | + } | ||
| 489 | + | ||
| 490 | + pub(in crate::gui) fn release_imported( | ||
| 491 | + &mut self, | ||
| 492 | + result: Result<Vec<Staged>, ReleaseProblem>, | ||
| 493 | + window: &mut Window, | ||
| 494 | + cx: &mut Context<Self>, | ||
| 495 | + ) { | ||
| 496 | + self.desk.importing = None; | ||
| 497 | + match result { | ||
| 498 | + Ok(staged) if staged.is_empty() => { | ||
| 499 | + window.push_notification(Notification::info(w().builder_release.nothing_new), cx) | ||
| 500 | + } | ||
| 501 | + Ok(staged) => { | ||
| 502 | + for staged in staged { | ||
| 503 | + let id = self.desk.next; | ||
| 504 | + self.desk.next += 1; | ||
| 505 | + self.desk.drafts.push(Draft { | ||
| 506 | + id, | ||
| 507 | + name: staged.target.clone(), | ||
| 508 | + size: staged.size, | ||
| 509 | + stage: Stage::Ready(staged), | ||
| 510 | + }); | ||
| 511 | + } | ||
| 512 | + } | ||
| 513 | + Err(problem) => window.push_notification(Notification::error(problem.to_string()), cx), | ||
| 514 | + } | ||
| 515 | + cx.notify(); | ||
| 516 | + } | ||
| 517 | + | ||
| 518 | + fn publish_release(&mut self, side: Side, window: &mut Window, cx: &mut Context<Self>) { | ||
| 519 | + let Some(files) = self.desk.picked(side) else { | ||
| 520 | + return; | ||
| 521 | + }; | ||
| 1126 | let required = self.desk.required; | 522 | let required = self.desk.required; |
| 1127 | self.desk.publishing = true; | 523 | self.desk.publishing = true; |
| 1128 | cx.notify(); | 524 | cx.notify(); |
| 1129 | let network = self.network.clone(); | 525 | let network = self.network.clone(); |
| 1130 | 526 | ||
| 1131 | cx.spawn_in(window, async move |this, cx| { | 527 | cx.spawn_in(window, async move |this, cx| { |
| 1132 | - match network.call(PublishRelease { files, required }).await { | 528 | + let call = PublishRelease { |
| 529 | + files: files.clone(), | ||
| 530 | + required, | ||
| 531 | + }; | ||
| 532 | + match network.call(call).await { | ||
| 1133 | Ok(_) => { | 533 | Ok(_) => { |
| 1134 | let _ = this.update_in(cx, |yumush, window, cx| { | 534 | let _ = this.update_in(cx, |yumush, window, cx| { |
| 1135 | - yumush.desk.drafts.clear(); | 535 | + yumush.desk.drafts.retain(|draft| { |
| 536 | + !matches!(&draft.stage, Stage::Ready(staged) if files.contains(&staged.file)) | ||
| 537 | + }); | ||
| 1136 | yumush.desk.required = false; | 538 | yumush.desk.required = false; |
| 1137 | yumush.desk.publishing = false; | 539 | yumush.desk.publishing = false; |
| 1138 | - yumush.desk.dismissed = true; | ||
| 1139 | yumush.load_releases(window, cx); | 540 | yumush.load_releases(window, cx); |
| 1140 | }); | 541 | }); |
| 1141 | } | 542 | } |
crates/client/src/gui/chat.rsmodified+4 -1
| @@ -807,7 +807,10 @@ impl Chat { | |||
| 807 | followed.1 = stats; | 807 | followed.1 = stats; |
| 808 | } | 808 | } |
| 809 | } | 809 | } |
| 810 | - Event::ReportCreated | Event::SettingsUpdated(_) | Event::Release => {} | 810 | + Event::ReportCreated |
| 811 | + | Event::SettingsUpdated(_) | ||
| 812 | + | Event::Release | ||
| 813 | + | Event::Imported { .. } => {} | ||
| 811 | } | 814 | } |
| 812 | } | 815 | } |
| 813 | 816 | ||
crates/client/src/gui/sidebar.rsmodified+0 -1
| @@ -217,7 +217,6 @@ impl Yumush { | |||
| 217 | |list, f| fade(list, f).flex_1().min_h_0(), | 217 | |list, f| fade(list, f).flex_1().min_h_0(), |
| 218 | ), | 218 | ), |
| 219 | ) | 219 | ) |
| 220 | - .children(self.build_control(entity, palette)) | ||
| 221 | .children(self.account_row(entity, palette)) | 220 | .children(self.account_row(entity, palette)) |
| 222 | .into_any_element() | 221 | .into_any_element() |
| 223 | } | 222 | } |
crates/client/src/lib.rsmodified+0 -1
| @@ -15,7 +15,6 @@ pub mod logo; | |||
| 15 | pub mod marks; | 15 | pub mod marks; |
| 16 | pub mod media; | 16 | pub mod media; |
| 17 | pub mod net; | 17 | pub mod net; |
| 18 | -pub mod release; | ||
| 19 | pub mod settings; | 18 | pub mod settings; |
| 20 | pub mod share; | 19 | pub mod share; |
| 21 | pub mod storage; | 20 | pub mod storage; |
crates/client/src/release.rsdeleted+0 -511
| @@ -1,511 +0,0 @@ | |||
| 1 | -use std::fs; | ||
| 2 | -use std::io::{BufReader, Read}; | ||
| 3 | -use std::path::{Path, PathBuf}; | ||
| 4 | -use std::process::{Child, Command, ExitStatus, Stdio}; | ||
| 5 | -use std::sync::atomic::{AtomicBool, Ordering}; | ||
| 6 | -use std::sync::{Arc, Mutex}; | ||
| 7 | -use std::thread; | ||
| 8 | -use std::time::Duration; | ||
| 9 | - | ||
| 10 | -use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel}; | ||
| 11 | - | ||
| 12 | -#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 13 | -pub enum Level { | ||
| 14 | - V1, | ||
| 15 | - V3, | ||
| 16 | -} | ||
| 17 | - | ||
| 18 | -#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 19 | -pub enum Job { | ||
| 20 | - Prepare, | ||
| 21 | - Server, | ||
| 22 | - Linux(Level), | ||
| 23 | - Windows(Level), | ||
| 24 | -} | ||
| 25 | - | ||
| 26 | -#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 27 | -pub enum Side { | ||
| 28 | - Server, | ||
| 29 | - Client, | ||
| 30 | - Both, | ||
| 31 | -} | ||
| 32 | - | ||
| 33 | -impl Side { | ||
| 34 | - pub fn jobs(self) -> Vec<Job> { | ||
| 35 | - let server = matches!(self, Side::Server | Side::Both); | ||
| 36 | - let client = matches!(self, Side::Client | Side::Both); | ||
| 37 | - let mut jobs = vec![Job::Prepare]; | ||
| 38 | - if server { | ||
| 39 | - jobs.push(Job::Server); | ||
| 40 | - } | ||
| 41 | - if client { | ||
| 42 | - jobs.extend([ | ||
| 43 | - Job::Linux(Level::V1), | ||
| 44 | - Job::Linux(Level::V3), | ||
| 45 | - Job::Windows(Level::V1), | ||
| 46 | - Job::Windows(Level::V3), | ||
| 47 | - ]); | ||
| 48 | - } | ||
| 49 | - jobs | ||
| 50 | - } | ||
| 51 | -} | ||
| 52 | - | ||
| 53 | -type Slot = Arc<Mutex<Option<Child>>>; | ||
| 54 | - | ||
| 55 | -#[derive(Debug, Clone, PartialEq)] | ||
| 56 | -pub enum Event { | ||
| 57 | - Started(Job), | ||
| 58 | - Progress { job: Job, done: u32, total: u32 }, | ||
| 59 | - Line(Job, String), | ||
| 60 | - Built(Job, PathBuf), | ||
| 61 | - Finished(Job), | ||
| 62 | - Skipped(Job, String), | ||
| 63 | - Failed(Job, String), | ||
| 64 | - Done, | ||
| 65 | -} | ||
| 66 | - | ||
| 67 | -const LINUX: &str = "yumush-linux"; | ||
| 68 | -const LINUX_IMAGE: &str = "docker.io/library/ubuntu:24.04"; | ||
| 69 | -const LINUX_CACHE: &str = ".cache/yumush-build"; | ||
| 70 | -const LINUX_READY: &str = "/etc/yumush-ready-2"; | ||
| 71 | -const LINUX_PACKAGES: &str = "ca-certificates curl git build-essential pkg-config clang lld llvm cmake nasm libpipewire-0.3-dev libspa-0.2-dev libva-dev libdrm-dev libgbm-dev libxkbcommon-x11-dev libxkbcommon-dev libxcb1-dev libwayland-dev libvulkan-dev libfontconfig-dev libfreetype-dev libasound2-dev"; | ||
| 72 | -const WINDOWS_TARGET: &str = "x86_64-pc-windows-msvc"; | ||
| 73 | -const SHADERS: &str = "crates/client/src/release/shaders_bytes.rs"; | ||
| 74 | -const SHADERS_SUM: &str = "crates/client/src/release/shaders.sha256"; | ||
| 75 | -const ARCHIVE: &str = "dist/source.tgz"; | ||
| 76 | - | ||
| 77 | -static RUNNING: AtomicBool = AtomicBool::new(false); | ||
| 78 | - | ||
| 79 | -pub fn running() -> bool { | ||
| 80 | - RUNNING.load(Ordering::SeqCst) | ||
| 81 | -} | ||
| 82 | - | ||
| 83 | -struct Running; | ||
| 84 | - | ||
| 85 | -impl Running { | ||
| 86 | - fn new() -> Self { | ||
| 87 | - RUNNING.store(true, Ordering::SeqCst); | ||
| 88 | - Self | ||
| 89 | - } | ||
| 90 | -} | ||
| 91 | - | ||
| 92 | -impl Drop for Running { | ||
| 93 | - fn drop(&mut self) { | ||
| 94 | - RUNNING.store(false, Ordering::SeqCst); | ||
| 95 | - } | ||
| 96 | -} | ||
| 97 | - | ||
| 98 | -pub fn is_source(path: &Path) -> bool { | ||
| 99 | - path.join("crates/client/Cargo.toml").is_file() && path.join(".git").exists() | ||
| 100 | -} | ||
| 101 | - | ||
| 102 | -pub struct Build { | ||
| 103 | - cancel: Arc<AtomicBool>, | ||
| 104 | - child: Slot, | ||
| 105 | - retry: Arc<AtomicBool>, | ||
| 106 | -} | ||
| 107 | - | ||
| 108 | -impl Build { | ||
| 109 | - pub fn start(source: PathBuf, side: Side) -> (Self, UnboundedReceiver<Event>) { | ||
| 110 | - let (tx, rx) = unbounded_channel(); | ||
| 111 | - let build = Self { | ||
| 112 | - cancel: Arc::default(), | ||
| 113 | - child: Slot::default(), | ||
| 114 | - retry: Arc::default(), | ||
| 115 | - }; | ||
| 116 | - let cx = Cx { | ||
| 117 | - tx, | ||
| 118 | - cancel: build.cancel.clone(), | ||
| 119 | - child: build.child.clone(), | ||
| 120 | - retry: build.retry.clone(), | ||
| 121 | - }; | ||
| 122 | - let running = Running::new(); | ||
| 123 | - thread::spawn(move || { | ||
| 124 | - let _running = running; | ||
| 125 | - run(&source, &side.jobs(), &cx); | ||
| 126 | - }); | ||
| 127 | - (build, rx) | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - pub fn retry(&self) { | ||
| 131 | - self.retry.store(true, Ordering::SeqCst); | ||
| 132 | - } | ||
| 133 | - | ||
| 134 | - pub fn cancel(&self) { | ||
| 135 | - self.cancel.store(true, Ordering::SeqCst); | ||
| 136 | - podman_ok(&["stop", "-t", "2", LINUX]); | ||
| 137 | - if let Some(child) = self.child.lock().unwrap().as_mut() { | ||
| 138 | - let _ = child.kill(); | ||
| 139 | - } | ||
| 140 | - } | ||
| 141 | -} | ||
| 142 | - | ||
| 143 | -#[derive(Clone)] | ||
| 144 | -struct Cx { | ||
| 145 | - tx: UnboundedSender<Event>, | ||
| 146 | - cancel: Arc<AtomicBool>, | ||
| 147 | - child: Slot, | ||
| 148 | - retry: Arc<AtomicBool>, | ||
| 149 | -} | ||
| 150 | - | ||
| 151 | -impl Cx { | ||
| 152 | - fn wait_retry(&self) -> bool { | ||
| 153 | - while !self.cancelled() { | ||
| 154 | - if self.retry.swap(false, Ordering::SeqCst) { | ||
| 155 | - return true; | ||
| 156 | - } | ||
| 157 | - thread::sleep(Duration::from_millis(200)); | ||
| 158 | - } | ||
| 159 | - false | ||
| 160 | - } | ||
| 161 | - | ||
| 162 | - fn send(&self, event: Event) { | ||
| 163 | - let _ = self.tx.send(event); | ||
| 164 | - } | ||
| 165 | - | ||
| 166 | - fn cancelled(&self) -> bool { | ||
| 167 | - self.cancel.load(Ordering::SeqCst) | ||
| 168 | - } | ||
| 169 | -} | ||
| 170 | - | ||
| 171 | -fn run(source: &Path, jobs: &[Job], cx: &Cx) { | ||
| 172 | - let prepared = lock().and_then(|lock| preflight(source).map(|()| lock)); | ||
| 173 | - match prepared { | ||
| 174 | - Ok(_lock) => { | ||
| 175 | - run_jobs(jobs, source, cx); | ||
| 176 | - podman_ok(&["stop", "-t", "2", LINUX]); | ||
| 177 | - } | ||
| 178 | - Err(e) => cx.send(Event::Failed(jobs[0], e)), | ||
| 179 | - } | ||
| 180 | - cx.send(Event::Done); | ||
| 181 | -} | ||
| 182 | - | ||
| 183 | -fn run_jobs(jobs: &[Job], source: &Path, cx: &Cx) { | ||
| 184 | - let mut next = 0; | ||
| 185 | - while let Some(&job) = jobs.get(next) { | ||
| 186 | - if cx.cancelled() { | ||
| 187 | - cx.send(Event::Failed(job, "cancelled".into())); | ||
| 188 | - return; | ||
| 189 | - } | ||
| 190 | - match run_job(job, source, cx) { | ||
| 191 | - Ok(()) => next += 1, | ||
| 192 | - Err(_) if cx.cancelled() => { | ||
| 193 | - cx.send(Event::Failed(job, "cancelled".into())); | ||
| 194 | - return; | ||
| 195 | - } | ||
| 196 | - Err(e) => { | ||
| 197 | - cx.send(Event::Failed(job, e)); | ||
| 198 | - if !cx.wait_retry() { | ||
| 199 | - return; | ||
| 200 | - } | ||
| 201 | - } | ||
| 202 | - } | ||
| 203 | - } | ||
| 204 | -} | ||
| 205 | - | ||
| 206 | -fn lock() -> Result<fs::File, String> { | ||
| 207 | - let cache = linux_cache(); | ||
| 208 | - fs::create_dir_all(&cache).map_err(|e| e.to_string())?; | ||
| 209 | - let file = fs::File::create(cache.join("build.lock")).map_err(|e| e.to_string())?; | ||
| 210 | - file.try_lock() | ||
| 211 | - .map_err(|_| "another build is running".to_string())?; | ||
| 212 | - Ok(file) | ||
| 213 | -} | ||
| 214 | - | ||
| 215 | -fn preflight(source: &Path) -> Result<(), String> { | ||
| 216 | - let dirty = Command::new("git") | ||
| 217 | - .arg("-C") | ||
| 218 | - .arg(source) | ||
| 219 | - .args(["status", "--porcelain"]) | ||
| 220 | - .output() | ||
| 221 | - .map_err(|e| e.to_string())?; | ||
| 222 | - if !dirty.stdout.is_empty() { | ||
| 223 | - return Err("uncommitted changes".into()); | ||
| 224 | - } | ||
| 225 | - snapshot(source) | ||
| 226 | -} | ||
| 227 | - | ||
| 228 | -fn run_job(job: Job, source: &Path, cx: &Cx) -> Result<(), String> { | ||
| 229 | - if !cfg!(target_os = "linux") { | ||
| 230 | - return skip(cx, job, "not linux"); | ||
| 231 | - } | ||
| 232 | - cx.send(Event::Started(job)); | ||
| 233 | - match job { | ||
| 234 | - Job::Prepare => prepare(job, source, cx), | ||
| 235 | - Job::Server => build_server(job, source, cx), | ||
| 236 | - Job::Linux(level) => build_linux(job, level, source, cx), | ||
| 237 | - Job::Windows(level) => build_windows(job, level, source, cx), | ||
| 238 | - } | ||
| 239 | -} | ||
| 240 | - | ||
| 241 | -fn skip(cx: &Cx, job: Job, why: &str) -> Result<(), String> { | ||
| 242 | - cx.send(Event::Skipped(job, why.into())); | ||
| 243 | - Ok(()) | ||
| 244 | -} | ||
| 245 | - | ||
| 246 | -fn flags(level: Level) -> (&'static str, &'static str) { | ||
| 247 | - match level { | ||
| 248 | - Level::V1 => ("v1", "x86-64"), | ||
| 249 | - Level::V3 => ("v3", "x86-64-v3"), | ||
| 250 | - } | ||
| 251 | -} | ||
| 252 | - | ||
| 253 | -fn snapshot(source: &Path) -> Result<(), String> { | ||
| 254 | - fs::create_dir_all(source.join("dist")).map_err(|e| e.to_string())?; | ||
| 255 | - check( | ||
| 256 | - Command::new("git") | ||
| 257 | - .arg("-C") | ||
| 258 | - .arg(source) | ||
| 259 | - .args(["archive", "--format=tar.gz", "-o"]) | ||
| 260 | - .arg(source.join(ARCHIVE)) | ||
| 261 | - .arg("HEAD"), | ||
| 262 | - ) | ||
| 263 | -} | ||
| 264 | - | ||
| 265 | -fn linux_cache() -> PathBuf { | ||
| 266 | - dirs::home_dir().unwrap_or_default().join(LINUX_CACHE) | ||
| 267 | -} | ||
| 268 | - | ||
| 269 | -fn host_rust() -> Result<String, String> { | ||
| 270 | - let out = Command::new("rustc") | ||
| 271 | - .arg("--version") | ||
| 272 | - .output() | ||
| 273 | - .map_err(|e| e.to_string())?; | ||
| 274 | - String::from_utf8_lossy(&out.stdout) | ||
| 275 | - .split_whitespace() | ||
| 276 | - .nth(1) | ||
| 277 | - .map(str::to_string) | ||
| 278 | - .ok_or_else(|| "rustc version unknown".to_string()) | ||
| 279 | -} | ||
| 280 | - | ||
| 281 | -fn in_linux(script: &str) -> Command { | ||
| 282 | - let mut cmd = podman(); | ||
| 283 | - cmd.args(["exec", "-w", "/build"]) | ||
| 284 | - .args(["-e", "PATH=/root/.cargo/bin:/usr/local/bin:/usr/bin:/bin"]) | ||
| 285 | - .args(["-e", "DEBIAN_FRONTEND=noninteractive"]) | ||
| 286 | - .args(["-e", "CARGO_TERM_PROGRESS_WHEN=always"]) | ||
| 287 | - .args(["-e", "CARGO_TERM_PROGRESS_WIDTH=200"]) | ||
| 288 | - .args(["-e", "CARGO_TERM_COLOR=never"]) | ||
| 289 | - .args([LINUX, "bash", "-ec", script]) | ||
| 290 | - .stdout(Stdio::piped()); | ||
| 291 | - cmd | ||
| 292 | -} | ||
| 293 | - | ||
| 294 | -fn prepare(job: Job, source: &Path, cx: &Cx) -> Result<(), String> { | ||
| 295 | - let cache = linux_cache(); | ||
| 296 | - for dir in ["cargo", "rustup", "target"] { | ||
| 297 | - fs::create_dir_all(cache.join(dir)).map_err(|e| e.to_string())?; | ||
| 298 | - } | ||
| 299 | - if !podman_ok(&["container", "exists", LINUX]) { | ||
| 300 | - cx.send(Event::Line(job, "creating container".into())); | ||
| 301 | - let mount = |dir: &str, at: &str| format!("{}:{at}:Z", cache.join(dir).display()); | ||
| 302 | - check( | ||
| 303 | - podman() | ||
| 304 | - .args(["run", "-d", "--name", LINUX]) | ||
| 305 | - .args(["-v", &mount("cargo", "/root/.cargo")]) | ||
| 306 | - .args(["-v", &mount("rustup", "/root/.rustup")]) | ||
| 307 | - .args(["-v", &mount("target", "/build/target")]) | ||
| 308 | - .args([LINUX_IMAGE, "sleep", "infinity"]), | ||
| 309 | - )?; | ||
| 310 | - } else { | ||
| 311 | - check(podman().args(["start", LINUX]))?; | ||
| 312 | - } | ||
| 313 | - check( | ||
| 314 | - podman() | ||
| 315 | - .arg("cp") | ||
| 316 | - .arg(source.join(ARCHIVE)) | ||
| 317 | - .arg(format!("{LINUX}:/build/src.tgz")), | ||
| 318 | - )?; | ||
| 319 | - let rust = host_rust()?; | ||
| 320 | - let script = format!( | ||
| 321 | - "[ -f {LINUX_READY} ] || {{ apt-get update; apt-get install -y --no-install-recommends {LINUX_PACKAGES}; touch {LINUX_READY}; }} | ||
| 322 | -[ -x /root/.cargo/bin/rustup ] || curl -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain none | ||
| 323 | -rustup toolchain install {rust} --profile minimal --target {WINDOWS_TARGET} | ||
| 324 | -rustup default {rust} | ||
| 325 | -command -v cargo-xwin >/dev/null || cargo install cargo-xwin --locked | ||
| 326 | -rm -rf src && mkdir src && tar -xmzf src.tgz -C src" | ||
| 327 | - ); | ||
| 328 | - stream(&mut in_linux(&script), job, cx)?; | ||
| 329 | - cx.send(Event::Finished(job)); | ||
| 330 | - Ok(()) | ||
| 331 | -} | ||
| 332 | - | ||
| 333 | -fn build_in_linux( | ||
| 334 | - job: Job, | ||
| 335 | - package: &str, | ||
| 336 | - level: Level, | ||
| 337 | - dest: &str, | ||
| 338 | - source: &Path, | ||
| 339 | - cx: &Cx, | ||
| 340 | -) -> Result<(), String> { | ||
| 341 | - let (name, cpu) = flags(level); | ||
| 342 | - let script = format!( | ||
| 343 | - "cd src | ||
| 344 | -rm -f /build/target/release-{name}/release/{package} | ||
| 345 | -cargo build --release -p {package} --target-dir /build/target/release-{name} --config 'target.x86_64-unknown-linux-gnu.rustflags=[\"-C\", \"target-cpu={cpu}\"]'" | ||
| 346 | - ); | ||
| 347 | - stream(&mut in_linux(&script), job, cx)?; | ||
| 348 | - let built = linux_cache().join(format!("target/release-{name}/release/{package}")); | ||
| 349 | - let dest = source.join("dist").join(dest); | ||
| 350 | - fs::copy(&built, &dest).map_err(|e| e.to_string())?; | ||
| 351 | - cx.send(Event::Built(job, dest)); | ||
| 352 | - cx.send(Event::Finished(job)); | ||
| 353 | - Ok(()) | ||
| 354 | -} | ||
| 355 | - | ||
| 356 | -fn build_linux(job: Job, level: Level, source: &Path, cx: &Cx) -> Result<(), String> { | ||
| 357 | - let (name, _) = flags(level); | ||
| 358 | - build_in_linux( | ||
| 359 | - job, | ||
| 360 | - "client", | ||
| 361 | - level, | ||
| 362 | - &format!("x86_64_{name}-linux"), | ||
| 363 | - source, | ||
| 364 | - cx, | ||
| 365 | - ) | ||
| 366 | -} | ||
| 367 | - | ||
| 368 | -fn build_server(job: Job, source: &Path, cx: &Cx) -> Result<(), String> { | ||
| 369 | - build_in_linux( | ||
| 370 | - job, | ||
| 371 | - "server", | ||
| 372 | - Level::V1, | ||
| 373 | - common::update::SERVER_TARGET, | ||
| 374 | - source, | ||
| 375 | - cx, | ||
| 376 | - ) | ||
| 377 | -} | ||
| 378 | - | ||
| 379 | -fn build_windows(job: Job, level: Level, source: &Path, cx: &Cx) -> Result<(), String> { | ||
| 380 | - let (name, cpu) = flags(level); | ||
| 381 | - let out = format!("release-{name}/{WINDOWS_TARGET}/release/client.exe"); | ||
| 382 | - let script = format!( | ||
| 383 | - "cd src | ||
| 384 | -sha256sum -c --quiet {SHADERS_SUM} | ||
| 385 | -rm -f /build/target/{out} | ||
| 386 | -export XWIN_ACCEPT_LICENSE=1 XWIN_CACHE_DIR=/root/.cargo/xwin GPUI_SHADERS_BYTES=$PWD/{SHADERS} | ||
| 387 | -export CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS='-C target-cpu={cpu}' | ||
| 388 | -cargo xwin build --release -p client --target {WINDOWS_TARGET} --target-dir /build/target/release-{name}" | ||
| 389 | - ); | ||
| 390 | - stream(&mut in_linux(&script), job, cx)?; | ||
| 391 | - let dest = source.join("dist").join(format!("x86_64_{name}-windows")); | ||
| 392 | - fs::copy(linux_cache().join("target").join(&out), &dest).map_err(|e| e.to_string())?; | ||
| 393 | - cx.send(Event::Built(job, dest)); | ||
| 394 | - cx.send(Event::Finished(job)); | ||
| 395 | - Ok(()) | ||
| 396 | -} | ||
| 397 | - | ||
| 398 | -fn podman() -> Command { | ||
| 399 | - let mut cmd = Command::new("podman"); | ||
| 400 | - if let Some(runtime) = std::env::var_os("XDG_RUNTIME_DIR") { | ||
| 401 | - let mut bus = std::ffi::OsString::from("unix:path="); | ||
| 402 | - bus.push(runtime); | ||
| 403 | - bus.push("/bus"); | ||
| 404 | - cmd.env("DBUS_SESSION_BUS_ADDRESS", bus); | ||
| 405 | - } | ||
| 406 | - cmd | ||
| 407 | -} | ||
| 408 | - | ||
| 409 | -fn podman_ok(args: &[&str]) -> bool { | ||
| 410 | - podman() | ||
| 411 | - .args(args) | ||
| 412 | - .stdout(Stdio::null()) | ||
| 413 | - .stderr(Stdio::null()) | ||
| 414 | - .status() | ||
| 415 | - .is_ok_and(|s| s.success()) | ||
| 416 | -} | ||
| 417 | - | ||
| 418 | -fn check(cmd: &mut Command) -> Result<(), String> { | ||
| 419 | - let out = cmd.output().map_err(|e| e.to_string())?; | ||
| 420 | - if out.status.success() { | ||
| 421 | - Ok(()) | ||
| 422 | - } else { | ||
| 423 | - let stderr = String::from_utf8_lossy(&out.stderr); | ||
| 424 | - Err(stderr | ||
| 425 | - .lines() | ||
| 426 | - .rev() | ||
| 427 | - .find(|line| !line.trim().is_empty()) | ||
| 428 | - .unwrap_or_default() | ||
| 429 | - .trim() | ||
| 430 | - .to_string()) | ||
| 431 | - } | ||
| 432 | -} | ||
| 433 | - | ||
| 434 | -fn stream(cmd: &mut Command, job: Job, cx: &Cx) -> Result<(), String> { | ||
| 435 | - let mut child = cmd | ||
| 436 | - .stderr(Stdio::piped()) | ||
| 437 | - .spawn() | ||
| 438 | - .map_err(|e| e.to_string())?; | ||
| 439 | - let stdout = child.stdout.take(); | ||
| 440 | - let stderr = child.stderr.take(); | ||
| 441 | - *cx.child.lock().unwrap() = Some(child); | ||
| 442 | - let out = stdout.map(|o| { | ||
| 443 | - let cx = cx.clone(); | ||
| 444 | - thread::spawn(move || pump(o, job, &cx)) | ||
| 445 | - }); | ||
| 446 | - let err = stderr.map(|e| pump(e, job, cx)).unwrap_or_default(); | ||
| 447 | - if let Some(out) = out { | ||
| 448 | - let _ = out.join(); | ||
| 449 | - } | ||
| 450 | - let status = wait(cx)?; | ||
| 451 | - if status.success() { | ||
| 452 | - return Ok(()); | ||
| 453 | - } | ||
| 454 | - Err(if err.is_empty() { | ||
| 455 | - format!("exit {status}") | ||
| 456 | - } else { | ||
| 457 | - err | ||
| 458 | - }) | ||
| 459 | -} | ||
| 460 | - | ||
| 461 | -fn wait(cx: &Cx) -> Result<ExitStatus, String> { | ||
| 462 | - loop { | ||
| 463 | - let mut slot = cx.child.lock().unwrap(); | ||
| 464 | - if cx.cancelled() | ||
| 465 | - && let Some(child) = slot.as_mut() | ||
| 466 | - { | ||
| 467 | - let _ = child.kill(); | ||
| 468 | - } | ||
| 469 | - let Some(child) = slot.as_mut() else { | ||
| 470 | - return Err("no child".into()); | ||
| 471 | - }; | ||
| 472 | - if let Some(status) = child.try_wait().map_err(|e| e.to_string())? { | ||
| 473 | - return Ok(status); | ||
| 474 | - } | ||
| 475 | - drop(slot); | ||
| 476 | - thread::sleep(Duration::from_millis(100)); | ||
| 477 | - } | ||
| 478 | -} | ||
| 479 | - | ||
| 480 | -fn pump(reader: impl Read, job: Job, cx: &Cx) -> String { | ||
| 481 | - let mut last = String::new(); | ||
| 482 | - let mut piece = Vec::new(); | ||
| 483 | - for byte in BufReader::new(reader) | ||
| 484 | - .bytes() | ||
| 485 | - .map_while(Result::ok) | ||
| 486 | - .chain(*b"\n") | ||
| 487 | - { | ||
| 488 | - if byte != b'\r' && byte != b'\n' { | ||
| 489 | - piece.push(byte); | ||
| 490 | - continue; | ||
| 491 | - } | ||
| 492 | - let text = String::from_utf8_lossy(&piece).trim().to_string(); | ||
| 493 | - piece.clear(); | ||
| 494 | - if text.is_empty() { | ||
| 495 | - continue; | ||
| 496 | - } | ||
| 497 | - cx.send(progress(job, &text).unwrap_or_else(|| Event::Line(job, text.clone()))); | ||
| 498 | - last = text; | ||
| 499 | - } | ||
| 500 | - last | ||
| 501 | -} | ||
| 502 | - | ||
| 503 | -fn progress(job: Job, text: &str) -> Option<Event> { | ||
| 504 | - let rest = text.split_once("Building [")?.1.split_once(']')?.1; | ||
| 505 | - let (done, total) = rest.trim_start().split(':').next()?.split_once('/')?; | ||
| 506 | - Some(Event::Progress { | ||
| 507 | - job, | ||
| 508 | - done: done.trim().parse().ok()?, | ||
| 509 | - total: total.trim().parse().ok()?, | ||
| 510 | - }) | ||
| 511 | -} | ||
crates/client/src/settings.rsmodified+1 -12
| @@ -1,4 +1,4 @@ | |||
| 1 | -use std::{collections::BTreeMap, fmt::Display, ops::RangeInclusive, path::PathBuf}; | 1 | +use std::{collections::BTreeMap, fmt::Display, ops::RangeInclusive}; |
| 2 | 2 | ||
| 3 | use common::{ | 3 | use common::{ |
| 4 | config::Config, | 4 | config::Config, |
| @@ -224,7 +224,6 @@ pub struct Settings { | |||
| 224 | pub clock_seconds: bool, | 224 | pub clock_seconds: bool, |
| 225 | pub jump_usage: BTreeMap<String, u32>, | 225 | pub jump_usage: BTreeMap<String, u32>, |
| 226 | pub last_chats: BTreeMap<Id, Id>, | 226 | pub last_chats: BTreeMap<Id, Id>, |
| 227 | - pub release_source: Option<PathBuf>, | ||
| 228 | } | 227 | } |
| 229 | 228 | ||
| 230 | impl Settings { | 229 | impl Settings { |
| @@ -254,7 +253,6 @@ impl Default for Settings { | |||
| 254 | clock_seconds: false, | 253 | clock_seconds: false, |
| 255 | jump_usage: BTreeMap::new(), | 254 | jump_usage: BTreeMap::new(), |
| 256 | last_chats: BTreeMap::new(), | 255 | last_chats: BTreeMap::new(), |
| 257 | - release_source: None, | ||
| 258 | } | 256 | } |
| 259 | } | 257 | } |
| 260 | } | 258 | } |
| @@ -390,7 +388,6 @@ pub fn load() -> Settings { | |||
| 390 | .collect() | 388 | .collect() |
| 391 | }) | 389 | }) |
| 392 | .unwrap_or_default(), | 390 | .unwrap_or_default(), |
| 393 | - release_source: text("release.source").map(PathBuf::from), | ||
| 394 | } | 391 | } |
| 395 | } | 392 | } |
| 396 | 393 | ||
| @@ -472,14 +469,6 @@ pub fn save(settings: &Settings) { | |||
| 472 | .collect::<Vec<_>>() | 469 | .collect::<Vec<_>>() |
| 473 | .join("\t"), | 470 | .join("\t"), |
| 474 | ), | 471 | ), |
| 475 | - line( | ||
| 476 | - "release.source", | ||
| 477 | - settings | ||
| 478 | - .release_source | ||
| 479 | - .as_ref() | ||
| 480 | - .map(|path| path.display().to_string()) | ||
| 481 | - .unwrap_or_default(), | ||
| 482 | - ), | ||
| 483 | line( | 472 | line( |
| 484 | "last_chats", | 473 | "last_chats", |
| 485 | settings | 474 | settings |
crates/client/src/update.rsmodified+0 -4
| @@ -15,7 +15,6 @@ pub const RESTART: &str = "--restart"; | |||
| 15 | pub const TARGET: &str = env!("YUMUSH_TARGET"); | 15 | pub const TARGET: &str = env!("YUMUSH_TARGET"); |
| 16 | const MARK: &str = concat!("yumush-target:", env!("YUMUSH_TARGET"), ";"); | 16 | const MARK: &str = concat!("yumush-target:", env!("YUMUSH_TARGET"), ";"); |
| 17 | const CHUNK: usize = 256 << 10; | 17 | const CHUNK: usize = 256 << 10; |
| 18 | -const BUILD_WAIT: std::time::Duration = std::time::Duration::from_secs(1); | ||
| 19 | 18 | ||
| 20 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 19 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 21 | pub enum Phase { | 20 | pub enum Phase { |
| @@ -262,9 +261,6 @@ pub fn install() { | |||
| 262 | }; | 261 | }; |
| 263 | runtime.block_on(report(&server, me, progress)); | 262 | runtime.block_on(report(&server, me, progress)); |
| 264 | if progress == Progress::Ready && offer.required { | 263 | if progress == Progress::Ready && offer.required { |
| 265 | - while crate::release::running() { | ||
| 266 | - std::thread::sleep(BUILD_WAIT); | ||
| 267 | - } | ||
| 268 | restart(); | 264 | restart(); |
| 269 | } | 265 | } |
| 270 | }); | 266 | }); |
crates/common/src/call.rsmodified+6 -0
| @@ -639,6 +639,11 @@ pub struct PublishRelease { | |||
| 639 | pub required: bool, | 639 | pub required: bool, |
| 640 | } | 640 | } |
| 641 | 641 | ||
| 642 | +#[derive(Debug, Clone, Encode, Decode)] | ||
| 643 | +pub struct ImportRelease { | ||
| 644 | + pub tag: String, | ||
| 645 | +} | ||
| 646 | + | ||
| 642 | #[derive(Debug, Clone, Encode, Decode)] | 647 | #[derive(Debug, Clone, Encode, Decode)] |
| 643 | pub struct SetReleaseRequired { | 648 | pub struct SetReleaseRequired { |
| 644 | pub seq: u64, | 649 | pub seq: u64, |
| @@ -790,6 +795,7 @@ calls! { | |||
| 790 | ListReleases: Builder -> Vec<ReleaseInfo>; | 795 | ListReleases: Builder -> Vec<ReleaseInfo>; |
| 791 | ListUpdateClients: Builder -> Vec<UpdateClient>; | 796 | ListUpdateClients: Builder -> Vec<UpdateClient>; |
| 792 | PublishRelease: Builder -> ReleaseInfo; | 797 | PublishRelease: Builder -> ReleaseInfo; |
| 798 | + ImportRelease: Builder -> (); | ||
| 793 | SetReleaseRequired: Builder -> (); | 799 | SetReleaseRequired: Builder -> (); |
| 794 | FollowStats: Builder -> Option<Stats>; | 800 | FollowStats: Builder -> Option<Stats>; |
| 795 | PushStats: User -> (); | 801 | PushStats: User -> (); |
crates/common/src/error.rsmodified+6 -0
| @@ -169,4 +169,10 @@ pub enum ReleaseProblem { | |||
| 169 | ServerBroken, | 169 | ServerBroken, |
| 170 | #[error("a protocol change needs the server and every client in one release")] | 170 | #[error("a protocol change needs the server and every client in one release")] |
| 171 | ProtocolSplit, | 171 | ProtocolSplit, |
| 172 | + #[error("the server has no forge set")] | ||
| 173 | + NoForge, | ||
| 174 | + #[error("forge could not be reached or has no such release")] | ||
| 175 | + Forge, | ||
| 176 | + #[error("a downloaded file does not match its checksum")] | ||
| 177 | + Checksum, | ||
| 172 | } | 178 | } |
crates/common/src/event.rsmodified+4 -0
| @@ -87,6 +87,10 @@ pub enum Event { | |||
| 87 | stats: Stats, | 87 | stats: Stats, |
| 88 | }, | 88 | }, |
| 89 | Release, | 89 | Release, |
| 90 | + Imported { | ||
| 91 | + tag: String, | ||
| 92 | + result: Result<Vec<crate::model::Staged>, crate::error::ReleaseProblem>, | ||
| 93 | + }, | ||
| 90 | } | 94 | } |
| 91 | 95 | ||
| 92 | #[derive(Debug, Clone, Encode, Decode)] | 96 | #[derive(Debug, Clone, Encode, Decode)] |
crates/common/src/transport.rsmodified+1 -1
| @@ -15,7 +15,7 @@ use socket2::{Domain, Protocol, Socket, Type}; | |||
| 15 | 15 | ||
| 16 | macro_rules! protocol { | 16 | macro_rules! protocol { |
| 17 | () => { | 17 | () => { |
| 18 | - "yumush/6" | 18 | + "yumush/7" |
| 19 | }; | 19 | }; |
| 20 | } | 20 | } |
| 21 | 21 | ||
crates/server/Cargo.tomlmodified+2 -0
| @@ -20,6 +20,8 @@ image = { version = "0.25.10", default-features = false, features = ["jpeg", "pn | |||
| 20 | thiserror = "2.0.21" | 20 | thiserror = "2.0.21" |
| 21 | tracing = "0.1.44" | 21 | tracing = "0.1.44" |
| 22 | tracing-subscriber = "0.3.23" | 22 | tracing-subscriber = "0.3.23" |
| 23 | +ureq = { version = "3.5.2", features = ["json"] } | ||
| 24 | +serde = { version = "1.0.229", features = ["derive"] } | ||
| 23 | zstd = { version = "0.14.5", features = ["zstdmt"] } | 25 | zstd = { version = "0.14.5", features = ["zstdmt"] } |
| 24 | 26 | ||
| 25 | [lints] | 27 | [lints] |
crates/server/src/call/mod.rsmodified+1 -0
| @@ -223,6 +223,7 @@ pub(crate) async fn dispatch(request: Request, cx: &mut Cx<'_>) -> Vec<u8> { | |||
| 223 | Request::ListReleases(call) => serve(call, cx).await, | 223 | Request::ListReleases(call) => serve(call, cx).await, |
| 224 | Request::ListUpdateClients(call) => serve(call, cx).await, | 224 | Request::ListUpdateClients(call) => serve(call, cx).await, |
| 225 | Request::PublishRelease(call) => serve(call, cx).await, | 225 | Request::PublishRelease(call) => serve(call, cx).await, |
| 226 | + Request::ImportRelease(call) => serve(call, cx).await, | ||
| 226 | Request::SetReleaseRequired(call) => serve(call, cx).await, | 227 | Request::SetReleaseRequired(call) => serve(call, cx).await, |
| 227 | } | 228 | } |
| 228 | } | 229 | } |
crates/server/src/call/release.rsmodified+27 -1
| @@ -1,5 +1,5 @@ | |||
| 1 | use common::{ | 1 | use common::{ |
| 2 | - call::{ListReleases, ListUpdateClients, PublishRelease, SetReleaseRequired}, | 2 | + call::{ImportRelease, ListReleases, ListUpdateClients, PublishRelease, SetReleaseRequired}, |
| 3 | error::{Error, ReleaseProblem}, | 3 | error::{Error, ReleaseProblem}, |
| 4 | event::Event, | 4 | event::Event, |
| 5 | model::{AdminAction, ReleaseFile, ReleaseInfo, UpdateClient}, | 5 | model::{AdminAction, ReleaseFile, ReleaseInfo, UpdateClient}, |
| @@ -121,3 +121,29 @@ impl Handle for SetReleaseRequired { | |||
| 121 | Ok(()) | 121 | Ok(()) |
| 122 | } | 122 | } |
| 123 | } | 123 | } |
| 124 | + | ||
| 125 | +impl Handle for ImportRelease { | ||
| 126 | + async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> { | ||
| 127 | + me.user()?; | ||
| 128 | + let shared = cx.sh.clone(); | ||
| 129 | + tokio::spawn(async move { | ||
| 130 | + let result = shared | ||
| 131 | + .releases | ||
| 132 | + .import(self.tag.clone(), &shared.db) | ||
| 133 | + .await | ||
| 134 | + .map_err(|error| match common::error::Error::from(error) { | ||
| 135 | + Error::Release(problem) => problem, | ||
| 136 | + _ => ReleaseProblem::Forge, | ||
| 137 | + }); | ||
| 138 | + let event = Event::Imported { | ||
| 139 | + tag: self.tag, | ||
| 140 | + result, | ||
| 141 | + }; | ||
| 142 | + let _ = crate::publish::job(&shared, async |_| { | ||
| 143 | + Ok(vec![crate::publish::Broadcast::new(To::Builders, event)]) | ||
| 144 | + }) | ||
| 145 | + .await; | ||
| 146 | + }); | ||
| 147 | + Ok(()) | ||
| 148 | + } | ||
| 149 | +} | ||
crates/server/src/forge.rsadded+89 -0
| @@ -0,0 +1,89 @@ | |||
| 1 | +use std::io::Read; | ||
| 2 | + | ||
| 3 | +use common::{error::ReleaseProblem, update::FILE_MAX}; | ||
| 4 | +use serde::Deserialize; | ||
| 5 | + | ||
| 6 | +pub struct Forge { | ||
| 7 | + api: String, | ||
| 8 | + token: Option<String>, | ||
| 9 | +} | ||
| 10 | + | ||
| 11 | +pub struct Asset { | ||
| 12 | + pub name: String, | ||
| 13 | + pub url: String, | ||
| 14 | + pub sha256: String, | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +#[derive(Deserialize)] | ||
| 18 | +struct Release { | ||
| 19 | + assets: Vec<AssetJson>, | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +#[derive(Deserialize)] | ||
| 23 | +struct AssetJson { | ||
| 24 | + name: String, | ||
| 25 | + browser_download_url: String, | ||
| 26 | + sha256: String, | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +impl Forge { | ||
| 30 | + pub fn new(repo: &str, token: Option<String>) -> Option<Self> { | ||
| 31 | + let (host, path) = repo | ||
| 32 | + .trim_end_matches('/') | ||
| 33 | + .split_once("://")? | ||
| 34 | + .1 | ||
| 35 | + .split_once('/')?; | ||
| 36 | + let scheme = repo.split_once("://")?.0; | ||
| 37 | + Some(Self { | ||
| 38 | + api: format!("{scheme}://{host}/api/v1/repos/{path}"), | ||
| 39 | + token, | ||
| 40 | + }) | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + fn get(&self, url: &str) -> ureq::RequestBuilder<ureq::typestate::WithoutBody> { | ||
| 44 | + let request = ureq::get(url); | ||
| 45 | + match &self.token { | ||
| 46 | + Some(token) => request.header("Authorization", format!("token {token}")), | ||
| 47 | + None => request, | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + pub fn assets(&self, tag: &str) -> Result<Vec<Asset>, ReleaseProblem> { | ||
| 52 | + let release: Release = self | ||
| 53 | + .get(&format!("{}/releases/tags/{tag}", self.api)) | ||
| 54 | + .call() | ||
| 55 | + .and_then(|mut response| response.body_mut().read_json()) | ||
| 56 | + .map_err(|_| ReleaseProblem::Forge)?; | ||
| 57 | + Ok(release | ||
| 58 | + .assets | ||
| 59 | + .into_iter() | ||
| 60 | + .map(|asset| Asset { | ||
| 61 | + name: asset.name, | ||
| 62 | + url: asset.browser_download_url, | ||
| 63 | + sha256: asset.sha256, | ||
| 64 | + }) | ||
| 65 | + .collect()) | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + pub fn download(&self, asset: &Asset) -> Result<Vec<u8>, ReleaseProblem> { | ||
| 69 | + let mut bytes = Vec::new(); | ||
| 70 | + self.get(&asset.url) | ||
| 71 | + .call() | ||
| 72 | + .map_err(|_| ReleaseProblem::Forge)? | ||
| 73 | + .into_body() | ||
| 74 | + .into_reader() | ||
| 75 | + .take(FILE_MAX + 1) | ||
| 76 | + .read_to_end(&mut bytes) | ||
| 77 | + .map_err(|_| ReleaseProblem::Forge)?; | ||
| 78 | + ensure_size(&bytes)?; | ||
| 79 | + Ok(bytes) | ||
| 80 | + } | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +fn ensure_size(bytes: &[u8]) -> Result<(), ReleaseProblem> { | ||
| 84 | + match bytes.len() as u64 { | ||
| 85 | + 0 => Err(ReleaseProblem::Forge), | ||
| 86 | + size if size > FILE_MAX => Err(ReleaseProblem::TooLarge), | ||
| 87 | + _ => Ok(()), | ||
| 88 | + } | ||
| 89 | +} | ||
crates/server/src/lib.rsmodified+9 -0
| @@ -6,6 +6,7 @@ pub mod datagram; | |||
| 6 | pub mod db; | 6 | pub mod db; |
| 7 | pub mod error; | 7 | pub mod error; |
| 8 | pub mod files; | 8 | pub mod files; |
| 9 | +pub mod forge; | ||
| 9 | pub mod hub; | 10 | pub mod hub; |
| 10 | pub mod network; | 11 | pub mod network; |
| 11 | pub mod publish; | 12 | pub mod publish; |
| @@ -41,6 +42,8 @@ pub struct ServerConfig { | |||
| 41 | pub server_address: String, | 42 | pub server_address: String, |
| 42 | pub certificate_path: String, | 43 | pub certificate_path: String, |
| 43 | pub key_path: String, | 44 | pub key_path: String, |
| 45 | + pub forge: Option<String>, | ||
| 46 | + pub forge_token: Option<String>, | ||
| 44 | } | 47 | } |
| 45 | 48 | ||
| 46 | fn load_config() -> Result<ServerConfig, ServerError> { | 49 | fn load_config() -> Result<ServerConfig, ServerError> { |
| @@ -52,6 +55,8 @@ fn load_config() -> Result<ServerConfig, ServerError> { | |||
| 52 | server_address: config.get("server_address")?, | 55 | server_address: config.get("server_address")?, |
| 53 | certificate_path: config.get("certificate_path")?, | 56 | certificate_path: config.get("certificate_path")?, |
| 54 | key_path: config.get("key_path")?, | 57 | key_path: config.get("key_path")?, |
| 58 | + forge: config.get("forge").ok(), | ||
| 59 | + forge_token: config.get("forge_token").ok(), | ||
| 55 | }) | 60 | }) |
| 56 | } | 61 | } |
| 57 | 62 | ||
| @@ -77,6 +82,10 @@ pub async fn showtime() -> Result<network::Exit, ServerError> { | |||
| 77 | let backups = sibling_directory(&config.database_path, "backups")?; | 82 | let backups = sibling_directory(&config.database_path, "backups")?; |
| 78 | let releases = update::Releases::load( | 83 | let releases = update::Releases::load( |
| 79 | sibling_directory(&config.database_path, "clients")?, | 84 | sibling_directory(&config.database_path, "clients")?, |
| 85 | + config | ||
| 86 | + .forge | ||
| 87 | + .as_deref() | ||
| 88 | + .and_then(|repo| forge::Forge::new(repo, config.forge_token.clone())), | ||
| 80 | &database, | 89 | &database, |
| 81 | ) | 90 | ) |
| 82 | .await?; | 91 | .await?; |
crates/server/src/update.rsmodified+44 -1
| @@ -25,6 +25,7 @@ use crate::{ | |||
| 25 | authentication, | 25 | authentication, |
| 26 | db::{self, Connection as DbConnection, Db}, | 26 | db::{self, Connection as DbConnection, Db}, |
| 27 | error::{ServerError, ensure, ensure_with}, | 27 | error::{ServerError, ensure, ensure_with}, |
| 28 | + forge::Forge, | ||
| 28 | }; | 29 | }; |
| 29 | 30 | ||
| 30 | const PACK_LEVEL: i32 = 19; | 31 | const PACK_LEVEL: i32 = 19; |
| @@ -104,12 +105,17 @@ pub struct Seen { | |||
| 104 | #[derive(Clone, Default)] | 105 | #[derive(Clone, Default)] |
| 105 | pub struct Releases { | 106 | pub struct Releases { |
| 106 | directory: PathBuf, | 107 | directory: PathBuf, |
| 108 | + forge: Option<Arc<Forge>>, | ||
| 107 | staged: Arc<Mutex<HashMap<Sha, (Staged, String)>>>, | 109 | staged: Arc<Mutex<HashMap<Sha, (Staged, String)>>>, |
| 108 | board: Arc<Mutex<HashMap<Install, Seen>>>, | 110 | board: Arc<Mutex<HashMap<Install, Seen>>>, |
| 109 | } | 111 | } |
| 110 | 112 | ||
| 111 | impl Releases { | 113 | impl Releases { |
| 112 | - pub async fn load(directory: PathBuf, db: &Db) -> Result<Self, ServerError> { | 114 | + pub async fn load( |
| 115 | + directory: PathBuf, | ||
| 116 | + forge: Option<Forge>, | ||
| 117 | + db: &Db, | ||
| 118 | + ) -> Result<Self, ServerError> { | ||
| 113 | let live = db.run(async |conn| db::release::live(conn).await).await?; | 119 | let live = db.run(async |conn| db::release::live(conn).await).await?; |
| 114 | let keep: Vec<PathBuf> = live.iter().map(|file| path_of(&directory, file)).collect(); | 120 | let keep: Vec<PathBuf> = live.iter().map(|file| path_of(&directory, file)).collect(); |
| 115 | for entry in std::fs::read_dir(&directory)? { | 121 | for entry in std::fs::read_dir(&directory)? { |
| @@ -121,6 +127,7 @@ impl Releases { | |||
| 121 | 127 | ||
| 122 | Ok(Self { | 128 | Ok(Self { |
| 123 | directory, | 129 | directory, |
| 130 | + forge: forge.map(Arc::new), | ||
| 124 | staged: Default::default(), | 131 | staged: Default::default(), |
| 125 | board: Default::default(), | 132 | board: Default::default(), |
| 126 | }) | 133 | }) |
| @@ -187,7 +194,43 @@ impl Releases { | |||
| 187 | )?; | 194 | )?; |
| 188 | let mut bytes = vec![0; size as usize]; | 195 | let mut bytes = vec![0; size as usize]; |
| 189 | receive.read_exact(&mut bytes).await?; | 196 | receive.read_exact(&mut bytes).await?; |
| 197 | + self.admit(bytes, db).await | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + pub async fn import(&self, tag: String, db: &Db) -> Result<Vec<Staged>, ServerError> { | ||
| 201 | + let forge = self | ||
| 202 | + .forge | ||
| 203 | + .clone() | ||
| 204 | + .ok_or(CommonError::Release(ReleaseProblem::NoForge))?; | ||
| 205 | + let downloads = tokio::task::spawn_blocking(move || { | ||
| 206 | + forge | ||
| 207 | + .assets(&tag)? | ||
| 208 | + .into_iter() | ||
| 209 | + .map(|asset| { | ||
| 210 | + let bytes = forge.download(&asset)?; | ||
| 211 | + if hex(&sha256(&bytes)) != asset.sha256 { | ||
| 212 | + return Err(ReleaseProblem::Checksum); | ||
| 213 | + } | ||
| 214 | + Ok(bytes) | ||
| 215 | + }) | ||
| 216 | + .collect::<Result<Vec<_>, _>>() | ||
| 217 | + }) | ||
| 218 | + .await? | ||
| 219 | + .map_err(CommonError::Release)?; | ||
| 220 | + | ||
| 221 | + let mut staged = Vec::new(); | ||
| 222 | + for bytes in downloads { | ||
| 223 | + match self.admit(bytes, db).await { | ||
| 224 | + Ok(file) => staged.push(file), | ||
| 225 | + Err(ServerError::Wire(CommonError::Release(ReleaseProblem::Released(_)))) => {} | ||
| 226 | + Err(error) => return Err(error), | ||
| 227 | + } | ||
| 228 | + } | ||
| 229 | + Ok(staged) | ||
| 230 | + } | ||
| 190 | 231 | ||
| 232 | + async fn admit(&self, bytes: Vec<u8>, db: &Db) -> Result<Staged, ServerError> { | ||
| 233 | + let size = bytes.len() as u64; | ||
| 191 | let file = sha256(&bytes); | 234 | let file = sha256(&bytes); |
| 192 | let target = target_of(&bytes).ok_or(CommonError::Release(ReleaseProblem::NotClient))?; | 235 | let target = target_of(&bytes).ok_or(CommonError::Release(ReleaseProblem::NotClient))?; |
| 193 | let protocol = | 236 | let protocol = |