@@ -3,9 +3,11 @@ mod tests;
3
3
4
4
use std:: collections:: BTreeMap ;
5
5
6
+ use anyhow:: Context as _;
6
7
use serde_yaml:: Value ;
7
8
8
9
use crate :: GitHubContext ;
10
+ use crate :: utils:: load_env_var;
9
11
10
12
/// Representation of a job loaded from the `src/ci/github-actions/jobs.yml` file.
11
13
#[ derive( serde:: Deserialize , Debug , Clone ) ]
@@ -109,6 +111,27 @@ struct GithubActionsJob {
109
111
doc_url : Option < String > ,
110
112
}
111
113
114
+ /// Replace GitHub context variables with environment variables in job configs.
115
+ /// Useful for codebuild jobs like
116
+ /// `codebuild-ubuntu-22-8c-${{ github.run_id }}-${{ github.run_attempt }}`
117
+ fn substitute_github_vars ( jobs : Vec < Job > ) -> anyhow:: Result < Vec < Job > > {
118
+ let run_id = load_env_var ( "GITHUB_RUN_ID" ) ?;
119
+ let run_attempt = load_env_var ( "GITHUB_RUN_ATTEMPT" ) ?;
120
+
121
+ let jobs = jobs
122
+ . into_iter ( )
123
+ . map ( |mut job| {
124
+ job. os = job
125
+ . os
126
+ . replace ( "${{ github.run_id }}" , & run_id)
127
+ . replace ( "${{ github.run_attempt }}" , & run_attempt) ;
128
+ job
129
+ } )
130
+ . collect ( ) ;
131
+
132
+ Ok ( jobs)
133
+ }
134
+
112
135
/// Skip CI jobs that are not supposed to be executed on the given `channel`.
113
136
fn skip_jobs ( jobs : Vec < Job > , channel : & str ) -> Vec < Job > {
114
137
jobs. into_iter ( )
@@ -177,6 +200,8 @@ fn calculate_jobs(
177
200
}
178
201
RunType :: AutoJob => ( db. auto_jobs . clone ( ) , "auto" , & db. envs . auto_env ) ,
179
202
} ;
203
+ let jobs = substitute_github_vars ( jobs. clone ( ) )
204
+ . context ( "Failed to substitute GitHub context variables in jobs" ) ?;
180
205
let jobs = skip_jobs ( jobs, channel) ;
181
206
let jobs = jobs
182
207
. into_iter ( )
0 commit comments