Skip to content

Commit bbe007d

Browse files
authored
Merge pull request #657 from Kobzol/git-embed-version
Embed bors git version into `@bors ping` response
2 parents dfed400 + bca93ce commit bbe007d

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

.github/workflows/deploy-production.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
push: true
4141
cache-from: type=gha
4242
cache-to: type=gha,mode=max
43+
build-args: GIT_VERSION=${{ github.sha }}
4344

4445
- name: Kick ECS to deploy new version
4546
run: |

.github/workflows/deploy-staging.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
push: true
4343
cache-from: type=gha
4444
cache-to: type=gha,mode=max
45+
build-args: GIT_VERSION=${{ github.sha }}
4546

4647
- name: Kick ECS to deploy new version
4748
run: |

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ COPY web web
2626
# Precompress static web assets with gzip to avoid paying for their compression cost at runtime
2727
RUN gzip --keep --best --force --recursive web/assets
2828

29+
ARG GIT_VERSION=unknown
30+
ENV GIT_VERSION=${GIT_VERSION}
31+
2932
RUN cargo build --release
3033

3134
FROM ubuntu:24.04 AS runtime

src/bors/handlers/ping.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::fmt::Write;
12
use std::sync::Arc;
23

34
use crate::PgDbClient;
@@ -10,8 +11,15 @@ pub(super) async fn command_ping(
1011
db: &PgDbClient,
1112
pr_number: PullRequestNumber,
1213
) -> anyhow::Result<()> {
14+
let mut msg = "Pong :ping_pong:!".to_string();
15+
16+
// We don't embed the git version automatically, e.g. through the
17+
// `git-version` crate, because for production we build bors in Docker anyway, where there
18+
// is no git repo.
19+
let git_version = option_env!("GIT_VERSION").unwrap_or_else(|| "unknown");
20+
writeln!(msg, "\n\nbors build: `{git_version}`").unwrap();
1321
repo.client
14-
.post_comment(pr_number, Comment::new("Pong 🏓!".to_string()), db)
22+
.post_comment(pr_number, Comment::new(msg), db)
1523
.await?;
1624
Ok(())
1725
}
@@ -24,7 +32,11 @@ mod tests {
2432
async fn ping_command(pool: sqlx::PgPool) {
2533
run_test(pool, async |ctx: &mut BorsTester| {
2634
ctx.post_comment("@bors ping").await?;
27-
assert_eq!(ctx.get_next_comment_text(()).await?, "Pong 🏓!");
35+
insta::assert_snapshot!(ctx.get_next_comment_text(()).await?, @"
36+
Pong :ping_pong:!
37+
38+
bors build: `unknown`
39+
");
2840
Ok(())
2941
})
3042
.await;

0 commit comments

Comments
 (0)