|
1 | 1 | <# |
2 | 2 | .SYNOPSIS |
3 | | - Filters test projects for CI workflows. |
| 3 | + Filters test projects based on changed files to optimize CI workflow execution. |
4 | 4 |
|
5 | 5 | .DESCRIPTION |
6 | | - Receives test project objects from the pipeline and returns them. |
7 | | - Currently, all projects are passed through unchanged. |
| 6 | + Analyzes changed files and determines which test projects need to run. Protected |
| 7 | + branches and global repository changes run all tests. Other branches run only |
| 8 | + affected modules. |
8 | 9 | #> |
9 | 10 |
|
10 | 11 | $PROTECTED_BRANCHES = @( |
11 | | - 'main', |
12 | | - 'develop' |
| 12 | + "main", |
| 13 | + "develop" |
13 | 14 | ) |
14 | 15 |
|
15 | 16 | $GLOBAL_PATTERNS = @( |
16 | | - '^\.github/scripts/', |
17 | | - '^\.github/workflows/', |
18 | | - '^build/', |
19 | | - '^Directory\.Build\.props$', |
20 | | - '^Directory\.Packages\.props$', |
21 | | - '^src/Testcontainers/' |
| 17 | + "^\.github/scripts/", |
| 18 | + "^\.github/workflows/", |
| 19 | + "^build/", |
| 20 | + "^Directory\.Build\.props$", |
| 21 | + "^Directory\.Packages\.props$", |
| 22 | + "^src/Testcontainers/" |
22 | 23 | ) |
23 | 24 |
|
24 | 25 | $DATABASE_MODULES = @( |
25 | | - 'Testcontainers.Cassandra', |
26 | | - 'Testcontainers.ClickHouse', |
27 | | - 'Testcontainers.CockroachDb', |
28 | | - 'Testcontainers.Db2', |
29 | | - 'Testcontainers.FirebirdSql', |
30 | | - 'Testcontainers.MariaDb', |
31 | | - 'Testcontainers.MsSql', |
32 | | - 'Testcontainers.MySql', |
33 | | - 'Testcontainers.Oracle', |
34 | | - 'Testcontainers.PostgreSql', |
35 | | - 'Testcontainers.Xunit', |
36 | | - 'Testcontainers.XunitV3' |
| 26 | + "Testcontainers.Cassandra", |
| 27 | + "Testcontainers.ClickHouse", |
| 28 | + "Testcontainers.CockroachDb", |
| 29 | + "Testcontainers.Db2", |
| 30 | + "Testcontainers.FirebirdSql", |
| 31 | + "Testcontainers.MariaDb", |
| 32 | + "Testcontainers.MsSql", |
| 33 | + "Testcontainers.MySql", |
| 34 | + "Testcontainers.Oracle", |
| 35 | + "Testcontainers.PostgreSql", |
| 36 | + "Testcontainers.Xunit", |
| 37 | + "Testcontainers.XunitV3" |
37 | 38 | ) |
38 | 39 |
|
39 | 40 | $ORACLE_MODULES = @( |
40 | | - 'Testcontainers.Oracle', |
41 | | - 'Testcontainers.Oracle11', |
42 | | - 'Testcontainers.Oracle18', |
43 | | - 'Testcontainers.Oracle21', |
44 | | - 'Testcontainers.Oracle23' |
| 41 | + "Testcontainers.Oracle", |
| 42 | + "Testcontainers.Oracle11", |
| 43 | + "Testcontainers.Oracle18", |
| 44 | + "Testcontainers.Oracle21", |
| 45 | + "Testcontainers.Oracle23" |
45 | 46 | ) |
46 | 47 |
|
47 | 48 | $XUNIT_MODULES = @( |
48 | | - 'Testcontainers.Xunit', |
49 | | - 'Testcontainers.XunitV3' |
| 49 | + "Testcontainers.Xunit", |
| 50 | + "Testcontainers.XunitV3" |
50 | 51 | ) |
51 | 52 |
|
52 | 53 | function Should-RunTests { |
53 | 54 | param ([string]$ModuleName) |
54 | 55 |
|
55 | | - return $false |
56 | | - |
57 | 56 | If ($script:branch -In $PROTECTED_BRANCHES) { |
58 | 57 | Write-Host "Running '$ModuleName': protected branch '$script:branch'." |
59 | | - return $true |
| 58 | + return $True |
60 | 59 | } |
61 | 60 |
|
62 | 61 | ForEach ($pattern In $GLOBAL_PATTERNS) { |
63 | 62 | If ($script:allChangedFiles | Where-Object { $_ -Match $pattern }) { |
64 | 63 | Write-Host "Running '$ModuleName': global changes detected ($pattern)." |
65 | | - return $true |
| 64 | + return $True |
66 | 65 | } |
67 | 66 | } |
68 | 67 |
|
69 | 68 | If ($script:allChangedFiles | Where-Object { $_ -Match "^(src|tests)/$ModuleName" }) { |
70 | 69 | Write-Host "Running '$ModuleName': module-specific changes detected." |
71 | | - return $true |
| 70 | + return $True |
72 | 71 | } |
73 | 72 |
|
74 | 73 | If ($ModuleName -In $DATABASE_MODULES -And ($script:allChangedFiles | Where-Object { $_ -Match '^tests/Testcontainers\.Databases\.Tests' })) { |
75 | 74 | Write-Host "Running '$ModuleName': database test changes detected." |
76 | | - return $true |
| 75 | + return $True |
77 | 76 | } |
78 | 77 |
|
79 | 78 | If ($ModuleName -In $ORACLE_MODULES -And ($script:allChangedFiles | Where-Object { $_ -Match '^(src|tests)/Testcontainers\.Oracle' })) { |
80 | 79 | Write-Host "Running '$ModuleName': Oracle module changes detected." |
81 | | - return $true |
| 80 | + return $True |
82 | 81 | } |
83 | 82 |
|
84 | 83 | If ($ModuleName -In $XUNIT_MODULES -And ($script:allChangedFiles | Where-Object { $_ -Match '^(src|tests)/Testcontainers\.Xunit(V3)?' })) { |
85 | 84 | Write-Host "Running '$ModuleName': xUnit module changes detected." |
86 | | - return $true |
| 85 | + return $True |
87 | 86 | } |
88 | 87 |
|
89 | 88 | Write-Host "Skipping '$ModuleName': no relevant changes detected." |
90 | | - return $false |
| 89 | + return $False |
91 | 90 | } |
92 | 91 |
|
93 | 92 | function Filter-TestProjects { |
94 | 93 | [CmdletBinding()] |
95 | 94 | Param ( |
96 | | - [Parameter(ValueFromPipeline = $true)] |
| 95 | + [Parameter(ValueFromPipeline = $True)] |
97 | 96 | $TestProject |
98 | 97 | ) |
99 | 98 |
|
|
0 commit comments