File tree Expand file tree Collapse file tree 4 files changed +41
-5
lines changed
crates_io_database_dump/src Expand file tree Collapse file tree 4 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ impl DumpDirectory {
7070 }
7171 let metadata = Metadata {
7272 timestamp : & self . timestamp ,
73- crates_io_commit : crates_io_heroku:: slug_commit ( )
73+ crates_io_commit : crates_io_heroku:: commit ( )
7474 . ok ( )
7575 . flatten ( )
7676 . unwrap_or_else ( || "unknown" . to_owned ( ) ) ,
Original file line number Diff line number Diff line change 22
33use crates_io_env_vars:: var;
44
5+ /// Returns the Git SHA of the currently deployed commit.
6+ ///
7+ /// This function tries `HEROKU_BUILD_COMMIT` first (the current standard),
8+ /// and falls back to `HEROKU_SLUG_COMMIT` (deprecated) if the former is not
9+ /// set. This provides compatibility with both old and new Heroku deployments.
10+ ///
11+ /// Both environment variables are set by Heroku when the appropriate Labs
12+ /// features are enabled (`runtime-dyno-build-metadata` for `HEROKU_BUILD_COMMIT`,
13+ /// `runtime-dyno-metadata` for `HEROKU_SLUG_COMMIT`).
14+ ///
15+ /// Returns `None` if neither variable is set (e.g., in local development).
16+ ///
17+ /// See <https://devcenter.heroku.com/articles/dyno-metadata> for more
18+ /// information.
19+ ///
20+ /// # Examples
21+ ///
22+ /// ```
23+ /// use crates_io_heroku::commit;
24+ ///
25+ /// if let Ok(Some(commit)) = commit() {
26+ /// println!("Running commit: {}", commit);
27+ /// } else {
28+ /// println!("Commit SHA unknown");
29+ /// }
30+ /// ```
31+ pub fn commit ( ) -> anyhow:: Result < Option < String > > {
32+ // Try the current standard first
33+ if let Some ( commit) = build_commit ( ) ? {
34+ return Ok ( Some ( commit) ) ;
35+ }
36+
37+ // Fall back to the deprecated variable for backward compatibility
38+ slug_commit ( )
39+ }
40+
541/// Returns the Git SHA of the currently deployed commit.
642///
743/// This value comes from the `HEROKU_SLUG_COMMIT` environment variable,
Original file line number Diff line number Diff line change 11use anyhow:: Context ;
22use crates_io_env_vars:: { required_var, var, var_parsed} ;
3- use crates_io_heroku:: slug_commit ;
3+ use crates_io_heroku:: commit ;
44use sentry:: IntoDsn ;
55use sentry:: types:: Dsn ;
66
@@ -29,7 +29,7 @@ impl SentryConfig {
2929 Ok ( Self {
3030 dsn,
3131 environment,
32- release : slug_commit ( ) ?,
32+ release : commit ( ) ?,
3333 traces_sample_rate : var_parsed ( "SENTRY_TRACES_SAMPLE_RATE" ) ?. unwrap_or ( 0.0 ) ,
3434 } )
3535 }
Original file line number Diff line number Diff line change 11use crate :: app:: AppState ;
22use axum:: Json ;
33use axum:: response:: IntoResponse ;
4- use crates_io_heroku:: slug_commit ;
4+ use crates_io_heroku:: commit ;
55use serde:: Serialize ;
66
77#[ derive( Debug , Serialize , utoipa:: ToSchema ) ]
@@ -34,7 +34,7 @@ pub struct MetadataResponse<'a> {
3434pub async fn get_site_metadata ( state : AppState ) -> impl IntoResponse {
3535 let read_only = state. config . db . are_all_read_only ( ) ;
3636
37- let deployed_sha = slug_commit ( ) . ok ( ) . flatten ( ) ;
37+ let deployed_sha = commit ( ) . ok ( ) . flatten ( ) ;
3838 let deployed_sha = deployed_sha. as_deref ( ) . unwrap_or ( "unknown" ) ;
3939
4040 Json ( MetadataResponse {
You can’t perform that action at this time.
0 commit comments