From e546b93e6afe0bdf4e0b2d817c090817d59e77c3 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 3 Feb 2021 12:25:32 +0100 Subject: [PATCH 01/10] ci: change to use Jenkins --- .ci/Jenkinsfile | 102 ++++++++++++++++++++++++++++++++++++++++++ .ci/jobs/defaults.yml | 19 ++++++++ .ci/jobs/main.yml | 44 ++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 .ci/Jenkinsfile create mode 100644 .ci/jobs/defaults.yml create mode 100644 .ci/jobs/main.yml diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile new file mode 100644 index 000000000..5bd0d13b6 --- /dev/null +++ b/.ci/Jenkinsfile @@ -0,0 +1,102 @@ +#!/usr/bin/env groovy + +@Library('apm@current') _ + +pipeline { + agent { label 'ubuntu-20 && immutable' } + environment { + BASE_DIR="src/github.com/elastic/gosigar" + PIPELINE_LOG_LEVEL='INFO' + } + options { + timeout(time: 1, unit: 'HOURS') + buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10', daysToKeepStr: '30')) + timestamps() + ansiColor('xterm') + disableResume() + durabilityHint('PERFORMANCE_OPTIMIZED') + rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true]) + quietPeriod(10) + } + triggers { + issueCommentTrigger('(?i)(.*(?:jenkins\\W+)?run\\W+(?:the\\W+)?tests(?:\\W+please)?|/test).*') + } + parameters { + booleanParam(name: 'run_all_stages', defaultValue: false, description: 'Force to run all stages.') + } + stages { + stage('Checkout') { + steps { + deleteDir() + gitCheckout(basedir: "${BASE_DIR}") + stash allowEmpty: true, name: 'source', useDefaultExcludes: false + } + } + stage('Lint'){ + steps { + withGoEnv(){ + dir("${BASE_DIR}"){ + sh(label: 'lint', script: ''' + go mod tidy && git diff --exit-code + gofmt -l . | read && echo "Code differs from gofmt's style. Run 'gofmt -w .'" 1>&2 && exit 1 || true + ''') + sh(label: 'Go vet', script: 'go vet') + } + } + } + } + stage('Build and test'){ + matrix { + agent {label "${PLATFORM}"} + axes { + axis { + name 'PLATFORM' + values 'macOS', 'ubuntu-20 && immutable' + } + axis { + name 'GO_VERSION' + values '1.11', '1.15' + } + } + stages { + stage('build'){ + steps { + deleteDir() + unstash 'source' + withGoEnv(){ + dir("${BASE_DIR}"){ + sh(label: 'Go build', script: 'go build') + } + } + } + } + stage('test'){ + steps { + dir("${BASE_DIR}"){ + goTestJUnit(options: '-v ./...', output: 'build/junit-report.xml') + sh(label: 'Build Examples', script: ''' + for i in $(ls examples) + do + go build -o examples/$i/$i ./examples/$i + ./examples/$i/$i + done + ''') + } + } + post{ + cleanup{ + junit(testResults: "${BASE_DIR}/junit-report.xml", allowEmptyResults: true) + } + } + } + } + } + } + } + post { + cleanup { + notifyBuildResult(prComment: true) + } + } +} + diff --git a/.ci/jobs/defaults.yml b/.ci/jobs/defaults.yml new file mode 100644 index 000000000..bb26a2fca --- /dev/null +++ b/.ci/jobs/defaults.yml @@ -0,0 +1,19 @@ + +--- + +##### GLOBAL METADATA + +- meta: + cluster: beats-ci + +##### JOB DEFAULTS + +- job: + logrotate: + numToKeep: 20 + node: linux + concurrent: true + publishers: + - email: + recipients: infra-root+build@elastic.co + prune-dead-branches: true diff --git a/.ci/jobs/main.yml b/.ci/jobs/main.yml new file mode 100644 index 000000000..18302d034 --- /dev/null +++ b/.ci/jobs/main.yml @@ -0,0 +1,44 @@ +--- +- job: + name: Beats/gosigar + display-name: Go sigar + description: Jenkins pipeline for Go sigar is a golang implementation of the sigar API. + view: Beats + project-type: multibranch + script-path: .ci/Jenkinsfile + scm: + - github: + branch-discovery: no-pr + discover-pr-forks-strategy: merge-current + discover-pr-forks-trust: permission + discover-pr-origin: merge-current + discover-tags: true + head-filter-regex: '(master|main|PR-.*)' + notification-context: 'gosigar' + repo: gosigar + repo-owner: elastic + credentials-id: 2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken + ssh-checkout: + credentials: f6c7695a-671e-4f4f-a331-acdce44ff9ba + build-strategies: + - tags: + ignore-tags-older-than: -1 + ignore-tags-newer-than: -1 + - regular-branches: true + - change-request: + ignore-target-only-changes: false + clean: + after: true + before: true + prune: true + shallow-clone: true + depth: 4 + do-not-fetch-tags: true + submodule: + disable: false + recursive: true + parent-credentials: true + timeout: 100 + timeout: '15' + use-author: true + wipe-workspace: 'True' From 92e2772af5b680afb392fafc479b4fb8ff433fa7 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 3 Feb 2021 12:43:25 +0100 Subject: [PATCH 02/10] feat: windows support --- .ci/Jenkinsfile | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 5bd0d13b6..92ed791d4 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -51,7 +51,7 @@ pipeline { axes { axis { name 'PLATFORM' - values 'macOS', 'ubuntu-20 && immutable' + values 'macOS', 'ubuntu-20 && immutable', 'windows-2012-r2 && immutable' } axis { name 'GO_VERSION' @@ -65,7 +65,7 @@ pipeline { unstash 'source' withGoEnv(){ dir("${BASE_DIR}"){ - sh(label: 'Go build', script: 'go build') + cmd(label: 'Go build', script: 'go build') } } } @@ -74,13 +74,7 @@ pipeline { steps { dir("${BASE_DIR}"){ goTestJUnit(options: '-v ./...', output: 'build/junit-report.xml') - sh(label: 'Build Examples', script: ''' - for i in $(ls examples) - do - go build -o examples/$i/$i ./examples/$i - ./examples/$i/$i - done - ''') + buildExamples() } } post{ @@ -100,3 +94,24 @@ pipeline { } } +def getExamplesDirs(){ + return [ + "examples/df", + "examples/free", + "examples/ps", + "examples/uptime" + ] +} + +def buildExamples(){ + getExamplesDirs().each { exampleDir -> + cmd(label: "Build Example ${exampleDir}", script: "go build -o ${exampleDir}/out.exe ./${exampleDir}") + dir("${exampleDir}"){ + def prefix = '' + if(isUnix()){ + prefix = './' + } + cmd(label: "Running Example ${exampleDir}", script: "${prefix}out.exe") + } + } +} From 14feaae81f7a306f61afba9833fff52281f9553c Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 3 Feb 2021 12:44:04 +0100 Subject: [PATCH 03/10] chore: remove travis and appveyor --- .appveyor.yml | 73 --------------------------------------------------- .travis.yml | 31 ---------------------- 2 files changed, 104 deletions(-) delete mode 100644 .appveyor.yml delete mode 100644 .travis.yml diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index 5f2ea79c4..000000000 --- a/.appveyor.yml +++ /dev/null @@ -1,73 +0,0 @@ -# Version format -version: "{build}" - -# Operating system (build VM template) -os: Windows Server 2012 R2 - -# Environment variables -environment: - GOPATH: c:\gopath - GO111MODULE: on - GVM_GO_VERSION: 1.11.13 - GVM_DL: https://github.com/andrewkroh/gvm/releases/download/v0.2.2/gvm-windows-amd64.exe - -# Custom clone folder (variables are not expanded here). -clone_folder: c:\gopath\src\github.com\elastic\gosigar - -# Cache mingw install until appveyor.yml is modified. -cache: -- C:\ProgramData\chocolatey\bin -> .appveyor.yml -- C:\ProgramData\chocolatey\lib -> .appveyor.yml -- C:\Users\appveyor\.gvm -> .appveyor.yml -- C:\Windows\System32\gvm.exe -> .appveyor.yml -- C:\tools\mingw64 -> .appveyor.yml - -# Scripts that run after cloning repository -install: - - ps: >- - if(!(Test-Path "C:\Windows\System32\gvm.exe")) { - wget "$env:GVM_DL" -Outfile C:\Windows\System32\gvm.exe - } - - ps: gvm --format=powershell "$env:GVM_GO_VERSION" | Invoke-Expression - # AppVeyor installed mingw is 32-bit only so install 64-bit version. - - ps: >- - if(!(Test-Path "C:\tools\mingw64\bin\gcc.exe")) { - cinst mingw > mingw-install.txt - Push-AppveyorArtifact mingw-install.txt - } - - set PATH=C:\tools\mingw64\bin;%GOROOT%\bin;%PATH% - - set PATH=%GOPATH%\bin;%PATH% - - go version - - go env - - python --version - -# To run your custom scripts instead of automatic MSBuild -build_script: - # Compile - - appveyor AddCompilationMessage "Starting Compile" - - cd c:\gopath\src\github.com\elastic\gosigar - - go build - - go build -o examples/df/df.exe ./examples/df - - go build -o examples/free/free.exe ./examples/free - - go build -o examples/ps/ps.exe ./examples/ps - - go build -o examples/uptime/uptime.exe ./examples/uptime - - appveyor AddCompilationMessage "Compile Success" - -# To run your custom scripts instead of automatic tests -test_script: - # Unit tests - - ps: Add-AppveyorTest "Unit Tests" -Outcome Running - - go test -v ./... - - ps: Update-AppveyorTest "Unit Tests" -Outcome Passed - - ps: Add-AppveyorTest "Running Examples" -Outcome Running - - .\examples\df\df.exe - - .\examples\free\free.exe - - .\examples\ps\ps.exe - - .\examples\uptime\uptime.exe - - ps: Update-AppveyorTest "Running Examples" -Outcome Passed - -# To disable deployment -deploy: off - -# Notifications should only be setup using the AppVeyor UI so that -# forks can be created without inheriting the settings. diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 773b88bfb..000000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -language: go - -os: - - linux - - osx - -go: - - 1.11.x - - 1.15.x - -env: - global: - - GO111MODULE=on - - PROJ="github.com/elastic/gosigar" - -sudo: false - -before_install: - # Put project into proper GOPATH location (important for forks). - - mkdir -p $HOME/gopath/src/${PROJ} - - rsync -az ${TRAVIS_BUILD_DIR}/ $HOME/gopath/src/${PROJ}/ - - export TRAVIS_BUILD_DIR=$HOME/gopath/src/${PROJ} - - cd $HOME/gopath/src/${PROJ} - -script: - - go mod tidy && git diff --exit-code - - gofmt -l . | read && echo "Code differs from gofmt's style. Run 'gofmt -w .'" 1>&2 && exit 1 || true - - go vet - - go build - - go test -v ./... - - for i in $(ls examples); do go build -o examples/$i/$i ./examples/$i; ./examples/$i/$i; done \ No newline at end of file From 784b1ab87f0fbb6edf4d0dd585dd5dc6a25665a9 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 3 Feb 2021 12:45:57 +0100 Subject: [PATCH 04/10] fix: correct junit report path --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 92ed791d4..269fba3d7 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -73,7 +73,7 @@ pipeline { stage('test'){ steps { dir("${BASE_DIR}"){ - goTestJUnit(options: '-v ./...', output: 'build/junit-report.xml') + goTestJUnit(options: '-v ./...', output: 'junit-report.xml') buildExamples() } } From c1673647fdf20be73902682e6044f687ddef95d8 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 3 Feb 2021 16:04:32 +0100 Subject: [PATCH 05/10] Update .ci/jobs/main.yml --- .ci/jobs/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/jobs/main.yml b/.ci/jobs/main.yml index 18302d034..5979566ac 100644 --- a/.ci/jobs/main.yml +++ b/.ci/jobs/main.yml @@ -13,7 +13,7 @@ discover-pr-forks-trust: permission discover-pr-origin: merge-current discover-tags: true - head-filter-regex: '(master|main|PR-.*)' + head-filter-regex: '(master|main|PR-.*|v\d+\.\d+\.\d+)' notification-context: 'gosigar' repo: gosigar repo-owner: elastic From be55c2a410d724d815571bf1148602379e2f63ab Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 3 Feb 2021 16:04:54 +0100 Subject: [PATCH 06/10] Apply suggestions from code review Co-authored-by: Victor Martinez --- .ci/Jenkinsfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 269fba3d7..f29047bd7 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -5,7 +5,8 @@ pipeline { agent { label 'ubuntu-20 && immutable' } environment { - BASE_DIR="src/github.com/elastic/gosigar" + REPO = 'gosigar' + BASE_DIR = "src/github.com/elastic/${env.REPO}" PIPELINE_LOG_LEVEL='INFO' } options { @@ -21,9 +22,6 @@ pipeline { triggers { issueCommentTrigger('(?i)(.*(?:jenkins\\W+)?run\\W+(?:the\\W+)?tests(?:\\W+please)?|/test).*') } - parameters { - booleanParam(name: 'run_all_stages', defaultValue: false, description: 'Force to run all stages.') - } stages { stage('Checkout') { steps { @@ -103,7 +101,7 @@ def getExamplesDirs(){ ] } -def buildExamples(){ +def buildExamples(){ getExamplesDirs().each { exampleDir -> cmd(label: "Build Example ${exampleDir}", script: "go build -o ${exampleDir}/out.exe ./${exampleDir}") dir("${exampleDir}"){ From c33877155fc18accdee5e0eb38755b90be45e13e Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 3 Feb 2021 16:49:15 +0100 Subject: [PATCH 07/10] fix: set proper macOS label --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index f29047bd7..430099b4a 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -49,7 +49,7 @@ pipeline { axes { axis { name 'PLATFORM' - values 'macOS', 'ubuntu-20 && immutable', 'windows-2012-r2 && immutable' + values 'macosx', 'ubuntu-20 && immutable', 'windows-2012-r2 && immutable' } axis { name 'GO_VERSION' From ace48829e965e1d09c416cdc0e2a75d6639ba1f6 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 3 Feb 2021 16:49:38 +0100 Subject: [PATCH 08/10] fix: use withGoEnv for build the examples --- .ci/Jenkinsfile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 430099b4a..24b3e897f 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -70,9 +70,11 @@ pipeline { } stage('test'){ steps { - dir("${BASE_DIR}"){ - goTestJUnit(options: '-v ./...', output: 'junit-report.xml') - buildExamples() + withGoEnv(){ + dir("${BASE_DIR}"){ + goTestJUnit(options: '-v ./...', output: 'junit-report.xml') + buildExamples() + } } } post{ From 0f4119eefd542b68d8dd4bfa1538ea2011b5f4aa Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 3 Feb 2021 17:07:50 +0100 Subject: [PATCH 09/10] fix: fix windows label --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 24b3e897f..f1f8c3f9b 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -49,7 +49,7 @@ pipeline { axes { axis { name 'PLATFORM' - values 'macosx', 'ubuntu-20 && immutable', 'windows-2012-r2 && immutable' + values 'macosx', 'ubuntu-20 && immutable', 'windows-2012-r2 && windows-immutable' } axis { name 'GO_VERSION' From 2466d3702fd0aca35e5a1f8c3119b81a22ad98d6 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Thu, 4 Feb 2021 10:00:59 +0100 Subject: [PATCH 10/10] Update .ci/Jenkinsfile --- .ci/Jenkinsfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index f1f8c3f9b..97943c536 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -51,10 +51,6 @@ pipeline { name 'PLATFORM' values 'macosx', 'ubuntu-20 && immutable', 'windows-2012-r2 && windows-immutable' } - axis { - name 'GO_VERSION' - values '1.11', '1.15' - } } stages { stage('build'){