File tree Expand file tree Collapse file tree 4 files changed +63
-4
lines changed Expand file tree Collapse file tree 4 files changed +63
-4
lines changed Original file line number Diff line number Diff line change 1010
1111 # Only run for pull requests if relevant files were changed
1212 pull_request :
13- branches : [main]
13+ branches :
14+ - main
15+ - ' release/**'
1416 paths :
1517 - Dockerfile
1618 - docker-bake.hcl
3133 DOCKER_METADATA_ANNOTATIONS_LEVELS : manifest,index
3234
3335jobs :
36+ compute-version :
37+ name : Compute version using git describe
38+ runs-on : ubuntu-24.04
39+ outputs :
40+ describe : ${{ steps.git.outputs.describe }}
41+ timestamp : ${{ steps.git.outputs.timestamp }}
42+ steps :
43+ - name : Checkout the code
44+ 45+ with :
46+ # Need a full clone so that `git describe` reports the right version
47+ fetch-depth : 0
48+
49+ - name : Compute version and timestamp out of git history
50+ id : git
51+ run : |
52+ echo "describe=$(git describe --tags --match 'v*.*.*' --always)" >> $GITHUB_OUTPUT
53+ echo "timestamp=$(git log -1 --format=%ct)" >> $GITHUB_OUTPUT
54+
55+
3456 build-binaries :
3557 name : Build binaries
3658 runs-on : ubuntu-22.04
3759
60+ needs :
61+ - compute-version
62+
63+ env :
64+ VERGEN_GIT_DESCRIBE : ${{ needs.compute-version.outputs.describe }}
65+ SOURCE_DATE_EPOCH : ${{ needs.compute-version.outputs.timestamp }}
66+
3867 permissions :
3968 contents : read
4069
@@ -136,6 +165,13 @@ jobs:
136165 packages : write
137166 id-token : write
138167
168+ needs :
169+ - compute-version
170+
171+ env :
172+ VERGEN_GIT_DESCRIBE : ${{ needs.compute-version.outputs.describe }}
173+ SOURCE_DATE_EPOCH : ${{ needs.compute-version.outputs.timestamp }}
174+
139175 steps :
140176 - name : Docker meta
141177 id : meta
Original file line number Diff line number Diff line change @@ -142,6 +142,10 @@ RUN --network=default \
142142# Build the rest
143143COPY ./ /app
144144ENV SQLX_OFFLINE=true
145+
146+ ARG VERGEN_GIT_DESCRIBE
147+ ENV VERGEN_GIT_DESCRIBE=${VERGEN_GIT_DESCRIBE}
148+
145149# Network access: cargo auditable needs it
146150RUN --network=default \
147151 cargo auditable build \
Original file line number Diff line number Diff line change 1- // Copyright 2024 New Vector Ltd.
1+ // Copyright 2024, 2025 New Vector Ltd.
22//
33// SPDX-License-Identifier: AGPL-3.0-only
44// Please see LICENSE in the repository root for full details.
55
66use vergen_gitcl:: { Emitter , GitclBuilder , RustcBuilder } ;
77
88fn main ( ) -> anyhow:: Result < ( ) > {
9- let gitcl = GitclBuilder :: default ( ) . describe ( true , true , None ) . build ( ) ?;
9+ // At build time, we override the version through the environment variable
10+ // VERGEN_GIT_DESCRIBE. In some contexts, it means this variable is set but
11+ // empty, so we unset it here.
12+ if let Ok ( ver) = std:: env:: var ( "VERGEN_GIT_DESCRIBE" ) {
13+ if ver. is_empty ( ) {
14+ std:: env:: remove_var ( "VERGEN_GIT_DESCRIBE" ) ;
15+ }
16+ }
17+
18+ let gitcl = GitclBuilder :: default ( )
19+ . describe ( true , false , Some ( "v*.*.*" ) )
20+ . build ( ) ?;
1021 let rustc = RustcBuilder :: default ( ) . semver ( true ) . build ( ) ?;
1122
1223 Emitter :: default ( )
Original file line number Diff line number Diff line change 1+ // This is used to set the version reported by the binary through an environment
2+ // variable. This is mainly useful when building out of a git context, like in
3+ // CI, where we don't have the full commit history available
4+ variable "VERGEN_GIT_DESCRIBE" {}
5+
16// This is what is baked by GitHub Actions
27group "default" { targets = [" regular" , " debug" , " syn2mas" ] }
38
@@ -11,8 +16,11 @@ target "docker-metadata-action-syn2mas" {}
1116target "base" {
1217 args = {
1318 // This is set so that when we use a git context, the .git directory is
14- // present, as we infer the version at build time out of it
19+ // present, as we may be infering the version at build time out of it
1520 BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
21+
22+ // Pass down the version from an external git describe source
23+ VERGEN_GIT_DESCRIBE = " ${ VERGEN_GIT_DESCRIBE } "
1624 }
1725
1826 platforms = [
You can’t perform that action at this time.
0 commit comments