@@ -4,7 +4,7 @@ use crate::{
4
4
error:: Result ,
5
5
registry_api:: { CrateData , CrateOwner , ReleaseData } ,
6
6
storage:: CompressionAlgorithm ,
7
- utils:: MetadataPackage ,
7
+ utils:: { rustc_version :: parse_rustc_date , MetadataPackage } ,
8
8
web:: crate_details:: { latest_release, releases_for_crate} ,
9
9
} ;
10
10
use anyhow:: Context ;
@@ -17,7 +17,7 @@ use std::{
17
17
io:: { BufRead , BufReader } ,
18
18
path:: Path ,
19
19
} ;
20
- use tracing:: { debug, info, instrument} ;
20
+ use tracing:: { debug, error , info, instrument} ;
21
21
22
22
/// Adds a package into database.
23
23
///
@@ -244,6 +244,17 @@ pub(crate) async fn finish_build(
244
244
debug ! ( "updating build after finishing" ) ;
245
245
let hostname = hostname:: get ( ) ?;
246
246
247
+ let rustc_date = match parse_rustc_date ( rustc_version) {
248
+ Ok ( date) => Some ( date) ,
249
+ Err ( err) => {
250
+ error ! (
251
+ "Failed to parse date from rustc version \" {}\" : {:?}" ,
252
+ rustc_version, err
253
+ ) ;
254
+ None
255
+ }
256
+ } ;
257
+
247
258
let release_id = sqlx:: query_scalar!(
248
259
"UPDATE builds
249
260
SET
@@ -252,15 +263,17 @@ pub(crate) async fn finish_build(
252
263
build_status = $3,
253
264
build_server = $4,
254
265
errors = $5,
266
+ rustc_nightly_date = $6,
255
267
build_time = NOW()
256
268
WHERE
257
- id = $6
269
+ id = $7
258
270
RETURNING rid" ,
259
271
rustc_version,
260
272
docsrs_version,
261
273
build_status as BuildStatus ,
262
274
hostname. to_str( ) . unwrap_or( "" ) ,
263
275
errors,
276
+ rustc_date,
264
277
build_id,
265
278
)
266
279
. fetch_one ( & mut * conn)
@@ -606,6 +619,7 @@ mod test {
606
619
use crate :: registry_api:: OwnerKind ;
607
620
use crate :: test:: * ;
608
621
use crate :: utils:: CargoMetadata ;
622
+ use chrono:: NaiveDate ;
609
623
use test_case:: test_case;
610
624
611
625
#[ test]
@@ -641,7 +655,55 @@ mod test {
641
655
}
642
656
643
657
#[ test]
644
- fn test_finish_build_success ( ) {
658
+ fn test_finish_build_success_valid_rustc_date ( ) {
659
+ async_wrapper ( |env| async move {
660
+ let mut conn = env. async_db ( ) . await . async_conn ( ) . await ;
661
+ let crate_id = initialize_crate ( & mut conn, "krate" ) . await ?;
662
+ let release_id = initialize_release ( & mut conn, crate_id, "0.1.0" ) . await ?;
663
+ let build_id = initialize_build ( & mut conn, release_id) . await ?;
664
+
665
+ finish_build (
666
+ & mut conn,
667
+ build_id,
668
+ "rustc 1.84.0-nightly (e7c0d2750 2024-10-15)" ,
669
+ "docsrs_version" ,
670
+ BuildStatus :: Success ,
671
+ None ,
672
+ )
673
+ . await ?;
674
+
675
+ let row = sqlx:: query!(
676
+ r#"SELECT
677
+ rustc_version,
678
+ docsrs_version,
679
+ build_status as "build_status: BuildStatus",
680
+ errors,
681
+ rustc_nightly_date
682
+ FROM builds
683
+ WHERE id = $1"# ,
684
+ build_id
685
+ )
686
+ . fetch_one ( & mut * conn)
687
+ . await ?;
688
+
689
+ assert_eq ! (
690
+ row. rustc_version,
691
+ Some ( "rustc 1.84.0-nightly (e7c0d2750 2024-10-15)" . into( ) )
692
+ ) ;
693
+ assert_eq ! ( row. docsrs_version, Some ( "docsrs_version" . into( ) ) ) ;
694
+ assert_eq ! ( row. build_status, BuildStatus :: Success ) ;
695
+ assert_eq ! (
696
+ row. rustc_nightly_date,
697
+ Some ( NaiveDate :: from_ymd_opt( 2024 , 10 , 15 ) . unwrap( ) )
698
+ ) ;
699
+ assert ! ( row. errors. is_none( ) ) ;
700
+
701
+ Ok ( ( ) )
702
+ } )
703
+ }
704
+
705
+ #[ test]
706
+ fn test_finish_build_success_invalid_rustc_date ( ) {
645
707
async_wrapper ( |env| async move {
646
708
let mut conn = env. async_db ( ) . await . async_conn ( ) . await ;
647
709
let crate_id = initialize_crate ( & mut conn, "krate" ) . await ?;
@@ -663,7 +725,8 @@ mod test {
663
725
rustc_version,
664
726
docsrs_version,
665
727
build_status as "build_status: BuildStatus",
666
- errors
728
+ errors,
729
+ rustc_nightly_date
667
730
FROM builds
668
731
WHERE id = $1"# ,
669
732
build_id
@@ -674,6 +737,7 @@ mod test {
674
737
assert_eq ! ( row. rustc_version, Some ( "rustc_version" . into( ) ) ) ;
675
738
assert_eq ! ( row. docsrs_version, Some ( "docsrs_version" . into( ) ) ) ;
676
739
assert_eq ! ( row. build_status, BuildStatus :: Success ) ;
740
+ assert ! ( row. rustc_nightly_date. is_none( ) ) ;
677
741
assert ! ( row. errors. is_none( ) ) ;
678
742
679
743
Ok ( ( ) )
0 commit comments