Skip to content

Commit

Permalink
added changeset ps1 script and updated xpack-winlogbeat pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
oakrizan committed Apr 17, 2024
1 parent 9be4ecc commit 29d1b4a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .buildkite/scripts/changesets.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
OSS_MODULE_PATTERN="^[a-z0-9]+beat/module/([^/]+)/.*"
XPACK_MODULE_PATTERN="^x-pack/[a-z0-9]+beat/module/([^/]+)/.*"

function ArePathsChanged($patterns) {
$changedlist = @()
foreach ($pattern in $patterns) {
$changedFiles = & git diff --name-only "HEAD@{1}" HEAD | Select-String -Pattern $pattern
if ($changedFiles) {
$changedlist += $changedFiles
}
}
if ($changedlist) {
Write-Output "Files changed:"
Write-Output $changedlist
return $true
}
else {
Write-Output "No files changed within specified changeset:"
Write-Output $patterns
return $false
}
}

function AreChangedOnlyPaths($patterns) {
$changedFiles = & git diff --name-only "HEAD@{1}" HEAD
$matchedFiles = @()
foreach ($pattern in $patterns) {
$matched = $changedFiles | Select-String -Pattern $pattern
if ($matched) {
$matchedFiles += $matched
}
}
if (($matchedFiles.Count -eq $changedFiles.Count) -or ($changedFiles.Count -eq 0)) {
return $true
}
return $false
}

# This function sets a `MODULE` env var, required by IT tests, containing a comma separated list of modules for a given beats project (specified via the first argument).
# The list is built depending on directories that have changed under `modules/` excluding anything else such as asciidoc and png files.
# `MODULE` will empty if no changes apply.
function DefineModuleFromTheChangeSet($projectPath) {
$projectPathTransformed = $projectPath -replace '\', '\\'
$projectPathExclusion = "((?!^$projectPathTransformed\/).*\$|((?!\/module\/).*\$|.*\.asciidoc|.*\.png)"
$exclude = "$projectPathExclusion"
$changedModules = ''

$moduleDirs = Get-ChildItem -Directory "$projectPath\module"
foreach($moduleDir in $moduleDirs) {
if((ArePathsChanged($moduleDir)) -and !(AreChangedOnlyPaths($exclude))) {
if(!$changedModules) {
$changedModules = $moduleDir.Name
}
else {
$changedModules += ',' + $moduleDir.Name
}
}
}

# TODO: remove this conditional when issue https://github.com/elastic/ingest-dev/issues/2993 gets resolved
if(!$changedModules) {
if($Env:BUILDKITE_PIPELINE_SLUG -eq 'beats-xpack-metricbeat') {
$Env:MODULE = "aws"
}
else {
# TODO: once https://github.com/elastic/ingest-dev/issues/2993 gets resolved, this should be the only thing we export
$Env:MODULE = "kubernetes"
}
}
else {
$Env:MODULE = $changedModules
}
}
1 change: 1 addition & 0 deletions .buildkite/scripts/changesets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ defineModuleFromTheChangeSet() {
else
local pattern=("$OSS_MODULE_PATTERN")
fi

local changed_modules=""
local module_dirs=$(find "$project_path/module" -mindepth 1 -maxdepth 1 -type d)
for module_dir in $module_dirs; do
Expand Down
3 changes: 3 additions & 0 deletions .buildkite/x-pack/pipeline.xpack.winlogbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ steps:
- label: ":windows: Xpack/Winlogbeat Win-2019 Unit (MODULE) Tests"
key: "mandatory-win-2019-module-unit-tests"
command: |
Import-Module .\.buildkite\scripts\changesets.psm1
$MODULE = defineModuleFromTheChangeSet ('.\x-pack\winlogbeat')
Write-Output "~~~ Will run tests with env var MODULE=$MODULE"
Set-Location -Path x-pack/winlogbeat
mage build unitTest
env:
Expand Down

0 comments on commit 29d1b4a

Please sign in to comment.