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 19, 2024
1 parent 9fede42 commit 0871809
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 29 deletions.
71 changes: 71 additions & 0 deletions .buildkite/scripts/changesets.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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) {
if($Env:BUILDKITE_PIPELINE_SLUG -eq 'beats-xpack-metricbeat') {
$Env:MODULE = "aws"
}
else {
$Env:MODULE = "kubernetes"
}
}
else {
# TODO: once https://github.com/elastic/ingest-dev/issues/2993 gets resolved, this should be the only thing we export
$Env:MODULE = $changedModules
}
}
5 changes: 1 addition & 4 deletions .buildkite/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ case "${BUILDKITE_PIPELINE_SLUG}" in
"beats-packetbeat")
BEAT_CHANGESET_REFERENCE=${packetbeat_changeset[@]}
;;
"beats-winlogbeat")
BEAT_CHANGESET_REFERENCE=${winlogbeat_changeset[@]}
;;
"beats-xpack-libbeat")
BEAT_CHANGESET_REFERENCE=${xpack_libbeat_changeset[@]}
;;
Expand Down Expand Up @@ -530,7 +527,7 @@ if are_paths_changed "${packaging_changeset[@]}" ; then
export PACKAGING_CHANGES="true"
fi

if [[ "$BUILDKITE_STEP_KEY" == "xpack-winlogbeat-pipeline" || "$BUILDKITE_STEP_KEY" == "xpack-metricbeat-pipeline" || "$BUILDKITE_STEP_KEY" == "xpack-dockerlogbeat-pipeline" || "$BUILDKITE_STEP_KEY" == "metricbeat-pipeline" ]]; then
if [[ "$BUILDKITE_STEP_KEY" == "xpack-metricbeat-pipeline" || "$BUILDKITE_STEP_KEY" == "xpack-dockerlogbeat-pipeline" || "$BUILDKITE_STEP_KEY" == "metricbeat-pipeline" ]]; then
# Set the MODULE env variable if possible, it should be defined before generating pipeline's steps. It is used in multiple pipelines.
defineModuleFromTheChangeSet "${BEATS_PROJECT_NAME}"
fi
Expand Down
52 changes: 27 additions & 25 deletions .buildkite/x-pack/pipeline.xpack.winlogbeat.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json
name: "beats-xpack-winlogbeat"
name: "beats-x-pack-winlogbeat"

env:
IMAGE_UBUNTU_X86_64: "family/platform-ingest-beats-ubuntu-2204"
Expand All @@ -15,14 +15,17 @@ env:
ASDF_MAGE_VERSION: 1.15.0

steps:
- group: "Mandatory Tests"
key: "xpack-winlogbeat-mandatory-tests"
- group: "x-pack/Winlogbeat Mandatory Tests"
key: "x-pack-winlogbeat-mandatory-tests"
steps:

- label: ":windows: Xpack/Winlogbeat Win-2019 Unit (MODULE) Tests"
- label: ":windows: x-pack/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 @@ -37,11 +40,11 @@ steps:
- "x-pack/winlogbeat/build/*.json"
notify:
- github_commit_status:
context: "Xpack/Winlogbeat Win-2019 Unit (MODULE) Tests"
context: "x-pack/Winlogbeat Win-2019 Unit (MODULE) Tests"

- label: ":windows: Xpack/Winlogbeat Win-2016 Unit Tests"
- label: ":windows: x-pack/Winlogbeat Win-2016 Unit Tests"
command: |
Set-Location -Path x-pack/winlogbeat
Set-Location -Path x-pack\winlogbeat
mage build unitTest
key: "mandatory-win-2016-unit-tests"
agents:
Expand All @@ -55,11 +58,11 @@ steps:
- "x-pack/winlogbeat/build/*.json"
notify:
- github_commit_status:
context: "Xpack/Winlogbeat Win-2016 Unit Tests"
context: "x-pack/Winlogbeat Win-2016 Unit Tests"

- label: ":windows: Xpack/Winlogbeat Win-2022 Unit Tests"
- label: ":windows: x-pack/Winlogbeat Win-2022 Unit Tests"
command: |
Set-Location -Path x-pack/winlogbeat
Set-Location -Path x-pack\winlogbeat
mage build unitTest
key: "mandatory-win-2022-unit-tests"
agents:
Expand All @@ -73,16 +76,16 @@ steps:
- "x-pack/winlogbeat/build/*.json"
notify:
- github_commit_status:
context: "Xpack/Winlogbeat Win-2022 Unit Tests"
context: "x-pack/Winlogbeat Win-2022 Unit Tests"

- group: "Extended Windows Tests"
key: "extended-win-tests"
if: build.env("BUILDKITE_PULL_REQUEST") == "false" || build.env("GITHUB_PR_LABELS") =~ /.*[Ww]indows.*/

steps:
- label: ":windows: Xpack/Winlogbeat Win-10 Unit Tests"
- label: ":windows: x-pack/Winlogbeat Win-10 Unit Tests"
command: |
Set-Location -Path x-pack/winlogbeat
Set-Location -Path x-pack\winlogbeat
mage build unitTest
key: "extended-win-10-unit-tests"
agents:
Expand All @@ -96,11 +99,11 @@ steps:
- "x-pack/winlogbeat/build/*.json"
notify:
- github_commit_status:
context: "Xpack/Winlogbeat Win-10 Unit Tests"
context: "x-pack/Winlogbeat Win-10 Unit Tests"

- label: ":windows: Xpack/Winlogbeat Win-11 Unit Tests"
- label: ":windows: x-pack/Winlogbeat Win-11 Unit Tests"
command: |
Set-Location -Path x-pack/winlogbeat
Set-Location -Path x-pack\winlogbeat
mage build unitTest
key: "extended-win-11-unit-tests"
agents:
Expand All @@ -114,11 +117,11 @@ steps:
- "x-pack/winlogbeat/build/*.json"
notify:
- github_commit_status:
context: "Xpack/Winlogbeat Win-11 Unit Tests"
context: "x-pack/Winlogbeat Win-11 Unit Tests"

- label: ":windows: Xpack/Winlogbeat Win-2019 Unit Tests"
- label: ":windows: x-pack/Winlogbeat Win-2019 Unit Tests"
command: |
Set-Location -Path x-pack/winlogbeat
Set-Location -Path x-pack\winlogbeat
mage build unitTest
key: "extended-win-2019-unit-tests"
agents:
Expand All @@ -140,10 +143,10 @@ steps:
# 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"
- "x-pack-winlogbeat-mandatory-tests"

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

steps:
- label: ":ubuntu: Packaging Linux"
Expand All @@ -159,5 +162,4 @@ steps:
PLATFORMS: "+all linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64"
notify:
- github_commit_status:
context: "Xpack/Winlogbeat Packaging"

context: "x-pack/Winlogbeat Packaging"

0 comments on commit 0871809

Please sign in to comment.