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 10
10
11
11
# Only run for pull requests if relevant files were changed
12
12
pull_request :
13
- branches : [main]
13
+ branches :
14
+ - main
15
+ - ' release/**'
14
16
paths :
15
17
- Dockerfile
16
18
- docker-bake.hcl
31
33
DOCKER_METADATA_ANNOTATIONS_LEVELS : manifest,index
32
34
33
35
jobs :
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
+ uses : actions/checkout@v4.2.2
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
+
34
56
build-binaries :
35
57
name : Build binaries
36
58
runs-on : ubuntu-22.04
37
59
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
+
38
67
permissions :
39
68
contents : read
40
69
@@ -136,6 +165,13 @@ jobs:
136
165
packages : write
137
166
id-token : write
138
167
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
+
139
175
steps :
140
176
- name : Docker meta
141
177
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