File tree Expand file tree Collapse file tree 4 files changed +60
-3
lines changed Expand file tree Collapse file tree 4 files changed +60
-3
lines changed Original file line number Diff line number Diff line change 31
31
DOCKER_METADATA_ANNOTATIONS_LEVELS : manifest,index
32
32
33
33
jobs :
34
+ compute-version :
35
+ name : Compute version using git describe
36
+ runs-on : ubuntu-24.04
37
+ outputs :
38
+ describe : ${{ steps.git.outputs.describe }}
39
+ timestamp : ${{ steps.git.outputs.timestamp }}
40
+ steps :
41
+ - name : Checkout the code
42
+ uses : actions/checkout@v4.2.2
43
+ with :
44
+ # Need a full clone so that `git describe` reports the right version
45
+ fetch-depth : 0
46
+
47
+ - name : Compute version and timestamp out of git history
48
+ id : git
49
+ run : |
50
+ echo "describe=$(git describe --tags --match 'v*.*.*' --always)" >> $GITHUB_OUTPUT
51
+ echo "timestamp=$(git log -1 --format=%ct)" >> $GITHUB_OUTPUT
52
+
53
+
34
54
build-binaries :
35
55
name : Build binaries
36
56
runs-on : ubuntu-22.04
37
57
58
+ needs :
59
+ - compute-version
60
+
61
+ env :
62
+ VERGEN_GIT_DESCRIBE : ${{ needs.compute-version.outputs.describe }}
63
+ SOURCE_DATE_EPOCH : ${{ needs.compute-version.outputs.timestamp }}
64
+
38
65
permissions :
39
66
contents : read
40
67
@@ -136,6 +163,13 @@ jobs:
136
163
packages : write
137
164
id-token : write
138
165
166
+ needs :
167
+ - compute-version
168
+
169
+ env :
170
+ VERGEN_GIT_DESCRIBE : ${{ needs.compute-version.outputs.describe }}
171
+ SOURCE_DATE_EPOCH : ${{ needs.compute-version.outputs.timestamp }}
172
+
139
173
steps :
140
174
- name : Docker meta
141
175
id : meta
Original file line number Diff line number Diff line change @@ -142,6 +142,10 @@ RUN --network=default \
142
142
# Build the rest
143
143
COPY ./ /app
144
144
ENV SQLX_OFFLINE=true
145
+
146
+ ARG VERGEN_GIT_DESCRIBE
147
+ ENV VERGEN_GIT_DESCRIBE=${VERGEN_GIT_DESCRIBE}
148
+
145
149
# Network access: cargo auditable needs it
146
150
RUN --network=default \
147
151
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.
2
2
//
3
3
// SPDX-License-Identifier: AGPL-3.0-only
4
4
// Please see LICENSE in the repository root for full details.
5
5
6
6
use vergen_gitcl:: { Emitter , GitclBuilder , RustcBuilder } ;
7
7
8
8
fn 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 ( ) ?;
10
21
let rustc = RustcBuilder :: default ( ) . semver ( true ) . build ( ) ?;
11
22
12
23
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
+
1
6
// This is what is baked by GitHub Actions
2
7
group "default" { targets = [" regular" , " debug" , " syn2mas" ] }
3
8
@@ -11,8 +16,11 @@ target "docker-metadata-action-syn2mas" {}
11
16
target "base" {
12
17
args = {
13
18
// 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
15
20
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 } "
16
24
}
17
25
18
26
platforms = [
You can’t perform that action at this time.
0 commit comments