Skip to content

Commit

Permalink
Initial project structure (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
edmocosta authored Jul 18, 2024
1 parent e33a247 commit 374c06f
Show file tree
Hide file tree
Showing 33 changed files with 3,990 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .buildkite/hooks/post-checkout
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 temporary 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 ""
74 changes: 74 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json
env:
SETUP_MAGE_VERSION: '1.15.0'
SETUP_GVM_VERSION: 'v0.5.0'
ASDF_MAGE_VERSION: '1.15.0'
GCP_DEFAULT_MACHINE_TYPE: "c2d-highcpu-8"
GCP_WIN_MACHINE_TYPE: "n2-standard-8"
IMAGE_MACOS_X86_64: "generic-13-ventura-x64"
IMAGE_UBUNTU_X86_64: "family/platform-ingest-beats-ubuntu-2204"
IMAGE_WIN_11: "family/platform-ingest-beats-windows-11"

steps:
- label: ":buildkite: Lint"
command: |
set -euo pipefail
echo "--- Mage notice"
mage notice
echo "--- Mage check"
mage -v check
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "${GCP_DEFAULT_MACHINE_TYPE}"

- label: ":linux: Test Linux"
key: test-lin
command: |
set -euo pipefail
go test -v > output-linux.report
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "${GCP_DEFAULT_MACHINE_TYPE}"
artifact_paths:
- "output-*.report"

- label: ":windows: Test Windows"
key: test-win
command: |
go test -v > output-windows.report
agents:
provider: "gcp"
image: "${IMAGE_WIN_11}"
machine_type: "${GCP_WIN_MACHINE_TYPE}"
disk_size: 200
disk_type: "pd-ssd"
artifact_paths:
- "output-*.report"

- label: ":pipeline: Process junit reports"
key: process-junit
command: ".buildkite/scripts/generate-report.sh"
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "${GCP_DEFAULT_MACHINE_TYPE}"
artifact_paths:
"*-junit.xml"
depends_on:
- step: "test-lin"
allow_failure: true
- step: "test-win"
allow_failure: true

- label: ":junit: Junit annotate"
plugins:
- junit-annotate#v2.4.1:
artifacts: "*-junit.xml"
fail-build-on-error: true
agents:
provider: "gcp" #junit plugin requires docker
depends_on:
- step: "process-junit"
allow_failure: true
16 changes: 16 additions & 0 deletions .buildkite/pull-requests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"jobs": [
{
"enabled": true,
"pipeline_slug": "lunes",
"allow_org_users": true,
"allowed_repo_permissions": ["admin", "write"],
"build_on_commit": true,
"build_on_comment": true,
"trigger_comment_regex": "^(?:(?:buildkite\\W+)?(?:build|test)\\W+(?:this|it))",
"always_trigger_comment_regex": "^(?:(?:buildkite\\W+)?(?:build|test)\\W+(?:this|it))",
"skip_ci_labels": ["skip-ci"],
"skip_ci_on_only_changed": ["\\.md$"]
}
]
}
5 changes: 5 additions & 0 deletions .buildkite/scripts/generate-report.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -euo pipefail

buildkite-agent artifact download "output-*.report" .
ls *.report | xargs -I{} sh -c 'go-junit-report > "$1-junit.xml" < $1' -- {}
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See: http://editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These owners will be the default owners for everything in
# the repo.
* @elastic/logstash
1 change: 1 addition & 0 deletions .go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.22.5
128 changes: 128 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# options for analysis running
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 1m

issues:
# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
max-same-issues: 0
# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
max-issues-per-linter: 0

output:
sort-results: true

# Find the whole list here https://golangci-lint.run/usage/linters/
linters:
disable-all: true
enable:
- errcheck # checking for unchecked errors in go programs
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
- forbidigo # forbids identifiers matched by reg exps
- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
- gosimple # linter for Go source code that specializes in simplifying a code
- misspell # finds commonly misspelled English words in comments
- nakedret # finds naked returns in functions greater than a specified function length
- nolintlint # reports ill-formed or insufficient nolint directives
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
- stylecheck # a replacement for golint
- unused # checks Go code for unused constants, variables, functions and types
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # detects when assignments to existing variables are not used
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
- unused # Finds unused global variables and constants
- asciicheck # simple linter to check that your code does not contain non-ASCII identifiers
- bodyclose # checks whether HTTP response body is closed successfully
- durationcheck # check for two durations multiplied together
- exportloopref # checks for pointers to enclosing loop variables
- goimports # Goimports does everything that gofmt does. Additionally, it checks unused imports
- gosec # inspects source code for security problems
- importas # enforces consistent import aliases
- nilerr # finds the code that returns nil even if it checks that the error is not nil.
- noctx # noctx finds sending http request without context.Context
- unconvert # Remove unnecessary type conversions
- wastedassign # wastedassign finds wasted assignment statements.
- gomodguard # check for blocked dependencies

# all available settings of specific linters
linters-settings:
errcheck:
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
check-type-assertions: true
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
check-blank: false
# List of functions to exclude from checking, where each entry is a single function to exclude.
# See https://github.com/kisielk/errcheck#excluding-functions for details.
exclude-functions:
- (mapstr.M).Delete # Only returns ErrKeyNotFound, can safely be ignored.
- (mapstr.M).Put # Can only fail on type conversions, usually safe to ignore.

errorlint:
# Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats
errorf: true
# Check for plain type assertions and type switches
asserts: true
# Check for plain error comparisons
comparison: true

forbidigo:
# Forbid the following identifiers
forbid:
- fmt.Print.* # too much log noise
# Exclude godoc examples from forbidigo checks. Default is true.
exclude_godoc_examples: true

gosimple:
# Select the Go version to target. The default is '1.13'.
go: "1.21.12"

nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 0

nolintlint:
# Enable to ensure that nolint directives are all used. Default is true.
allow-unused: false
# Disable to ensure that nolint directives don't have a leading space. Default is true.
allow-leading-space: false
# Exclude following linters from requiring an explanation. Default is [].
allow-no-explanation: []
# Enable to require an explanation of nonzero length after each nolint directive. Default is false.
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
require-specific: true

gomodguard:
blocked:
# List of blocked modules.
modules:
# Blocked module.
- github.com/pkg/errors:
# Recommended modules that should be used instead. (Optional)
recommendations:
- errors
- fmt
reason: "This package is deprecated, use fmt.Errorf with %%w instead"
- github.com/elastic/beats/v7:
reason: "There must be no Beats dependency"

staticcheck:
# Select the Go version to target. The default is '1.13'.
go: "1.22.5"
# https://staticcheck.io/docs/options#checks
checks: ["all"]

stylecheck:
# Select the Go version to target. The default is '1.13'.
go: "1.22.5"
# https://staticcheck.io/docs/options#checks
checks: ["all"]

unused:
# Select the Go version to target. The default is '1.13'.
go: "1.22.5"

Empty file added CHANGELOG.md
Empty file.
Loading

0 comments on commit 374c06f

Please sign in to comment.