@@ -10,6 +10,15 @@ interface MatrixInclude {
10
10
label ?: string ;
11
11
}
12
12
13
+ /**
14
+ * This methods generates a matrix for the GitHub Actions workflow to run the E2E tests.
15
+ * It checks which test applications are affected by the current changes in the PR and then generates a matrix
16
+ * including all test apps that have at least one dependency that was changed in the PR.
17
+ * If no `--base=xxx` is provided, it will output all test applications.
18
+ *
19
+ * If `--optional=true` is set, it will generate a matrix of optional test applications only.
20
+ * Otherwise, these will be skipped.
21
+ */
13
22
function run ( ) : void {
14
23
const args : Record < string , string > = { } ;
15
24
process . argv
@@ -22,30 +31,15 @@ function run(): void {
22
31
args [ argName ] = argValue ;
23
32
} ) ;
24
33
25
- // We default to `develop` as base, if none is specified
26
- // head has a correct default value anyhow
27
- const { base = 'develop' , head, optional = 'false' } = args ;
34
+ const { base, head, optional = 'false' } = args ;
28
35
29
36
const testApplications = globSync ( '*' , { cwd : `${ __dirname } /../test-applications/` } ) ;
30
37
31
- const additionalArgs = [ ] ;
32
- if ( base ) {
33
- additionalArgs . push ( `--base=${ base } ` ) ;
34
- }
35
- if ( head ) {
36
- additionalArgs . push ( `--head=${ head } ` ) ;
37
- }
38
-
39
- const affectedProjects = execSync ( `yarn --silent nx show projects --affected ${ additionalArgs . join ( ' ' ) } ` )
40
- . toString ( )
41
- . split ( '\n' )
42
- . map ( line => line . trim ( ) )
43
- . filter ( Boolean ) ;
44
-
45
- const includedTestApplications = testApplications . filter ( testApp => {
46
- const sentryDependencies = getSentryDependencies ( testApp ) ;
47
- return sentryDependencies . some ( dep => affectedProjects . includes ( dep ) ) ;
48
- } ) ;
38
+ // If `--base=xxx` is defined, we only want to get test applications changed since that base
39
+ // Else, we take all test applications (e.g. on push)
40
+ const includedTestApplications = base
41
+ ? getAffectedTestApplications ( testApplications , { base, head } )
42
+ : testApplications ;
49
43
50
44
const optionalMode = optional === 'true' ;
51
45
const includes : MatrixInclude [ ] = [ ] ;
@@ -121,3 +115,25 @@ function getPackageJson(appName: string): {
121
115
}
122
116
123
117
run ( ) ;
118
+
119
+ function getAffectedTestApplications (
120
+ testApplications : string [ ] ,
121
+ { base = 'develop' , head } : { base ?: string ; head ?: string } ,
122
+ ) : string [ ] {
123
+ const additionalArgs = [ `--base=${ base } ` ] ;
124
+
125
+ if ( head ) {
126
+ additionalArgs . push ( `--head=${ head } ` ) ;
127
+ }
128
+
129
+ const affectedProjects = execSync ( `yarn --silent nx show projects --affected ${ additionalArgs . join ( ' ' ) } ` )
130
+ . toString ( )
131
+ . split ( '\n' )
132
+ . map ( line => line . trim ( ) )
133
+ . filter ( Boolean ) ;
134
+
135
+ return testApplications . filter ( testApp => {
136
+ const sentryDependencies = getSentryDependencies ( testApp ) ;
137
+ return sentryDependencies . some ( dep => affectedProjects . includes ( dep ) ) ;
138
+ } ) ;
139
+ }
0 commit comments