forked from elastic/elastic-agent-autodiscover
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
21,929 additions
and
954 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
checkout_merge() { | ||
local target_branch=$1 | ||
local pr_commit=$2 | ||
local merge_branch=$3 | ||
|
||
if [[ -z "${target_branch}" ]]; then | ||
echo "No pull request target branch" | ||
exit 1 | ||
fi | ||
|
||
git fetch -v origin "${target_branch}" | ||
git checkout FETCH_HEAD | ||
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)" | ||
|
||
# create temporal branch to merge the PR with the target branch | ||
git checkout -b ${merge_branch} | ||
echo "New branch created: $(git rev-parse --abbrev-ref HEAD)" | ||
|
||
# set author identity so it can be run git merge | ||
git config user.name "github-merged-pr-post-checkout" | ||
git config user.email "auto-merge@buildkite" | ||
|
||
git merge --no-edit "${BUILDKITE_COMMIT}" || { | ||
local merge_result=$? | ||
echo "Merge failed: ${merge_result}" | ||
git merge --abort | ||
exit ${merge_result} | ||
} | ||
} | ||
|
||
pull_request="${BUILDKITE_PULL_REQUEST:-false}" | ||
|
||
if [[ "${pull_request}" == "false" ]]; then | ||
echo "Not a pull request, skipping" | ||
exit 0 | ||
fi | ||
|
||
TARGET_BRANCH="${BUILDKITE_PULL_REQUEST_BASE_BRANCH:-master}" | ||
PR_COMMIT="${BUILDKITE_COMMIT}" | ||
PR_ID=${BUILDKITE_PULL_REQUEST} | ||
MERGE_BRANCH="pr_merge_${PR_ID}" | ||
|
||
checkout_merge "${TARGET_BRANCH}" "${PR_COMMIT}" "${MERGE_BRANCH}" | ||
|
||
echo "Commit information" | ||
git --no-pager log --format=%B -n 1 | ||
|
||
# Ensure buildkite groups are rendered | ||
echo "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
if [[ "$BUILDKITE_PIPELINE_SLUG" == "elastic-agent-autodiscover" ]]; then | ||
export GO_VERSION=$(cat .go-version) | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json | ||
|
||
env: | ||
SETUP_GVM_VERSION: 'v0.5.0' | ||
GO_VERSION_CHOCO: "1.20.5" | ||
LINUX_AGENT_IMAGE: "golang:${GO_VERSION}" | ||
WINDOWS_AGENT_IMAGE: "family/ci-windows-2022" | ||
|
||
steps: | ||
- label: ":golangci-lint: Lint" | ||
key: lint-test | ||
command: ".buildkite/scripts/lint_test.sh" | ||
agents: | ||
image: "${LINUX_AGENT_IMAGE}" | ||
cpu: "2" | ||
memory: "1G" | ||
|
||
- label: ":linux: Tests on Linux" | ||
key: linux-test | ||
command: ".buildkite/scripts/run-linux-tests.sh" | ||
agents: | ||
image: "${LINUX_AGENT_IMAGE}" | ||
cpu: "2" | ||
memory: "1G" | ||
artifact_paths: "*.xml" | ||
|
||
- label: ":windows: Tests on Windows" | ||
key: windows-test | ||
command: ".buildkite/scripts/run-win-tests.ps1" | ||
agents: | ||
provider: "gcp" | ||
image: "${WINDOWS_AGENT_IMAGE}" | ||
artifact_paths: "*.xml" | ||
|
||
- label: ":junit: Junit annotate" | ||
plugins: | ||
- junit-annotate#v2.4.1: | ||
artifacts: "*.xml" | ||
fail-build-on-error: true | ||
agents: | ||
provider: "gcp" | ||
depends_on: | ||
- step: "linux-test" | ||
allow_failure: true | ||
- step: "windows-test" | ||
allow_failure: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"jobs": [ | ||
{ | ||
"enabled": true, | ||
"pipelineSlug": "elastic-agent-autodiscover", | ||
"allow_org_users": true, | ||
"allowed_repo_permissions": ["admin", "write"], | ||
"allowed_list": [ ], | ||
"set_commit_status": true, | ||
"build_on_commit": true, | ||
"build_on_comment": true, | ||
"trigger_comment_regex": "^(?:(?:buildkite\\W+)?(?:build|test)\\W+(?:this|it))|^/test$", | ||
"always_trigger_comment_regex": "^(?:(?:buildkite\\W+)?(?:build|test)\\W+(?:this|it))|^/test$", | ||
"skip_ci_labels": [ ], | ||
"skip_target_branches": [ ], | ||
"skip_ci_on_only_changed": [ ], | ||
"always_require_ci_on_changed": [ ] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
WORKSPACE="$(pwd)/bin" | ||
|
||
create_workspace() { | ||
if [[ ! -d "${WORKSPACE}" ]]; then | ||
mkdir -p ${WORKSPACE} | ||
fi | ||
} | ||
|
||
install_go_dependencies() { | ||
local install_packages=( | ||
"github.com/magefile/mage" | ||
"github.com/elastic/go-licenser" | ||
"golang.org/x/tools/cmd/goimports" | ||
"github.com/jstemmer/go-junit-report" | ||
"gotest.tools/gotestsum" | ||
) | ||
for pkg in "${install_packages[@]}"; do | ||
go install "${pkg}@latest" | ||
done | ||
} | ||
|
||
retry() { | ||
local retries=$1 | ||
shift | ||
local count=0 | ||
until "$@"; do | ||
exit=$? | ||
wait=$((2 ** count)) | ||
count=$((count + 1)) | ||
if [ $count -lt "$retries" ]; then | ||
>&2 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..." | ||
sleep $wait | ||
else | ||
>&2 echo "Retry $count/$retries exited $exit, no more retries left." | ||
return $exit | ||
fi | ||
done | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
source .buildkite/scripts/common.sh | ||
|
||
create_workspace | ||
|
||
install_go_dependencies | ||
|
||
mage notice | ||
|
||
mage -v check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
source .buildkite/scripts/common.sh | ||
|
||
install_go_dependencies | ||
|
||
gotestsum --format testname --junitfile junit-linux-report.xml -- -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
$ErrorActionPreference = "Stop" # set -e | ||
# Forcing to checkout again all the files with a correct autocrlf. | ||
# Doing this here because we cannot set git clone options before. | ||
function fixCRLF { | ||
Write-Host "-- Fixing CRLF in git checkout --" | ||
git config core.autocrlf input | ||
git rm --quiet --cached -r . | ||
git reset --quiet --hard | ||
} | ||
function withGolang($version) { | ||
Write-Host "-- Install golang --" | ||
choco install -y golang --version $version | ||
$env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.." | ||
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" | ||
refreshenv | ||
go version | ||
go env | ||
} | ||
function installGoDependencies { | ||
$installPackages = @( | ||
"github.com/magefile/mage" | ||
"github.com/elastic/go-licenser" | ||
"golang.org/x/tools/cmd/goimports" | ||
"github.com/jstemmer/go-junit-report/v2" | ||
"gotest.tools/gotestsum" | ||
) | ||
foreach ($pkg in $installPackages) { | ||
go install "$pkg@latest" | ||
} | ||
} | ||
|
||
fixCRLF | ||
withGolang $env:GO_VERSION_CHOCO | ||
installGoDependencies | ||
|
||
$ErrorActionPreference = "Continue" # set +e | ||
|
||
gotestsum --format testname --junitfile junit-win-report.xml -- -v ./... | ||
|
||
$EXITCODE=$LASTEXITCODE | ||
$ErrorActionPreference = "Stop" | ||
|
||
Exit $EXITCODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
--- | ||
name: Bump golang-version to latest version | ||
|
||
scms: | ||
githubConfig: | ||
kind: github | ||
spec: | ||
user: '{{ requiredEnv "GIT_USER" }}' | ||
email: '{{ requiredEnv "GIT_EMAIL" }}' | ||
owner: elastic | ||
repository: elastic-agent-autodiscover | ||
token: '{{ requiredEnv "GITHUB_TOKEN" }}' | ||
username: '{{ requiredEnv "GIT_USER" }}' | ||
branch: main | ||
|
||
actions: | ||
elastic-agent-autodiscover: | ||
kind: github/pullrequest | ||
scmid: githubConfig | ||
sourceid: latestGoVersion | ||
spec: | ||
automerge: false | ||
labels: | ||
- dependencies | ||
- backport-skip | ||
title: '[Automation] Bump Golang version to {{ source "latestGoVersion" }}' | ||
|
||
sources: | ||
minor: | ||
name: Get minor version in .go-version | ||
kind: shell | ||
transformers: | ||
- findsubmatch: | ||
pattern: '^\d+.(\d+).\d+$' | ||
captureindex: 1 | ||
spec: | ||
command: cat .go-version | ||
|
||
latestGoVersion: | ||
name: Get Latest Go Release | ||
kind: githubrelease | ||
dependson: | ||
- minor | ||
transformers: | ||
- trimprefix: go | ||
spec: | ||
owner: golang | ||
repository: go | ||
token: '{{ requiredEnv "GITHUB_TOKEN" }}' | ||
username: '{{ requiredEnv "GIT_USER" }}' | ||
versionfilter: | ||
kind: regex | ||
pattern: go1\.{{ source "minor" }}\.(\d*)$ | ||
|
||
gomod: | ||
dependson: | ||
- latestGoVersion | ||
name: Get version in go.mod format | ||
kind: shell | ||
transformers: | ||
- findsubmatch: | ||
pattern: '^(\d+.\d+).\d+' | ||
captureindex: 1 | ||
spec: | ||
command: echo {{ source "latestGoVersion" }} | ||
|
||
conditions: | ||
dockerTag: | ||
name: Is docker image golang:{{ source "latestGoVersion" }} published | ||
kind: dockerimage | ||
spec: | ||
image: golang | ||
tag: '{{ source "latestGoVersion" }}' | ||
sourceid: latestGoVersion | ||
|
||
goDefaultVersion-check: | ||
name: Check if defined golang version differs | ||
kind: shell | ||
sourceid: latestGoVersion | ||
spec: | ||
command: 'grep -v -q {{ source "latestGoVersion" }} .go-version #' | ||
|
||
targets: | ||
update-go-version: | ||
name: "Update .go-version" | ||
sourceid: latestGoVersion | ||
scmid: githubConfig | ||
kind: file | ||
spec: | ||
content: '{{ source "latestGoVersion" }}' | ||
file: .go-version | ||
matchpattern: '\d+.\d+.\d+' | ||
update-golang.ci: | ||
name: "Update .golangci.yml" | ||
sourceid: latestGoVersion | ||
scmid: githubConfig | ||
kind: file | ||
spec: | ||
content: '{{ source "latestGoVersion" }}' | ||
file: .golangci.yml | ||
matchpattern: '\d+.\d+.\d+' | ||
update-gomod: | ||
name: "Update go.mod" | ||
sourceid: gomod | ||
scmid: githubConfig | ||
kind: file | ||
spec: | ||
content: 'go {{ source "gomod" }}' | ||
file: go.mod | ||
matchpattern: 'go \d+.\d+' |
Oops, something went wrong.