File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ path = "src/xtask.rs"
14
14
[dependencies ]
15
15
anyhow = " 1.0.68"
16
16
camino = " 1.0"
17
+ chrono = { version = " 0.4.23" , default_features = false , features = [" std" ] }
17
18
fn-error-context = " 0.2.0"
18
19
tempfile = " 3.3"
19
20
xshell = { version = " 0.2" }
Original file line number Diff line number Diff line change @@ -66,6 +66,17 @@ fn gitrev(sh: &Shell) -> Result<String> {
66
66
}
67
67
}
68
68
69
+ /// Return a string formatted version of the git commit timestamp, up to the minute
70
+ /// but not second because, well, we're not going to build more than once a second.
71
+ #[ context( "Finding git timestamp" ) ]
72
+ fn git_timestamp ( sh : & Shell ) -> Result < String > {
73
+ let ts = cmd ! ( sh, "git show --format=%ct" ) . read ( ) ?;
74
+ let ts = ts. trim ( ) . parse :: < i64 > ( ) ?;
75
+ let ts = chrono:: NaiveDateTime :: from_timestamp_opt ( ts, 0 )
76
+ . ok_or_else ( || anyhow:: anyhow!( "Failed to parse timestamp" ) ) ?;
77
+ Ok ( ts. format ( "%Y%m%d%H%M" ) . to_string ( ) )
78
+ }
79
+
69
80
struct Package {
70
81
version : String ,
71
82
srcpath : Utf8PathBuf ,
@@ -74,6 +85,9 @@ struct Package {
74
85
#[ context( "Packaging" ) ]
75
86
fn impl_package ( sh : & Shell ) -> Result < Package > {
76
87
let v = gitrev ( sh) ?;
88
+ let timestamp = git_timestamp ( sh) ?;
89
+ // We always inject the timestamp first to ensure that newer is better.
90
+ let v = format ! ( "{timestamp}.{v}" ) ;
77
91
let namev = format ! ( "{NAME}-{v}" ) ;
78
92
let p = Utf8Path :: new ( "target" ) . join ( format ! ( "{namev}.tar.zstd" ) ) ;
79
93
let o = File :: create ( & p) ?;
You can’t perform that action at this time.
0 commit comments