@@ -10,7 +10,11 @@ import { GithubRunnersDatasource } from '../../datasource/github-runners';
10
10
import { GithubTagsDatasource } from '../../datasource/github-tags' ;
11
11
import * as dockerVersioning from '../../versioning/docker' ;
12
12
import { getDep } from '../dockerfile/extract' ;
13
- import type { PackageDependency , PackageFileContent } from '../types' ;
13
+ import type {
14
+ ExtractConfig ,
15
+ PackageDependency ,
16
+ PackageFileContent ,
17
+ } from '../types' ;
14
18
import type { Workflow } from './types' ;
15
19
16
20
const dockerActionRe = regEx ( / ^ \s + u s e s \s * : [ ' " ] ? d o c k e r : \/ \/ ( [ ^ ' " ] + ) \s * $ / ) ;
@@ -44,7 +48,10 @@ function detectCustomGitHubRegistryUrlsForActions(): PackageDependency {
44
48
return { } ;
45
49
}
46
50
47
- function extractWithRegex ( content : string ) : PackageDependency [ ] {
51
+ function extractWithRegex (
52
+ content : string ,
53
+ config : ExtractConfig ,
54
+ ) : PackageDependency [ ] {
48
55
const customRegistryUrlsPackageDependency =
49
56
detectCustomGitHubRegistryUrlsForActions ( ) ;
50
57
logger . trace ( 'github-actions.extractWithRegex()' ) ;
@@ -57,7 +64,7 @@ function extractWithRegex(content: string): PackageDependency[] {
57
64
const dockerMatch = dockerActionRe . exec ( line ) ;
58
65
if ( dockerMatch ) {
59
66
const [ , currentFrom ] = dockerMatch ;
60
- const dep = getDep ( currentFrom ) ;
67
+ const dep = getDep ( currentFrom , true , config . registryAliases ) ;
61
68
dep . depType = 'docker' ;
62
69
deps . push ( dep ) ;
63
70
continue ;
@@ -126,11 +133,14 @@ function detectDatasource(registryUrl: string): PackageDependency {
126
133
} ;
127
134
}
128
135
129
- function extractContainer ( container : unknown ) : PackageDependency | undefined {
136
+ function extractContainer (
137
+ container : unknown ,
138
+ registryAliases : Record < string , string > | undefined ,
139
+ ) : PackageDependency | undefined {
130
140
if ( is . string ( container ) ) {
131
- return getDep ( container ) ;
141
+ return getDep ( container , true , registryAliases ) ;
132
142
} else if ( is . plainObject ( container ) && is . string ( container . image ) ) {
133
- return getDep ( container . image ) ;
143
+ return getDep ( container . image , true , registryAliases ) ;
134
144
}
135
145
return undefined ;
136
146
}
@@ -181,6 +191,7 @@ function extractRunners(runner: unknown): PackageDependency[] {
181
191
function extractWithYAMLParser (
182
192
content : string ,
183
193
packageFile : string ,
194
+ config : ExtractConfig ,
184
195
) : PackageDependency [ ] {
185
196
logger . trace ( 'github-actions.extractWithYAMLParser()' ) ;
186
197
const deps : PackageDependency [ ] = [ ] ;
@@ -198,14 +209,14 @@ function extractWithYAMLParser(
198
209
}
199
210
200
211
for ( const job of Object . values ( pkg ?. jobs ?? { } ) ) {
201
- const dep = extractContainer ( job ?. container ) ;
212
+ const dep = extractContainer ( job ?. container , config . registryAliases ) ;
202
213
if ( dep ) {
203
214
dep . depType = 'container' ;
204
215
deps . push ( dep ) ;
205
216
}
206
217
207
218
for ( const service of Object . values ( job ?. services ?? { } ) ) {
208
- const dep = extractContainer ( service ) ;
219
+ const dep = extractContainer ( service , config . registryAliases ) ;
209
220
if ( dep ) {
210
221
dep . depType = 'service' ;
211
222
deps . push ( dep ) ;
@@ -221,11 +232,12 @@ function extractWithYAMLParser(
221
232
export function extractPackageFile (
222
233
content : string ,
223
234
packageFile : string ,
235
+ config : ExtractConfig = { } , // TODO: enforce ExtractConfig
224
236
) : PackageFileContent | null {
225
237
logger . trace ( `github-actions.extractPackageFile(${ packageFile } )` ) ;
226
238
const deps = [
227
- ...extractWithRegex ( content ) ,
228
- ...extractWithYAMLParser ( content , packageFile ) ,
239
+ ...extractWithRegex ( content , config ) ,
240
+ ...extractWithYAMLParser ( content , packageFile , config ) ,
229
241
] ;
230
242
if ( ! deps . length ) {
231
243
return null ;
0 commit comments