diff --git a/AGENT_TASKS.md b/AGENT_TASKS.md index 8bdcd05..cc96353 100644 --- a/AGENT_TASKS.md +++ b/AGENT_TASKS.md @@ -14,9 +14,9 @@ The Python implementation remains the behavioral oracle until the Rust replaceme - Defer live API release tests until a disposable token is provided. - Use the small `target_test_project` submodule for fast build and cross-target experiments. -Current Rust milestone: `inspect`, `metadata`, repository preparation, host `verify`, Cross `build`, and local `package` stages are implemented. Preparation has disposable Git tests for dry-run, commit, tag safety, and destination refusal; atomic push still needs an isolated integration test. The tiny fixture built and packaged all three default targets locally. Gitea publication remains in the Python worker. +Current Rust milestone: inspection, metadata, preparation, host verification, Cross build, packaging, Gitea publication, anonymous downloads, and isolated cargo-binstall orchestration are implemented. Gitea paths pass local HTTP mock tests; live publication and real cargo-binstall installation still need a disposable token. Preparation has disposable Git tests for dry-run, commit, tag safety, and destination refusal; atomic push still needs an isolated integration test. The tiny fixture built and packaged all three default targets locally. -Progress tracking: check a task only when the Rust behavior is implemented and locally verified. Keep phase gates open until their full fixture/parity criteria pass. The Python baseline has 45 passing tests and two opt-in tests skipped. CI runs Cargo tests only; Cross and live Gitea tests are deferred. Next work: validate a real local target build, complete repository preparation, and port mocked Gitea publication and artifact verification. +Progress tracking: check a task only when the Rust behavior is implemented and locally verified. Keep phase gates open until their full fixture/parity criteria pass. The Python baseline has 45 passing tests and two opt-in tests skipped. CI runs Cargo tests only; Cross and live Gitea tests are deferred. Next work: isolated preparation-push test, broader parity fixtures, and offline publication edge cases. Work in small, testable phases. Commit migration work in coherent increments. @@ -329,7 +329,7 @@ Test-only as useful: - [x] Apply configured/CLI tag prefix. - [x] Validate explicit `--tag`. - [x] Validate local tag points to HEAD where required. -- [ ] Validate remote tag exists and points to expected commit before publication. +- [x] Validate remote tag exists and points to expected commit before publication. - [ ] Preserve preparation-mode distinction: intended tag naming without checking out an existing tag. - [ ] Never move an existing tag. - [ ] Never rewrite Cargo package version. @@ -502,38 +502,38 @@ Test-only as useful: ### Client -- [ ] Parse base instance/repository coordinates. -- [ ] Load token only from configured environment variable. -- [ ] Use HTTPS for authenticated publication. -- [ ] Set useful user-agent. -- [ ] Implement contextual API errors. +- [x] Parse base instance/repository coordinates. +- [x] Load token only from configured environment variable. +- [x] Use HTTPS for authenticated publication. +- [x] Set useful user-agent. +- [x] Implement contextual API errors. ### Releases -- [ ] Get remote tag. -- [ ] Get release by tag. -- [ ] Create release. -- [ ] Reuse existing release. -- [ ] Preserve draft/prerelease fields. +- [x] Get remote tag. +- [x] Get release by tag. +- [x] Create release. +- [x] Reuse existing release. +- [x] Preserve draft/prerelease fields. ### Assets -- [ ] List release assets once according to current Gitea API behavior. -- [ ] Do not reintroduce the historical repeated pagination bug. -- [ ] Upload assets. -- [ ] Fail on duplicate filename by default. -- [ ] Delete/replace only under `--replace-assets`. -- [ ] Never touch unrelated assets. +- [x] List release assets once according to current Gitea API behavior. +- [x] Do not reintroduce the historical repeated pagination bug. +- [x] Upload assets. +- [x] Fail on duplicate filename by default. +- [x] Delete/replace only under `--replace-assets`. +- [x] Never touch unrelated assets. ### Tests -- [ ] Mock release absence -> create. -- [ ] Mock existing release -> reuse. -- [ ] Asset listing regression test. -- [ ] Collision refusal. -- [ ] Explicit replacement. -- [ ] HTTP failure context. -- [ ] Token redaction. +- [x] Mock release absence -> create. +- [x] Mock existing release -> reuse. +- [x] Asset listing regression test. +- [x] Collision refusal. +- [x] Explicit replacement. +- [x] HTTP failure context. +- [x] Token redaction. ### Gate @@ -545,25 +545,25 @@ Test-only as useful: ### Artifact verification -- [ ] Build expected asset URLs. -- [ ] Download published archives. -- [ ] Prefer anonymous downloads for public assets. -- [ ] Validate SHA256SUMS. -- [ ] Validate archive root. -- [ ] Validate binary filename. -- [ ] Validate Unix executable bit where meaningful. +- [x] Build expected asset URLs. +- [x] Download published archives. +- [x] Prefer anonymous downloads for public assets. +- [x] Validate SHA256SUMS. +- [x] Validate archive root. +- [x] Validate binary filename. +- [x] Validate Unix executable bit where meaningful. ### cargo-binstall -- [ ] Use selected package manifest. -- [ ] Create temporary Cargo home/install root. -- [ ] Install without touching user's normal Cargo bin. +- [x] Use selected package manifest. +- [x] Create temporary Cargo home/install root. +- [x] Install without touching user's normal Cargo bin. - [ ] Verify all default target contracts where supported. -- [ ] Respect `--skip-binstall-test`. +- [x] Respect `--skip-binstall-test`. ### Tests -- [ ] Local/mock HTTP asset server integration. +- [x] Local/mock HTTP asset server integration. - [ ] Real cargo-binstall integration fixture. - [ ] Check all three default target artifact layouts. diff --git a/Cargo.lock b/Cargo.lock index 9642e4b..c9d1f1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,7 +53,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -64,9 +64,21 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys", + "windows-sys 0.61.2", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "2.13.2" @@ -82,12 +94,51 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cc" +version = "1.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3eb0f42d6c360dc3f8a821f6bf2fdea7f72bfd36b3076eb0e6d1e9e0752fff4" +dependencies = [ + "find-msvc-tools", + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "rand_core", +] + [[package]] name = "clap" version = "4.6.7" @@ -143,6 +194,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.5.2" @@ -196,7 +256,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -205,6 +265,12 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" +[[package]] +name = "find-msvc-tools" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d" + [[package]] name = "flate2" version = "1.1.10" @@ -225,6 +291,55 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures-channel" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "262590f4fe6afeb0bc83be1daa64e52657fe185690a958af7f3ad0e92085c5ae" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cd50c473c80f6d7c3670a752354b8e569b1a7cbfdc0419ec88e5edad85e0dc7" + +[[package]] +name = "futures-io" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4577ecaa3c4f96589d473f679a71b596316f6641bc350038b962a5daf0085d7a" + +[[package]] +name = "futures-sink" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e34418ac499d6305c2fb5ad0ed2f6ac998c5f8ca209b4510f7f94242c647e307" + +[[package]] +name = "futures-task" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b231ed28831efb4a61a08580c4bc233ec56bc009f4cd8f52da2c3cb97df0c109" + +[[package]] +name = "futures-util" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a77a90a256fce34da66415271e30f94ee91c57b04b8a2c042d9cf3220179deaa" +dependencies = [ + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -235,6 +350,19 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + [[package]] name = "getrandom" version = "0.4.3" @@ -242,8 +370,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" dependencies = [ "cfg-if", + "js-sys", "libc", "r-efi", + "rand_core", + "wasm-bindgen", ] [[package]] @@ -258,6 +389,104 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "http" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6970f50e31d6fc17d3fa27329444bfa74e196cf62e95052a3f6fee181dba6425" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55281c53a1894c864990125767da440a4e630446785086f52523b20033b74498" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + [[package]] name = "icu_collections" version = "2.2.0" @@ -371,6 +600,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "ipnet" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" + [[package]] name = "is_terminal_polyfill" version = "1.70.2" @@ -383,6 +618,17 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "js-sys" +version = "0.3.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + [[package]] name = "libc" version = "0.2.189" @@ -401,12 +647,40 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" +[[package]] +name = "log" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + [[package]] name = "memchr" version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "miniz_oxide" version = "0.9.1" @@ -417,6 +691,17 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "mio" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + [[package]] name = "once_cell" version = "1.21.4" @@ -435,6 +720,12 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + [[package]] name = "potential_utf" version = "0.1.6" @@ -453,6 +744,62 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4bfc015262b9df63c8845072ce59068853ff5872180c2ce2f13038b970e560" +dependencies = [ + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand", + "rand_pcg", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + [[package]] name = "quote" version = "1.0.47" @@ -468,6 +815,32 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core", +] + [[package]] name = "regex" version = "1.13.1" @@ -497,6 +870,61 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "mime_guess", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rust_realease" version = "0.1.0" @@ -504,6 +932,7 @@ dependencies = [ "clap", "flate2", "regex", + "reqwest", "serde", "serde_json", "sha2", @@ -514,6 +943,12 @@ dependencies = [ "url", ] +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + [[package]] name = "rustix" version = "1.1.4" @@ -524,9 +959,56 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.61.2", ] +[[package]] +name = "rustls" +version = "0.23.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b92b125634d9b795e7beca796cc790df15a7fb38323bf3196fda83292d06b1f" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + [[package]] name = "serde" version = "1.0.229" @@ -579,6 +1061,18 @@ dependencies = [ "serde_core", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "sha2" version = "0.10.9" @@ -586,10 +1080,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", "digest", ] +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + [[package]] name = "simd-adler32" version = "0.3.10" @@ -602,12 +1102,28 @@ version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + [[package]] name = "smallvec" version = "1.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba467056f1b547ed52077911161fc86985becbc60e8e1857c8a144dab0def891" +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + [[package]] name = "stable_deref_trait" version = "1.2.1" @@ -620,6 +1136,12 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "2.0.119" @@ -642,6 +1164,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + [[package]] name = "synstructure" version = "0.13.2" @@ -660,10 +1191,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom", + "getrandom 0.4.3", "once_cell", "rustix", - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", ] [[package]] @@ -676,6 +1227,45 @@ dependencies = [ "zerovec", ] +[[package]] +name = "tinyvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cf0ded5c4e56918d8f8a339e1bb67d038d3bc6d144ac407904015ba2e4cde9b" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + [[package]] name = "toml" version = "1.1.6+spec-1.1.0" @@ -728,18 +1318,100 @@ version = "1.1.2+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2" +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "typenum" version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" +[[package]] +name = "unicase" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" + [[package]] name = "unicode-ident" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.8" @@ -770,12 +1442,120 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62df1340f32221cb9c54d6a27b030e3dba64361d4a95bed55f9aacb44da291d" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.119", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8622dcb61c0bcc9fffa6938bed81210af2da9a7e4a1a834b2e37a59b6dfb6141" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf85cb06032201fa7c6f829d7db5a7e5aa45bcc0655327713065f6f0576731bf" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -785,6 +1565,70 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "winnow" version = "1.0.4" @@ -844,6 +1688,12 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + [[package]] name = "zerotrie" version = "0.2.5" diff --git a/Cargo.toml b/Cargo.toml index 18a02cb..b08a912 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ regex = "1" flate2 = "1.1" sha2 = "0.10" similar = "2" +reqwest = { version = "0.12", default-features = false, features = ["blocking", "json", "multipart", "rustls-tls"] } diff --git a/Jenkinsfile b/Jenkinsfile index 6f5aaad..1d42c1b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,7 +17,7 @@ pipeline { stage('Cargo Tests') { steps { - sh 'cargo test --locked --offline --all' + sh 'cargo test --locked --all' } } } diff --git a/README.md b/README.md index eb5fe1b..6cf7118 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Rust Binstall Publisher -> Rust migration status: the Rust binary supports local and remote Git inspection, metadata repair, repository preparation, host check/test (`--stop-after verify`), Cross builds (`--stop-after build`), and local `.tgz`/SHA256SUMS packaging (`--stop-after package`). Preparation has disposable Git tests for dry-run, commit, and tag safety; its remote push path still needs an isolated integration test. The tiny fixture built and packaged all three default targets locally. The Python worker remains the publication implementation. +> Rust migration status: the Rust binary supports inspection, metadata repair, repository preparation, host check/test, Cross builds, local packaging, Gitea release/upload, anonymous artifact verification, and isolated cargo-binstall verification. The Gitea and download paths have local HTTP mock tests; a live disposable release and real cargo-binstall install still need a token. Preparation's remote push path still needs an isolated integration test. The Python worker remains the proven publication reference until those parity gates pass. -Inspect locally with `cargo run -- target_test_project --stop-after inspect`. Validate metadata with `cargo run -- target_test_project --stop-after metadata`; add `--dry-run` to preview proposed repairs or `--fix-metadata` to write them. Preview repository changes with `cargo run -- target_test_project --prepare-repo --dry-run`. Use `--commit-preparation`, `--create-tag`, and `--push-preparation` only when those Git writes are intended. Run host checks with `cargo run -- target_test_project --stop-after verify`. Build and package locally with `--stop-after package` once Cross and a container backend are available. Run the Rust checks with `cargo fmt --check`, `cargo clippy --offline --all-targets --all-features -- -D warnings`, and `cargo test --offline`. Live Gitea tests are deferred until a disposable token is available. +Inspect locally with `cargo run -- target_test_project --stop-after inspect`. Validate metadata with `cargo run -- target_test_project --stop-after metadata`; add `--dry-run` to preview proposed repairs or `--fix-metadata` to write them. Preview repository changes with `cargo run -- target_test_project --prepare-repo --dry-run`. Use `--commit-preparation`, `--create-tag`, and `--push-preparation` only when those Git writes are intended. Run host checks with `cargo run -- target_test_project --stop-after verify`. Build and package locally with `--stop-after package` once Cross and a container backend are available. Run the Rust checks with `cargo fmt --check`, `cargo clippy --all-targets --all-features -- -D warnings`, and `cargo test --all`. Live Gitea tests are deferred until a disposable token is available. A small Python release tool for Rust CLI projects on Gitea, releasing one package with one binary at a time. It inspects Cargo metadata, checks version tags, cross-compiles binaries, creates reproducible `.tgz` archives and SHA-256 checksums, uploads a release, and verifies the downloads with cargo-binstall. diff --git a/src/cli.rs b/src/cli.rs index a0389f6..61700cd 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -2,10 +2,12 @@ use crate::{ build, config::{self, Overrides}, error::Error, + gitea::Gitea, manifest, model::Stage, policy, prepare, project, runner::Runner, + verify, }; use clap::Parser; use std::path::PathBuf; @@ -104,6 +106,11 @@ pub fn run(args: Cli) -> Result<(), Error> { .to_str() .ok_or_else(|| Error("Project path is not UTF-8.".into()))?; let selected = project::inspect(root, args.package.as_deref(), &runner)?; + let publishing = !args.prepare_repo + && !args.dry_run + && args + .stop_after + .is_none_or(|stage| stage.order() >= Stage::Release.order()); let tag = policy::expected_tag(&selected.version, &config.tag_prefix); if args.tag.as_ref().is_some_and(|provided| provided != &tag) { return Err(Error(format!( @@ -122,6 +129,19 @@ pub fn run(args: Cli) -> Result<(), Error> { { return Ok(()); } + if publishing + && !runner + .text( + "git", + &["status", "--porcelain", "--untracked-files=normal"], + &checkout.root, + )? + .is_empty() + { + return Err(Error( + "Publication requires a clean checkout before metadata repair.".into(), + )); + } let candidate = args .repository_url .as_deref() @@ -135,6 +155,15 @@ pub fn run(args: Cli) -> Result<(), Error> { ) })?; let repository = project::normalize_repository(&candidate)?; + if publishing { + if let Some(origin) = project::origin_url(&checkout.root, &runner) { + if project::normalize_repository(&origin)? != repository { + return Err(Error( + "Git origin differs from the release repository.".into(), + )); + } + } + } let issues = manifest::changes(&selected.manifest, &repository, &config.tag_prefix)?; if issues.is_empty() { println!("Binstall metadata: valid"); @@ -216,6 +245,18 @@ pub fn run(args: Cli) -> Result<(), Error> { "Resolve the prerequisite issues above before building.".into(), )); } + if publishing { + project::validate_checkout_tag(&checkout.root, &tag, &runner)?; + if std::env::var(&config.token_env) + .ok() + .is_none_or(|value| value.is_empty()) + { + return Err(Error(format!( + "Set {} before publishing.", + config.token_env + ))); + } + } build::verify_source(&checkout.root, &selected, &config, args.skip_tests, &runner)?; if args.stop_after == Some(Stage::Verify) { return Ok(()); @@ -248,9 +289,28 @@ pub fn run(args: Cli) -> Result<(), Error> { if args.stop_after == Some(Stage::Package) { return Ok(()); } - Err(Error( - "Rust Gitea publication is still being ported; use release.sh for publication.".into(), - )) + let commit = project::head_commit(&checkout.root, &runner)?; + let api = Gitea::new(&repository, &config.token_env)?; + let release = api.ensure_release(&tag, &commit, args.draft, args.prerelease)?; + println!("Release ready: {tag}"); + if args.stop_after == Some(Stage::Release) { + return Ok(()); + } + let mut paths: Vec<&std::path::Path> = artifacts.iter().map(|a| a.path.as_path()).collect(); + paths.push(sums.as_path()); + api.upload(release.id, &paths, args.replace_assets)?; + if args.stop_after == Some(Stage::Upload) { + return Ok(()); + } + if release.draft { + return Err(Error("Draft uploaded. Public verification requires publishing the draft; use --stop-after upload for draft workflows.".into())); + } + verify::verify_published(&repository, &tag, &artifacts, &sums)?; + if !args.skip_binstall_test { + verify::verify_binstall(&checkout.root, &selected, &config.targets, &runner)?; + } + println!("Release completed and published artifacts verified."); + Ok(()) } #[cfg(test)] diff --git a/src/gitea.rs b/src/gitea.rs index 794c4e9..1dbc89c 100644 --- a/src/gitea.rs +++ b/src/gitea.rs @@ -1 +1,426 @@ -//! Placeholder for the future gitea implementation. +use crate::error::Error; +use reqwest::{ + blocking::{ + multipart::{Form, Part}, + Client, + }, + header::{HeaderMap, HeaderValue, AUTHORIZATION}, + Method, StatusCode, +}; +use serde::Deserialize; +use serde_json::{json, Value}; +use std::{env, fs::File, path::Path, time::Duration}; + +#[derive(Debug, Deserialize)] +pub struct RemoteRelease { + pub id: u64, + #[serde(default)] + pub draft: bool, +} + +#[derive(Debug, Deserialize)] +struct Asset { + id: u64, + name: String, +} + +pub struct Gitea { + client: Client, + base: String, +} + +impl Gitea { + pub fn new(repository: &str, token_env: &str) -> Result { + let token = env::var(token_env) + .ok() + .filter(|s| !s.is_empty()) + .ok_or_else(|| Error(format!("Set {token_env} before publishing.")))?; + if !repository.starts_with("https://") { + return Err(Error( + "Authenticated Gitea publishing requires HTTPS.".into(), + )); + } + Self::with_token(repository, &token) + } + + fn with_token(repository: &str, token: &str) -> Result { + let parsed = url::Url::parse(repository) + .map_err(|_| Error("Invalid release repository URL.".into()))?; + let parts: Vec<_> = parsed + .path_segments() + .ok_or_else(|| Error("Repository URL must end in owner/repository.".into()))? + .filter(|part| !part.is_empty()) + .collect(); + if parts.len() < 2 { + return Err(Error("Repository URL must end in owner/repository.".into())); + } + let prefix = parts[..parts.len() - 2].join("/"); + let owner = parts[parts.len() - 2]; + let name = parts[parts.len() - 1]; + let origin = parsed.origin().ascii_serialization(); + let base = if prefix.is_empty() { + format!("{origin}/api/v1/repos/{owner}/{name}") + } else { + format!("{origin}/{prefix}/api/v1/repos/{owner}/{name}") + }; + let mut headers = HeaderMap::new(); + headers.insert( + AUTHORIZATION, + HeaderValue::from_str(&format!("token {token}")) + .map_err(|_| Error("Invalid Gitea token value.".into()))?, + ); + let client = Client::builder() + .default_headers(headers) + .user_agent("rust_realease/0.1") + .timeout(Duration::from_secs(120)) + .redirect(reqwest::redirect::Policy::none()) + .build() + .map_err(|_| Error("Cannot initialize Gitea HTTP client.".into()))?; + Ok(Self { client, base }) + } + + fn request( + &self, + method: Method, + path: &str, + body: Option, + missing_ok: bool, + ) -> Result, Error> { + let url = format!("{}{path}", self.base); + let mut request = self.client.request(method.clone(), &url); + if let Some(body) = body { + request = request.json(&body); + } + let response = request + .send() + .map_err(|_| Error(format!("Gitea {method} {path}: connection failed.")))?; + if missing_ok && response.status() == StatusCode::NOT_FOUND { + return Ok(None); + } + if !response.status().is_success() { + return Err(Error(format!( + "Gitea {method} {path}: HTTP {}.", + response.status().as_u16() + ))); + } + let bytes = response + .bytes() + .map_err(|_| Error(format!("Gitea {method} {path}: response failed.")))?; + if bytes.is_empty() { + return Ok(Some(Value::Null)); + } + serde_json::from_slice(&bytes) + .map(Some) + .map_err(|_| Error(format!("Gitea {method} {path}: invalid JSON response."))) + } + + pub fn ensure_release( + &self, + tag: &str, + commit: &str, + draft: bool, + prerelease: bool, + ) -> Result { + let encoded = encode(tag); + let remote = self + .request(Method::GET, &format!("/tags/{encoded}"), None, true)? + .ok_or_else(|| { + Error(format!( + "Remote tag {tag:?} is missing. Push the tag explicitly before publishing." + )) + })?; + if remote.pointer("/commit/sha").and_then(Value::as_str) != Some(commit) { + return Err(Error( + "Remote tag commit differs from the checkout; refusing publication.".into(), + )); + } + let release = if let Some(existing) = self.request( + Method::GET, + &format!("/releases/tags/{encoded}"), + None, + true, + )? { + existing + } else { + self.request(Method::POST, "/releases", Some(json!({"tag_name": tag, "name": tag, "target_commitish": commit, "draft": draft, "prerelease": prerelease})), false)? + .ok_or_else(|| Error("Gitea release creation returned no response.".into()))? + }; + serde_json::from_value(release) + .map_err(|_| Error("Gitea release response is missing id or draft state.".into())) + } + + fn assets(&self, release_id: u64) -> Result, Error> { + let response = self + .request( + Method::GET, + &format!("/releases/{release_id}/assets"), + None, + false, + )? + .ok_or_else(|| Error("Gitea assets response is empty.".into()))?; + serde_json::from_value(response) + .map_err(|_| Error("Gitea assets response is invalid.".into())) + } + + pub fn upload(&self, release_id: u64, paths: &[&Path], replace: bool) -> Result<(), Error> { + let existing = self.assets(release_id)?; + let names: Vec<_> = paths + .iter() + .map(|p| { + p.file_name() + .and_then(|s| s.to_str()) + .ok_or_else(|| Error("Invalid upload filename.".into())) + }) + .collect::>()?; + let collisions: Vec<_> = existing + .iter() + .filter(|asset| names.contains(&asset.name.as_str())) + .collect(); + if !collisions.is_empty() && !replace { + return Err(Error(format!("Release assets already exist: {}. Use --replace-assets to replace them explicitly.", collisions.iter().map(|a| a.name.as_str()).collect::>().join(", ")))); + } + for (path, name) in paths.iter().zip(names.iter()) { + for asset in collisions.iter().filter(|asset| asset.name == *name) { + self.request( + Method::DELETE, + &format!("/releases/{release_id}/assets/{}", asset.id), + None, + false, + )?; + } + let input = File::open(path) + .map_err(|e| Error(format!("cannot open asset {}: {e}", path.display())))?; + let size = input + .metadata() + .map_err(|e| Error(format!("cannot inspect asset {}: {e}", path.display())))? + .len(); + let part = Part::reader_with_length(input, size) + .file_name((*name).to_owned()) + .mime_str("application/octet-stream") + .map_err(|_| Error("Invalid upload MIME type.".into()))?; + let mut url = url::Url::parse(&format!("{}/releases/{release_id}/assets", self.base)) + .map_err(|_| Error("Invalid Gitea upload URL.".into()))?; + url.query_pairs_mut().append_pair("name", name); + let response = self + .client + .post(url) + .multipart(Form::new().part("attachment", part)) + .send() + .map_err(|_| { + Error(format!( + "Gitea POST /releases/{release_id}/assets: connection failed." + )) + })?; + if !response.status().is_success() { + return Err(Error(format!( + "Gitea POST /releases/{release_id}/assets: HTTP {}.", + response.status().as_u16() + ))); + } + println!("Uploaded {name}"); + } + Ok(()) + } +} + +fn encode(segment: &str) -> String { + url::form_urlencoded::byte_serialize(segment.as_bytes()).collect() +} + +#[cfg(test)] +mod tests { + use super::*; + use std::{ + io::{Read, Write}, + net::TcpListener, + thread, + time::Duration, + }; + + struct Reply { + method: &'static str, + path: &'static str, + status: u16, + body: &'static str, + } + + fn server(replies: Vec) -> (String, thread::JoinHandle>) { + let listener = TcpListener::bind("127.0.0.1:0").unwrap(); + let address = format!("http://{}", listener.local_addr().unwrap()); + let handle = thread::spawn(move || { + let mut requests = Vec::new(); + for reply in replies { + let (mut stream, _) = listener.accept().unwrap(); + stream + .set_read_timeout(Some(Duration::from_secs(5))) + .unwrap(); + let mut bytes = Vec::new(); + let mut buffer = [0_u8; 8192]; + let header_end = loop { + let n = stream.read(&mut buffer).unwrap(); + assert!(n > 0, "client closed before headers"); + bytes.extend_from_slice(&buffer[..n]); + if let Some(index) = bytes.windows(4).position(|w| w == b"\r\n\r\n") { + break index + 4; + } + assert!(bytes.len() < 64 * 1024); + }; + let headers = String::from_utf8_lossy(&bytes[..header_end]).to_string(); + let first = headers.lines().next().unwrap().to_owned(); + assert!( + first.starts_with(&format!("{} {} ", reply.method, reply.path)), + "{first}" + ); + let length = headers + .lines() + .find_map(|line| { + line.to_ascii_lowercase() + .strip_prefix("content-length: ") + .and_then(|v| v.trim().parse::().ok()) + }) + .unwrap_or(0); + while bytes.len() < header_end + length { + let n = stream.read(&mut buffer).unwrap(); + assert!(n > 0, "client closed before body"); + bytes.extend_from_slice(&buffer[..n]); + } + requests.push(first); + let reason = if reply.status == 200 { + "OK" + } else if reply.status == 201 { + "Created" + } else if reply.status == 204 { + "No Content" + } else if reply.status == 404 { + "Not Found" + } else { + "Unauthorized" + }; + write!(stream, "HTTP/1.1 {} {}\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}", reply.status, reason, reply.body.len(), reply.body).unwrap(); + } + requests + }); + (address, handle) + } + + #[test] + fn creates_or_reuses_release_after_remote_tag_check() { + let base = "/gitea/api/v1/repos/team/demo"; + let (host, handle) = server(vec![ + Reply { + method: "GET", + path: "/gitea/api/v1/repos/team/demo/tags/v0.1.0", + status: 200, + body: r#"{"commit":{"sha":"abc"}}"#, + }, + Reply { + method: "GET", + path: "/gitea/api/v1/repos/team/demo/releases/tags/v0.1.0", + status: 404, + body: "{}", + }, + Reply { + method: "POST", + path: "/gitea/api/v1/repos/team/demo/releases", + status: 201, + body: r#"{"id":7,"draft":false}"#, + }, + ]); + let api = Gitea::with_token(&format!("{host}/gitea/team/demo"), "test-token").unwrap(); + let release = api.ensure_release("v0.1.0", "abc", false, true).unwrap(); + assert_eq!(release.id, 7); + assert_eq!(handle.join().unwrap().len(), 3); + + let (host, handle) = server(vec![ + Reply { + method: "GET", + path: "/gitea/api/v1/repos/team/demo/tags/v0.1.0", + status: 200, + body: r#"{"commit":{"sha":"abc"}}"#, + }, + Reply { + method: "GET", + path: "/gitea/api/v1/repos/team/demo/releases/tags/v0.1.0", + status: 200, + body: r#"{"id":9,"draft":true}"#, + }, + ]); + let api = Gitea::with_token(&format!("{host}/gitea/team/demo"), "test-token").unwrap(); + assert_eq!( + api.ensure_release("v0.1.0", "abc", false, false) + .unwrap() + .id, + 9 + ); + assert_eq!(handle.join().unwrap().len(), 2); + let _ = base; + } + + #[test] + fn collisions_refuse_or_replace_only_matching_asset() { + let temp = tempfile::tempdir().unwrap(); + let path = temp.path().join("one.tgz"); + std::fs::write(&path, b"archive").unwrap(); + let assets = r#"[{"id":3,"name":"one.tgz"},{"id":4,"name":"unrelated.tgz"}]"#; + let (host, handle) = server(vec![Reply { + method: "GET", + path: "/api/v1/repos/team/demo/releases/7/assets", + status: 200, + body: assets, + }]); + let api = Gitea::with_token(&format!("{host}/team/demo"), "test-token").unwrap(); + assert!(api + .upload(7, &[&path], false) + .unwrap_err() + .to_string() + .contains("--replace-assets")); + assert_eq!(handle.join().unwrap().len(), 1); + let (host, handle) = server(vec![ + Reply { + method: "GET", + path: "/api/v1/repos/team/demo/releases/7/assets", + status: 200, + body: assets, + }, + Reply { + method: "DELETE", + path: "/api/v1/repos/team/demo/releases/7/assets/3", + status: 204, + body: "", + }, + Reply { + method: "POST", + path: "/api/v1/repos/team/demo/releases/7/assets?name=one.tgz", + status: 201, + body: r#"{"id":5}"#, + }, + ]); + let api = Gitea::with_token(&format!("{host}/team/demo"), "test-token").unwrap(); + api.upload(7, &[&path], true).unwrap(); + assert_eq!(handle.join().unwrap().len(), 3); + } + + #[test] + fn api_errors_do_not_echo_server_body_or_token() { + let (host, handle) = server(vec![Reply { + method: "GET", + path: "/api/v1/repos/team/demo/tags/v0.1.0", + status: 401, + body: "test-token", + }]); + let api = Gitea::with_token(&format!("{host}/team/demo"), "test-token").unwrap(); + let error = api + .ensure_release("v0.1.0", "abc", false, false) + .unwrap_err() + .to_string(); + assert!(error.contains("HTTP 401")); + assert!(!error.contains("test-token")); + handle.join().unwrap(); + } + + #[test] + fn encodes_tag_and_requires_https() { + assert_eq!(encode("v1.0+build"), "v1.0%2Bbuild"); + assert!(Gitea::new("http://example.com/team/demo", "GITEA_TOKEN").is_err()); + } +} diff --git a/src/main.rs b/src/main.rs index bc76552..9058296 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ mod build; mod cli; mod config; mod error; +mod gitea; mod manifest; mod model; mod package; @@ -11,6 +12,7 @@ mod policy; mod prepare; mod project; mod runner; +mod verify; use clap::Parser; diff --git a/src/package.rs b/src/package.rs index f00239c..55cba20 100644 --- a/src/package.rs +++ b/src/package.rs @@ -140,7 +140,7 @@ fn unix_mode(metadata: &fs::Metadata) -> u32 { } } -fn checksum(path: &Path) -> Result { +pub fn checksum(path: &Path) -> Result { let mut input = File::open(path).map_err(|e| Error(format!("cannot open {}: {e}", path.display())))?; let mut hasher = Sha256::new(); diff --git a/src/project.rs b/src/project.rs index f2fd8e2..8313969 100644 --- a/src/project.rs +++ b/src/project.rs @@ -241,6 +241,10 @@ pub fn origin_url(root: &Path, runner: &Runner) -> Option { .ok() } +pub fn head_commit(root: &Path, runner: &Runner) -> Result { + runner.text("git", &["rev-parse", "HEAD"], root) +} + pub fn validate_checkout_tag(root: &Path, tag: &str, runner: &Runner) -> Result<(), Error> { let tagged = runner .text( diff --git a/src/verify.rs b/src/verify.rs index a01391b..598ec31 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -1 +1,332 @@ -//! Placeholder for the future verify implementation. +use crate::{ + error::Error, + package::{self, Artifact}, + policy, + project::SelectedPackage, + runner::Runner, +}; +use flate2::read::GzDecoder; +use reqwest::blocking::Client; +use std::{ + fs::{self, File}, + io::{Read, Write}, + path::Path, + time::Duration, +}; + +pub fn asset_url(repository: &str, tag: &str, filename: &str) -> String { + let encode = + |s: &str| -> String { url::form_urlencoded::byte_serialize(s.as_bytes()).collect() }; + format!( + "{repository}/releases/download/{}/{}", + encode(tag), + encode(filename) + ) +} + +pub fn verify_archive(path: &Path, artifact: &Artifact) -> Result<(), Error> { + let mut tar = Vec::new(); + let file = + File::open(path).map_err(|e| Error(format!("cannot open {}: {e}", path.display())))?; + GzDecoder::new(file) + .read_to_end(&mut tar) + .map_err(|e| Error(format!("{}: invalid gzip archive: {e}", path.display())))?; + if tar.len() < 2048 { + return Err(Error(format!("{}: truncated tar archive.", path.display()))); + } + let directory = &tar[..512]; + let first = member_name(directory)?; + if first != artifact.root || directory[156] != b'5' { + return Err(Error(format!( + "{}: archive root does not match binstall metadata.", + path.display() + ))); + } + let binary = &tar[512..1024]; + let second = member_name(binary)?; + if second != format!("{}/{}", artifact.root, artifact.binary) || binary[156] != b'0' { + return Err(Error(format!( + "{}: archive binary does not match binstall metadata.", + path.display() + ))); + } + let mode = octal(&binary[100..108])?; + if !artifact.target.split('-').any(|part| part == "windows") && mode & 0o111 == 0 { + return Err(Error(format!( + "{}: binary is not executable.", + path.display() + ))); + } + let size = octal(&binary[124..136])?; + let rounded = size + .checked_add(511) + .ok_or_else(|| Error("Archive size overflow.".into()))? + / 512 + * 512; + let end = 1024_u64 + .checked_add(rounded) + .and_then(|n| n.checked_add(1024)) + .ok_or_else(|| Error("Archive size overflow.".into()))?; + if end > tar.len() as u64 { + return Err(Error(format!( + "{}: truncated binary or tar footer.", + path.display() + ))); + } + if tar[(end - 1024) as usize..].iter().any(|b| *b != 0) { + return Err(Error(format!( + "{}: archive contains unexpected members.", + path.display() + ))); + } + Ok(()) +} + +fn member_name(header: &[u8]) -> Result { + let name = text_field(&header[..100])?; + let prefix = text_field(&header[345..500])?; + if prefix.is_empty() { + Ok(name) + } else { + Ok(format!("{prefix}/{name}")) + } +} + +fn text_field(field: &[u8]) -> Result { + let end = field.iter().position(|b| *b == 0).unwrap_or(field.len()); + std::str::from_utf8(&field[..end]) + .map(str::to_owned) + .map_err(|_| Error("Archive contains non-UTF-8 paths.".into())) +} + +fn octal(field: &[u8]) -> Result { + let bytes = field + .iter() + .take_while(|b| **b != 0) + .copied() + .collect::>(); + let string = + std::str::from_utf8(&bytes).map_err(|_| Error("Invalid tar numeric field.".into()))?; + u64::from_str_radix(string.trim(), 8).map_err(|_| Error("Invalid tar numeric field.".into())) +} + +pub fn verify_published( + repository: &str, + tag: &str, + artifacts: &[Artifact], + sums: &Path, +) -> Result<(), Error> { + let downloads = tempfile::Builder::new() + .prefix("rust-realease-download-") + .tempdir() + .map_err(|e| Error(format!("cannot create download directory: {e}")))?; + let client = Client::builder() + .timeout(Duration::from_secs(120)) + .redirect(reqwest::redirect::Policy::limited(10)) + .build() + .map_err(|_| Error("Cannot initialize anonymous download client.".into()))?; + for local in artifacts + .iter() + .map(|a| a.path.as_path()) + .chain(std::iter::once(sums)) + { + let filename = local + .file_name() + .and_then(|s| s.to_str()) + .ok_or_else(|| Error("Invalid asset filename.".into()))?; + let mut response = client + .get(asset_url(repository, tag, filename)) + .send() + .map_err(|_| Error(format!("{filename}: public download failed.")))?; + if response.status() != reqwest::StatusCode::OK { + return Err(Error(format!( + "{filename}: public download returned HTTP {}.", + response.status().as_u16() + ))); + } + let expected = fs::metadata(local) + .map_err(|e| { + Error(format!( + "cannot inspect local asset {}: {e}", + local.display() + )) + })? + .len(); + let path = downloads.path().join(filename); + let mut output = File::create(&path) + .map_err(|e| Error(format!("cannot create download {}: {e}", path.display())))?; + let mut count = 0_u64; + let mut buffer = [0_u8; 64 * 1024]; + loop { + let n = response + .read(&mut buffer) + .map_err(|_| Error(format!("{filename}: public download failed.")))?; + if n == 0 { + break; + } + count = count + .checked_add(n as u64) + .ok_or_else(|| Error("Download size overflow.".into()))?; + if count > expected { + return Err(Error(format!( + "{filename}: download exceeds expected size." + ))); + } + output + .write_all(&buffer[..n]) + .map_err(|e| Error(format!("cannot write download: {e}")))?; + } + drop(output); + if package::checksum(&path)? != package::checksum(local)? { + return Err(Error(format!( + "{filename}: published SHA-256 differs from local artifact." + ))); + } + if let Some(artifact) = artifacts.iter().find(|a| a.path == local) { + verify_archive(&path, artifact)?; + println!("Verified URL, checksum and archive: {}", artifact.target); + } + } + println!("Verified published SHA256SUMS"); + Ok(()) +} + +pub fn binstall_arguments(project: &SelectedPackage, target: &str, install: &Path) -> Vec { + vec![ + "binstall".into(), + project.name.clone(), + "--manifest-path".into(), + project.manifest.display().to_string(), + "--version".into(), + format!("={}", project.version), + "--targets".into(), + target.into(), + "--strategies".into(), + "crate-meta-data".into(), + "--no-confirm".into(), + "--no-track".into(), + "--disable-telemetry".into(), + "--no-discover-github-token".into(), + "--install-path".into(), + install.display().to_string(), + ] +} + +pub fn verify_binstall( + root: &Path, + project: &SelectedPackage, + targets: &[String], + runner: &Runner, +) -> Result<(), Error> { + for target in targets { + let temp = tempfile::Builder::new() + .prefix("rust-realease-binstall-") + .tempdir() + .map_err(|e| Error(format!("cannot create isolated install directory: {e}")))?; + let cargo_home = temp.path().join("cargo-home"); + let install = temp.path().join("install"); + fs::create_dir_all(&cargo_home) + .map_err(|e| Error(format!("cannot create isolated Cargo home: {e}")))?; + fs::create_dir_all(&install) + .map_err(|e| Error(format!("cannot create isolated install root: {e}")))?; + let args = binstall_arguments(project, target, &install); + let borrowed: Vec<_> = args.iter().map(String::as_str).collect(); + let cargo_home = cargo_home + .to_str() + .ok_or_else(|| Error("Cargo home path is not UTF-8.".into()))?; + runner.output_with("cargo", &borrowed, root, &[("CARGO_HOME", cargo_home)], &[])?; + let binary = install.join(policy::binary_filename(&project.binary, target)); + if !binary.is_file() { + return Err(Error(format!( + "cargo-binstall did not install the expected binary for {target}." + ))); + } + println!("cargo-binstall installation verified: {target}"); + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn anonymous_downloads_match_local_archives_and_checksums() { + use std::{net::TcpListener, thread}; + let temp = tempfile::tempdir().unwrap(); + let binary = temp.path().join("demo"); + fs::write(&binary, b"binary").unwrap(); + let (artifacts, sums) = package::package( + temp.path(), + "demo", + "0.1.0", + "demo", + &[("x86_64-unknown-linux-musl".into(), binary)], + ) + .unwrap(); + let filename = artifacts[0] + .path + .file_name() + .unwrap() + .to_str() + .unwrap() + .to_owned(); + let bodies = [ + (filename, fs::read(&artifacts[0].path).unwrap()), + ("SHA256SUMS".into(), fs::read(&sums).unwrap()), + ]; + let listener = TcpListener::bind("127.0.0.1:0").unwrap(); + let repository = format!("http://{}/team/demo", listener.local_addr().unwrap()); + let handle = thread::spawn(move || { + for (filename, body) in bodies { + let (mut stream, _) = listener.accept().unwrap(); + let mut buffer = [0_u8; 4096]; + let count = stream.read(&mut buffer).unwrap(); + let request = String::from_utf8_lossy(&buffer[..count]); + assert!(request.starts_with(&format!( + "GET /team/demo/releases/download/v0.1.0/{filename} " + ))); + assert!(!request.to_ascii_lowercase().contains("authorization:")); + write!( + stream, + "HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n", + body.len() + ) + .unwrap(); + stream.write_all(&body).unwrap(); + } + }); + verify_published(&repository, "v0.1.0", &artifacts, &sums).unwrap(); + handle.join().unwrap(); + } + + #[test] + fn local_archive_validation_and_binstall_command() { + let temp = tempfile::tempdir().unwrap(); + let binary = temp.path().join("demo"); + fs::write(&binary, b"binary").unwrap(); + let (artifacts, _) = package::package( + temp.path(), + "demo", + "0.1.0", + "demo", + &[("x86_64-unknown-linux-musl".into(), binary)], + ) + .unwrap(); + verify_archive(&artifacts[0].path, &artifacts[0]).unwrap(); + let project = SelectedPackage { + name: "demo".into(), + version: "0.1.0".into(), + binary: "demo".into(), + manifest: temp.path().join("Cargo.toml"), + repository: None, + target_directory: temp.path().join("target"), + }; + let args = binstall_arguments(&project, "x86_64-unknown-linux-musl", temp.path()); + assert!(args.contains(&"--no-track".to_owned())); + assert!(args.contains(&"--no-discover-github-token".to_owned())); + assert_eq!( + asset_url("https://example.com/team/demo", "release+1", "one.tgz"), + "https://example.com/team/demo/releases/download/release%2B1/one.tgz" + ); + } +}