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 1694cf1
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 62 deletions.
76 changes: 76 additions & 0 deletions .buildkite/scripts/changesets.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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\\\/).)*\$"
$exclude = @("^($projectPathExclusion|((?!\\/module\\/).)*\$|.*\\.asciidoc|.*\\.png)")

$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) {
Write-Output "--- CHANGED MODULES: $changedModules"
Write-Output "--- DEFINING MODULE"
Write-Output "--- Slug: $Env:BUILDKITE_PIPELINE_SLUG"

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 {
Write-Output "--- CHANGE MODULES not defined"
$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
127 changes: 65 additions & 62 deletions .buildkite/x-pack/pipeline.xpack.winlogbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ steps:
- label: ":windows: Xpack/Winlogbeat Win-2019 Unit (MODULE) Tests"
key: "mandatory-win-2019-module-unit-tests"
command: |
Set-Location -Path x-pack/winlogbeat
Import-Module .\.buildkite\scripts\changesets.psm1
defineModuleFromTheChangeSet 'x-pack\winlogbeat'
Write-Output "~~~ Will run tests with env var MODULE=$Env:MODULE"
Set-Location -Path x-pack\winlogbeat
mage build unitTest
env:
MODULE: $MODULE
Expand All @@ -39,41 +42,41 @@ steps:
- github_commit_status:
context: "Xpack/Winlogbeat Win-2019 Unit (MODULE) Tests"

- label: ":windows: Xpack/Winlogbeat Win-2016 Unit Tests"
command: |
Set-Location -Path x-pack/winlogbeat
mage build unitTest
key: "mandatory-win-2016-unit-tests"
agents:
provider: "gcp"
image: "${IMAGE_WIN_2016}"
machine_type: "${GCP_WIN_MACHINE_TYPE}"
disk_size: 100
disk_type: "pd-ssd"
artifact_paths:
- "x-pack/winlogbeat/build/*.xml"
- "x-pack/winlogbeat/build/*.json"
notify:
- github_commit_status:
context: "Xpack/Winlogbeat Win-2016 Unit Tests"

- label: ":windows: Xpack/Winlogbeat Win-2022 Unit Tests"
command: |
Set-Location -Path x-pack/winlogbeat
mage build unitTest
key: "mandatory-win-2022-unit-tests"
agents:
provider: "gcp"
image: "${IMAGE_WIN_2022}"
machine_type: "${GCP_WIN_MACHINE_TYPE}"
disk_size: 100
disk_type: "pd-ssd"
artifact_paths:
- "x-pack/winlogbeat/build/*.xml"
- "x-pack/winlogbeat/build/*.json"
notify:
- github_commit_status:
context: "Xpack/Winlogbeat Win-2022 Unit Tests"
# - label: ":windows: Xpack/Winlogbeat Win-2016 Unit Tests"
# command: |
# Set-Location -Path x-pack/winlogbeat
# mage build unitTest
# key: "mandatory-win-2016-unit-tests"
# agents:
# provider: "gcp"
# image: "${IMAGE_WIN_2016}"
# machine_type: "${GCP_WIN_MACHINE_TYPE}"
# disk_size: 100
# disk_type: "pd-ssd"
# artifact_paths:
# - "x-pack/winlogbeat/build/*.xml"
# - "x-pack/winlogbeat/build/*.json"
# notify:
# - github_commit_status:
# context: "Xpack/Winlogbeat Win-2016 Unit Tests"
#
# - label: ":windows: Xpack/Winlogbeat Win-2022 Unit Tests"
# command: |
# Set-Location -Path x-pack/winlogbeat
# mage build unitTest
# key: "mandatory-win-2022-unit-tests"
# agents:
# provider: "gcp"
# image: "${IMAGE_WIN_2022}"
# machine_type: "${GCP_WIN_MACHINE_TYPE}"
# disk_size: 100
# disk_type: "pd-ssd"
# artifact_paths:
# - "x-pack/winlogbeat/build/*.xml"
# - "x-pack/winlogbeat/build/*.json"
# notify:
# - github_commit_status:
# context: "Xpack/Winlogbeat Win-2022 Unit Tests"

- group: "Extended Windows Tests"
key: "extended-win-tests"
Expand Down Expand Up @@ -134,30 +137,30 @@ steps:
- github_commit_status:
context: "x-pack/winlogbeat: Win-2019 Unit Tests"

- wait: ~
# with PRs, we want to run packaging only if mandatory tests succeed
# for other cases, e.g. merge commits, we want to run packaging (and publish) independently of other tests
# this allows building DRA artifacts even if there is flakiness in mandatory tests
if: build.env("BUILDKITE_PULL_REQUEST") != "false"
depends_on:
- "xpack-winlogbeat-mandatory-tests"

- group: "Xpack/Winlogbeat Packaging"
key: "xpack-winlogbeat-packaging"

steps:
- label: ":ubuntu: Packaging Linux"
key: "packaging-linux"
command: "cd x-pack/winlogbeat && mage package"
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "${GCP_HI_PERF_MACHINE_TYPE}"
disk_size: 100
disk_type: "pd-ssd"
env:
PLATFORMS: "+all linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64"
notify:
- github_commit_status:
context: "Xpack/Winlogbeat Packaging"
# - wait: ~
# # with PRs, we want to run packaging only if mandatory tests succeed
# # for other cases, e.g. merge commits, we want to run packaging (and publish) independently of other tests
# # this allows building DRA artifacts even if there is flakiness in mandatory tests
# if: build.env("BUILDKITE_PULL_REQUEST") != "false"
# depends_on:
# - "xpack-winlogbeat-mandatory-tests"
#
# - group: "Xpack/Winlogbeat Packaging"
# key: "xpack-winlogbeat-packaging"
#
# steps:
# - label: ":ubuntu: Packaging Linux"
# key: "packaging-linux"
# command: "cd x-pack/winlogbeat && mage package"
# agents:
# provider: "gcp"
# image: "${IMAGE_UBUNTU_X86_64}"
# machineType: "${GCP_HI_PERF_MACHINE_TYPE}"
# disk_size: 100
# disk_type: "pd-ssd"
# env:
# PLATFORMS: "+all linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64"
# notify:
# - github_commit_status:
# context: "Xpack/Winlogbeat Packaging"

0 comments on commit 1694cf1

Please sign in to comment.